@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
package/build/link/inline.js
CHANGED
|
@@ -1,32 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var inline_exports = {};
|
|
29
|
+
__export(inline_exports, {
|
|
30
|
+
default: () => inline_default
|
|
5
31
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
module.exports = __toCommonJS(inline_exports);
|
|
33
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
34
|
+
var import_element = require("@wordpress/element");
|
|
35
|
+
var import_i18n = require("@wordpress/i18n");
|
|
36
|
+
var import_a11y = require("@wordpress/a11y");
|
|
37
|
+
var import_components = require("@wordpress/components");
|
|
38
|
+
var import_url = require("@wordpress/url");
|
|
39
|
+
var import_rich_text = require("@wordpress/rich-text");
|
|
40
|
+
var import_block_editor = require("@wordpress/block-editor");
|
|
41
|
+
var import_data = require("@wordpress/data");
|
|
42
|
+
var import_utils = require("./utils");
|
|
43
|
+
var import_index = require("./index");
|
|
44
|
+
var import_css_classes_setting = __toESM(require("./css-classes-setting"));
|
|
45
|
+
const LINK_SETTINGS = [
|
|
46
|
+
...import_block_editor.LinkControl.DEFAULT_LINK_SETTINGS,
|
|
47
|
+
{
|
|
48
|
+
id: "nofollow",
|
|
49
|
+
title: (0, import_i18n.__)("Mark as nofollow")
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "cssClasses",
|
|
53
|
+
title: (0, import_i18n.__)("Additional CSS class(es)"),
|
|
54
|
+
render: (setting, value, onChange) => {
|
|
55
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
56
|
+
import_css_classes_setting.default,
|
|
57
|
+
{
|
|
58
|
+
setting,
|
|
59
|
+
value,
|
|
60
|
+
onChange
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
];
|
|
30
66
|
function InlineLinkUI({
|
|
31
67
|
isActive,
|
|
32
68
|
activeAttributes,
|
|
@@ -38,74 +74,74 @@ function InlineLinkUI({
|
|
|
38
74
|
focusOnMount
|
|
39
75
|
}) {
|
|
40
76
|
const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
|
|
41
|
-
|
|
42
|
-
// Get the text content minus any HTML tags.
|
|
43
77
|
const richTextText = richLinkTextValue.text;
|
|
44
|
-
const {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
const { selectionChange } = (0, import_data.useDispatch)(import_block_editor.store);
|
|
79
|
+
const { createPageEntity, userCanCreatePages, selectionStart } = (0, import_data.useSelect)(
|
|
80
|
+
(select) => {
|
|
81
|
+
const { getSettings, getSelectionStart } = select(import_block_editor.store);
|
|
82
|
+
const _settings = getSettings();
|
|
83
|
+
return {
|
|
84
|
+
createPageEntity: _settings.__experimentalCreatePageEntity,
|
|
85
|
+
userCanCreatePages: _settings.__experimentalUserCanCreatePages,
|
|
86
|
+
selectionStart: getSelectionStart()
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
[]
|
|
90
|
+
);
|
|
91
|
+
const linkValue = (0, import_element.useMemo)(
|
|
92
|
+
() => ({
|
|
93
|
+
url: activeAttributes.url,
|
|
94
|
+
type: activeAttributes.type,
|
|
95
|
+
id: activeAttributes.id,
|
|
96
|
+
opensInNewTab: activeAttributes.target === "_blank",
|
|
97
|
+
nofollow: activeAttributes.rel?.includes("nofollow"),
|
|
98
|
+
title: richTextText,
|
|
99
|
+
cssClasses: activeAttributes.class
|
|
100
|
+
}),
|
|
101
|
+
[
|
|
102
|
+
activeAttributes.class,
|
|
103
|
+
activeAttributes.id,
|
|
104
|
+
activeAttributes.rel,
|
|
105
|
+
activeAttributes.target,
|
|
106
|
+
activeAttributes.type,
|
|
107
|
+
activeAttributes.url,
|
|
108
|
+
richTextText
|
|
109
|
+
]
|
|
110
|
+
);
|
|
71
111
|
function removeLink() {
|
|
72
|
-
const newValue = (0,
|
|
112
|
+
const newValue = (0, import_rich_text.removeFormat)(value, "core/link");
|
|
73
113
|
onChange(newValue);
|
|
74
114
|
stopAddingLink();
|
|
75
|
-
(0,
|
|
115
|
+
(0, import_a11y.speak)((0, import_i18n.__)("Link removed."), "assertive");
|
|
76
116
|
}
|
|
77
117
|
function onChangeLink(nextValue) {
|
|
78
118
|
const hasLink = linkValue?.url;
|
|
79
119
|
const isNewLink = !hasLink;
|
|
80
|
-
|
|
81
|
-
// Merge the next value with the current link value.
|
|
82
120
|
nextValue = {
|
|
83
121
|
...linkValue,
|
|
84
122
|
...nextValue
|
|
85
123
|
};
|
|
86
|
-
const newUrl = (0,
|
|
87
|
-
const linkFormat = (0,
|
|
124
|
+
const newUrl = (0, import_url.prependHTTP)(nextValue.url);
|
|
125
|
+
const linkFormat = (0, import_utils.createLinkFormat)({
|
|
88
126
|
url: newUrl,
|
|
89
127
|
type: nextValue.type,
|
|
90
|
-
id: nextValue.id !==
|
|
128
|
+
id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0,
|
|
91
129
|
opensInNewWindow: nextValue.opensInNewTab,
|
|
92
|
-
nofollow: nextValue.nofollow
|
|
130
|
+
nofollow: nextValue.nofollow,
|
|
131
|
+
cssClasses: nextValue.cssClasses
|
|
93
132
|
});
|
|
94
133
|
const newText = nextValue.title || newUrl;
|
|
95
|
-
|
|
96
|
-
// Scenario: we have any active text selection or an active format.
|
|
97
134
|
let newValue;
|
|
98
|
-
if ((0,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
135
|
+
if ((0, import_rich_text.isCollapsed)(value) && !isActive) {
|
|
136
|
+
const inserted = (0, import_rich_text.insert)(value, newText);
|
|
137
|
+
newValue = (0, import_rich_text.applyFormat)(
|
|
138
|
+
inserted,
|
|
139
|
+
linkFormat,
|
|
140
|
+
value.start,
|
|
141
|
+
value.start + newText.length
|
|
142
|
+
);
|
|
102
143
|
onChange(newValue);
|
|
103
|
-
|
|
104
|
-
// Close the Link UI.
|
|
105
144
|
stopAddingLink();
|
|
106
|
-
|
|
107
|
-
// Move the selection to the end of the inserted link outside of the format boundary
|
|
108
|
-
// so the user can continue typing after the link.
|
|
109
145
|
selectionChange({
|
|
110
146
|
clientId: selectionStart.clientId,
|
|
111
147
|
identifier: selectionStart.attributeKey,
|
|
@@ -113,141 +149,117 @@ function InlineLinkUI({
|
|
|
113
149
|
});
|
|
114
150
|
return;
|
|
115
151
|
} else if (newText === richTextText) {
|
|
116
|
-
newValue = (0,
|
|
152
|
+
newValue = (0, import_rich_text.applyFormat)(value, linkFormat);
|
|
117
153
|
} else {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
newValue = (0, _richText.create)({
|
|
123
|
-
text: newText
|
|
124
|
-
});
|
|
125
|
-
// Apply the new Link format to this new text value.
|
|
126
|
-
newValue = (0, _richText.applyFormat)(newValue, linkFormat, 0, newText.length);
|
|
127
|
-
|
|
128
|
-
// Get the boundaries of the active link format.
|
|
129
|
-
const boundary = (0, _utils.getFormatBoundary)(value, {
|
|
130
|
-
type: 'core/link'
|
|
154
|
+
newValue = (0, import_rich_text.create)({ text: newText });
|
|
155
|
+
newValue = (0, import_rich_text.applyFormat)(newValue, linkFormat, 0, newText.length);
|
|
156
|
+
const boundary = (0, import_utils.getFormatBoundary)(value, {
|
|
157
|
+
type: "core/link"
|
|
131
158
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
// Update the original (full) RichTextValue replacing the
|
|
141
|
-
// target text with the *new* RichTextValue containing:
|
|
142
|
-
// 1. The new text content.
|
|
143
|
-
// 2. The new link format.
|
|
144
|
-
// As "replace" will operate on the first match only, it is
|
|
145
|
-
// run only against the second half of the value which was
|
|
146
|
-
// split at the active format's boundary. This avoids a bug
|
|
147
|
-
// with incorrectly targeted replacements.
|
|
148
|
-
// See: https://github.com/WordPress/gutenberg/issues/41771.
|
|
149
|
-
// Note original formats will be lost when applying this change.
|
|
150
|
-
// That is expected behaviour.
|
|
151
|
-
// See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
|
|
152
|
-
const newValAfter = (0, _richText.replace)(valAfter, richTextText, newValue);
|
|
153
|
-
newValue = (0, _richText.concat)(valBefore, newValAfter);
|
|
159
|
+
const [valBefore, valAfter] = (0, import_rich_text.split)(
|
|
160
|
+
value,
|
|
161
|
+
boundary.start,
|
|
162
|
+
boundary.start
|
|
163
|
+
);
|
|
164
|
+
const newValAfter = (0, import_rich_text.replace)(valAfter, richTextText, newValue);
|
|
165
|
+
newValue = (0, import_rich_text.concat)(valBefore, newValAfter);
|
|
154
166
|
}
|
|
155
167
|
onChange(newValue);
|
|
156
|
-
|
|
157
|
-
// Focus should only be returned to the rich text on submit if this link is not
|
|
158
|
-
// being created for the first time. If it is then focus should remain within the
|
|
159
|
-
// Link UI because it should remain open for the user to modify the link they have
|
|
160
|
-
// just created.
|
|
161
168
|
if (!isNewLink) {
|
|
162
169
|
stopAddingLink();
|
|
163
170
|
}
|
|
164
|
-
if (!(0,
|
|
165
|
-
(0,
|
|
171
|
+
if (!(0, import_utils.isValidHref)(newUrl)) {
|
|
172
|
+
(0, import_a11y.speak)(
|
|
173
|
+
(0, import_i18n.__)(
|
|
174
|
+
"Warning: the link has been inserted but may have errors. Please test it."
|
|
175
|
+
),
|
|
176
|
+
"assertive"
|
|
177
|
+
);
|
|
166
178
|
} else if (isActive) {
|
|
167
|
-
(0,
|
|
179
|
+
(0, import_a11y.speak)((0, import_i18n.__)("Link edited."), "assertive");
|
|
168
180
|
} else {
|
|
169
|
-
(0,
|
|
181
|
+
(0, import_a11y.speak)((0, import_i18n.__)("Link inserted."), "assertive");
|
|
170
182
|
}
|
|
171
183
|
}
|
|
172
|
-
const popoverAnchor = (0,
|
|
184
|
+
const popoverAnchor = (0, import_rich_text.useAnchor)({
|
|
173
185
|
editableContentElement: contentRef.current,
|
|
174
186
|
settings: {
|
|
175
|
-
...
|
|
187
|
+
...import_index.link,
|
|
176
188
|
isActive
|
|
177
189
|
}
|
|
178
190
|
});
|
|
179
191
|
async function handleCreate(pageTitle) {
|
|
180
192
|
const page = await createPageEntity({
|
|
181
193
|
title: pageTitle,
|
|
182
|
-
status:
|
|
194
|
+
status: "draft"
|
|
183
195
|
});
|
|
184
196
|
return {
|
|
185
197
|
id: page.id,
|
|
186
198
|
type: page.type,
|
|
187
199
|
title: page.title.rendered,
|
|
188
200
|
url: page.link,
|
|
189
|
-
kind:
|
|
201
|
+
kind: "post-type"
|
|
190
202
|
};
|
|
191
203
|
}
|
|
192
204
|
function createButtonText(searchTerm) {
|
|
193
|
-
return (0,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
205
|
+
return (0, import_element.createInterpolateElement)(
|
|
206
|
+
(0, import_i18n.sprintf)(
|
|
207
|
+
/* translators: %s: search term. */
|
|
208
|
+
(0, import_i18n.__)("Create page: <mark>%s</mark>"),
|
|
209
|
+
searchTerm
|
|
210
|
+
),
|
|
211
|
+
{ mark: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("mark", {}) }
|
|
212
|
+
);
|
|
197
213
|
}
|
|
198
|
-
return
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
215
|
+
import_components.Popover,
|
|
216
|
+
{
|
|
217
|
+
anchor: popoverAnchor,
|
|
218
|
+
animate: false,
|
|
219
|
+
onClose: stopAddingLink,
|
|
220
|
+
onFocusOutside,
|
|
221
|
+
placement: "bottom",
|
|
222
|
+
offset: 8,
|
|
223
|
+
shift: true,
|
|
224
|
+
focusOnMount,
|
|
225
|
+
constrainTabbing: true,
|
|
226
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
227
|
+
import_block_editor.LinkControl,
|
|
228
|
+
{
|
|
229
|
+
value: linkValue,
|
|
230
|
+
onChange: onChangeLink,
|
|
231
|
+
onRemove: removeLink,
|
|
232
|
+
hasRichPreviews: true,
|
|
233
|
+
createSuggestion: createPageEntity && handleCreate,
|
|
234
|
+
withCreateSuggestion: userCanCreatePages,
|
|
235
|
+
createSuggestionButtonText: createButtonText,
|
|
236
|
+
hasTextControl: true,
|
|
237
|
+
settings: LINK_SETTINGS,
|
|
238
|
+
showInitialSuggestions: true,
|
|
239
|
+
suggestionsQuery: {
|
|
240
|
+
// always show Pages as initial suggestions
|
|
241
|
+
initialSuggestionsSearchOptions: {
|
|
242
|
+
type: "post",
|
|
243
|
+
subtype: "page",
|
|
244
|
+
perPage: 20
|
|
245
|
+
}
|
|
246
|
+
}
|
|
225
247
|
}
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
);
|
|
229
251
|
}
|
|
230
252
|
function getRichTextValueFromSelection(value, isActive) {
|
|
231
|
-
// Default to the selection ranges on the RichTextValue object.
|
|
232
253
|
let textStart = value.start;
|
|
233
254
|
let textEnd = value.end;
|
|
234
|
-
|
|
235
|
-
// If the format is currently active then the rich text value
|
|
236
|
-
// should always be taken from the bounds of the active format
|
|
237
|
-
// and not the selected text.
|
|
238
255
|
if (isActive) {
|
|
239
|
-
const boundary = (0,
|
|
240
|
-
type:
|
|
256
|
+
const boundary = (0, import_utils.getFormatBoundary)(value, {
|
|
257
|
+
type: "core/link"
|
|
241
258
|
});
|
|
242
259
|
textStart = boundary.start;
|
|
243
|
-
|
|
244
|
-
// Text *selection* always extends +1 beyond the edge of the format.
|
|
245
|
-
// We account for that here.
|
|
246
260
|
textEnd = boundary.end + 1;
|
|
247
261
|
}
|
|
248
|
-
|
|
249
|
-
// Get a RichTextValue containing the selected text content.
|
|
250
|
-
return (0, _richText.slice)(value, textStart, textEnd);
|
|
262
|
+
return (0, import_rich_text.slice)(value, textStart, textEnd);
|
|
251
263
|
}
|
|
252
|
-
var
|
|
253
|
-
//# sourceMappingURL=inline.js.map
|
|
264
|
+
var inline_default = InlineLinkUI;
|
|
265
|
+
//# sourceMappingURL=inline.js.map
|
package/build/link/inline.js.map
CHANGED
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_a11y","_components","_url","_richText","_blockEditor","_data","_utils","_index","_jsxRuntime","LINK_SETTINGS","LinkControl","DEFAULT_LINK_SETTINGS","id","title","__","InlineLinkUI","isActive","activeAttributes","value","onChange","onFocusOutside","stopAddingLink","contentRef","focusOnMount","richLinkTextValue","getRichTextValueFromSelection","richTextText","text","selectionChange","useDispatch","blockEditorStore","createPageEntity","userCanCreatePages","selectionStart","useSelect","select","getSettings","getSelectionStart","_settings","__experimentalCreatePageEntity","__experimentalUserCanCreatePages","linkValue","useMemo","url","type","opensInNewTab","target","nofollow","rel","includes","removeLink","newValue","removeFormat","speak","onChangeLink","nextValue","hasLink","isNewLink","newUrl","prependHTTP","linkFormat","createLinkFormat","undefined","String","opensInNewWindow","newText","isCollapsed","inserted","insert","applyFormat","start","length","clientId","identifier","attributeKey","create","boundary","getFormatBoundary","valBefore","valAfter","split","newValAfter","replace","concat","isValidHref","popoverAnchor","useAnchor","editableContentElement","current","settings","handleCreate","pageTitle","page","status","rendered","link","kind","createButtonText","searchTerm","createInterpolateElement","sprintf","mark","jsx","Popover","anchor","animate","onClose","placement","offset","shift","constrainTabbing","children","onRemove","hasRichPreviews","createSuggestion","withCreateSuggestion","createSuggestionButtonText","hasTextControl","showInitialSuggestions","suggestionsQuery","initialSuggestionsSearchOptions","subtype","perPage","textStart","textEnd","end","slice","_default","exports","default"],"sources":["@wordpress/format-library/src/link/inline.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, 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":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,WAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AAYA,IAAAM,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AS,GAAGzG,KAAK,CAACoD,KAAK;EAC3B,IAAIsD,OAAO,GAAG1G,KAAK,CAAC2G,GAAG;;EAEvB;EACA;EACA;EACA,IAAK7G,QAAQ,EAAG;IACf,MAAM4D,QAAQ,GAAG,IAAAC,wBAAiB,EAAE3D,KAAK,EAAE;MAC1C0B,IAAI,EAAE;IACP,CAAE,CAAC;IAEH+E,SAAS,GAAG/C,QAAQ,CAACN,KAAK;;IAE1B;IACA;IACAsD,OAAO,GAAGhD,QAAQ,CAACiD,GAAG,GAAG,CAAC;EAC3B;;EAEA;EACA,OAAO,IAAAC,eAAK,EAAE5G,KAAK,EAAEyG,SAAS,EAAEC,OAAQ,CAAC;AAC1C;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEclH,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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8CI;AA3CJ,qBAAkD;AAClD,kBAA4B;AAC5B,kBAAsB;AACtB,wBAAwB;AACxB,iBAA4B;AAC5B,uBAWO;AACP,0BAGO;AACP,kBAAuC;AAKvC,mBAAiE;AACjE,mBAAiC;AACjC,iCAAuC;AAIvC,MAAM,gBAAgB;AAAA,EACrB,GAAG,gCAAY;AAAA,EACf;AAAA,IACC,IAAI;AAAA,IACJ,WAAO,gBAAI,kBAAmB;AAAA,EAC/B;AAAA,EACA;AAAA,IACC,IAAI;AAAA,IACJ,WAAO,gBAAI,0BAA2B;AAAA,IACtC,QAAQ,CAAE,SAAS,OAAO,aAAc;AACvC,aACC;AAAA,QAAC,2BAAAA;AAAA,QAAA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA;AAAA,MACD;AAAA,IAEF;AAAA,EACD;AACD;AAEA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ACT,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,eAAW,gCAAmB,OAAO;AAAA,MAC1C,MAAM;AAAA,IACP,CAAE;AAEF,gBAAY,SAAS;AAIrB,cAAU,SAAS,MAAM;AAAA,EAC1B;AAGA,aAAO,wBAAO,OAAO,WAAW,OAAQ;AACzC;AAEA,IAAO,iBAAQ;",
|
|
6
|
+
"names": ["CSSClassesSettingComponent", "blockEditorStore", "settings"]
|
|
7
|
+
}
|
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var use_link_instance_key_exports = {};
|
|
19
|
+
__export(use_link_instance_key_exports, {
|
|
20
|
+
default: () => use_link_instance_key_default
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
const weakMap = new WeakMap();
|
|
9
|
-
|
|
10
|
-
// Incrementing zero-based ID value.
|
|
22
|
+
module.exports = __toCommonJS(use_link_instance_key_exports);
|
|
23
|
+
const weakMap = /* @__PURE__ */ new WeakMap();
|
|
11
24
|
let id = -1;
|
|
12
|
-
const prefix =
|
|
25
|
+
const prefix = "link-control-instance";
|
|
13
26
|
function getKey(_id) {
|
|
14
27
|
return `${prefix}-${_id}`;
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Builds a unique link control key for the given object reference.
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} instance an unique object reference specific to this link control instance.
|
|
21
|
-
* @return {string | undefined} the unique key to use for this link control.
|
|
22
|
-
*/
|
|
23
29
|
function useLinkInstanceKey(instance) {
|
|
24
30
|
if (!instance) {
|
|
25
31
|
return;
|
|
@@ -31,5 +37,5 @@ function useLinkInstanceKey(instance) {
|
|
|
31
37
|
weakMap.set(instance, id);
|
|
32
38
|
return getKey(id);
|
|
33
39
|
}
|
|
34
|
-
var
|
|
35
|
-
//# sourceMappingURL=use-link-instance-key.js.map
|
|
40
|
+
var use_link_instance_key_default = useLinkInstanceKey;
|
|
41
|
+
//# 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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
+
}
|