PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / format-library / index.js

index.js in Gutenberg 22.3.0, at build/scripts/format-library/index.js

2,015 lines 73.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 var wp;
2 (wp ||= {}).formatLibrary = (() => {
3 var __create = Object.create;
4 var __defProp = Object.defineProperty;
5 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6 var __getOwnPropNames = Object.getOwnPropertyNames;
7 var __getProtoOf = Object.getPrototypeOf;
8 var __hasOwnProp = Object.prototype.hasOwnProperty;
9 var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10 get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11 }) : x)(function(x) {
12 if (typeof require !== "undefined") return require.apply(this, arguments);
13 throw Error('Dynamic require of "' + x + '" is not supported');
14 });
15 var __commonJS = (cb, mod) => function __require2() {
16 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17 };
18 var __copyProps = (to, from, except, desc) => {
19 if (from && typeof from === "object" || typeof from === "function") {
20 for (let key of __getOwnPropNames(from))
21 if (!__hasOwnProp.call(to, key) && key !== except)
22 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23 }
24 return to;
25 };
26 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27 // If the importer is in node compatibility mode or this is not an ESM
28 // file that has been converted to a CommonJS file using a Babel-
29 // compatible transform (i.e. "__esModule" has not been set), then set
30 // "default" to the CommonJS "module.exports" for node compatibility.
31 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32 mod
33 ));
34
35 // package-external:@wordpress/rich-text
36 var require_rich_text = __commonJS({
37 "package-external:@wordpress/rich-text"(exports, module) {
38 module.exports = window.wp.richText;
39 }
40 });
41
42 // package-external:@wordpress/i18n
43 var require_i18n = __commonJS({
44 "package-external:@wordpress/i18n"(exports, module) {
45 module.exports = window.wp.i18n;
46 }
47 });
48
49 // package-external:@wordpress/block-editor
50 var require_block_editor = __commonJS({
51 "package-external:@wordpress/block-editor"(exports, module) {
52 module.exports = window.wp.blockEditor;
53 }
54 });
55
56 // package-external:@wordpress/element
57 var require_element = __commonJS({
58 "package-external:@wordpress/element"(exports, module) {
59 module.exports = window.wp.element;
60 }
61 });
62
63 // package-external:@wordpress/primitives
64 var require_primitives = __commonJS({
65 "package-external:@wordpress/primitives"(exports, module) {
66 module.exports = window.wp.primitives;
67 }
68 });
69
70 // vendor-external:react/jsx-runtime
71 var require_jsx_runtime = __commonJS({
72 "vendor-external:react/jsx-runtime"(exports, module) {
73 module.exports = window.ReactJSXRuntime;
74 }
75 });
76
77 // package-external:@wordpress/private-apis
78 var require_private_apis = __commonJS({
79 "package-external:@wordpress/private-apis"(exports, module) {
80 module.exports = window.wp.privateApis;
81 }
82 });
83
84 // package-external:@wordpress/components
85 var require_components = __commonJS({
86 "package-external:@wordpress/components"(exports, module) {
87 module.exports = window.wp.components;
88 }
89 });
90
91 // package-external:@wordpress/url
92 var require_url = __commonJS({
93 "package-external:@wordpress/url"(exports, module) {
94 module.exports = window.wp.url;
95 }
96 });
97
98 // package-external:@wordpress/html-entities
99 var require_html_entities = __commonJS({
100 "package-external:@wordpress/html-entities"(exports, module) {
101 module.exports = window.wp.htmlEntities;
102 }
103 });
104
105 // package-external:@wordpress/a11y
106 var require_a11y = __commonJS({
107 "package-external:@wordpress/a11y"(exports, module) {
108 module.exports = window.wp.a11y;
109 }
110 });
111
112 // package-external:@wordpress/data
113 var require_data = __commonJS({
114 "package-external:@wordpress/data"(exports, module) {
115 module.exports = window.wp.data;
116 }
117 });
118
119 // package-external:@wordpress/compose
120 var require_compose = __commonJS({
121 "package-external:@wordpress/compose"(exports, module) {
122 module.exports = window.wp.compose;
123 }
124 });
125
126 // packages/format-library/build-module/index.js
127 var import_rich_text18 = __toESM(require_rich_text());
128
129 // packages/format-library/build-module/bold/index.js
130 var import_i18n = __toESM(require_i18n());
131 var import_rich_text = __toESM(require_rich_text());
132 var import_block_editor = __toESM(require_block_editor());
133
134 // packages/icons/build-module/icon/index.js
135 var import_element = __toESM(require_element());
136 var icon_default = (0, import_element.forwardRef)(
137 ({ icon, size = 24, ...props }, ref) => {
138 return (0, import_element.cloneElement)(icon, {
139 width: size,
140 height: size,
141 ...props,
142 ref
143 });
144 }
145 );
146
147 // packages/icons/build-module/library/button.js
148 var import_primitives = __toESM(require_primitives());
149 var import_jsx_runtime = __toESM(require_jsx_runtime());
150 var button_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.Path, { d: "M8 12.5h8V11H8v1.5Z M19 6.5H5a2 2 0 0 0-2 2V15a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.5a2 2 0 0 0-2-2ZM5 8h14a.5.5 0 0 1 .5.5V15a.5.5 0 0 1-.5.5H5a.5.5 0 0 1-.5-.5V8.5A.5.5 0 0 1 5 8Z" }) });
151
152 // packages/icons/build-module/library/code.js
153 var import_primitives2 = __toESM(require_primitives());
154 var import_jsx_runtime2 = __toESM(require_jsx_runtime());
155 var code_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.Path, { d: "M20.8 10.7l-4.3-4.3-1.1 1.1 4.3 4.3c.1.1.1.3 0 .4l-4.3 4.3 1.1 1.1 4.3-4.3c.7-.8.7-1.9 0-2.6zM4.2 11.8l4.3-4.3-1-1-4.3 4.3c-.7.7-.7 1.8 0 2.5l4.3 4.3 1.1-1.1-4.3-4.3c-.2-.1-.2-.3-.1-.4z" }) });
156
157 // packages/icons/build-module/library/color.js
158 var import_primitives3 = __toESM(require_primitives());
159 var import_jsx_runtime3 = __toESM(require_jsx_runtime());
160 var color_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.Path, { d: "M17.2 10.9c-.5-1-1.2-2.1-2.1-3.2-.6-.9-1.3-1.7-2.1-2.6L12 4l-1 1.1c-.6.9-1.3 1.7-2 2.6-.8 1.2-1.5 2.3-2 3.2-.6 1.2-1 2.2-1 3 0 3.4 2.7 6.1 6.1 6.1s6.1-2.7 6.1-6.1c0-.8-.3-1.8-1-3zm-5.1 7.6c-2.5 0-4.6-2.1-4.6-4.6 0-.3.1-1 .8-2.3.5-.9 1.1-1.9 2-3.1.7-.9 1.3-1.7 1.8-2.3.7.8 1.3 1.6 1.8 2.3.8 1.1 1.5 2.2 2 3.1.7 1.3.8 2 .8 2.3 0 2.5-2.1 4.6-4.6 4.6z" }) });
161
162 // packages/icons/build-module/library/format-bold.js
163 var import_primitives4 = __toESM(require_primitives());
164 var import_jsx_runtime4 = __toESM(require_jsx_runtime());
165 var format_bold_default = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_primitives4.Path, { d: "M14.7 11.3c1-.6 1.5-1.6 1.5-3 0-2.3-1.3-3.4-4-3.4H7v14h5.8c1.4 0 2.5-.3 3.3-1 .8-.7 1.2-1.7 1.2-2.9.1-1.9-.8-3.1-2.6-3.7zm-5.1-4h2.3c.6 0 1.1.1 1.4.4.3.3.5.7.5 1.2s-.2 1-.5 1.2c-.3.3-.8.4-1.4.4H9.6V7.3zm4.6 9c-.4.3-1 .4-1.7.4H9.6v-3.9h2.9c.7 0 1.3.2 1.7.5.4.3.6.8.6 1.5s-.2 1.2-.6 1.5z" }) });
166
167 // packages/icons/build-module/library/format-italic.js
168 var import_primitives5 = __toESM(require_primitives());
169 var import_jsx_runtime5 = __toESM(require_jsx_runtime());
170 var format_italic_default = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_primitives5.Path, { d: "M12.5 5L10 19h1.9l2.5-14z" }) });
171
172 // packages/icons/build-module/library/format-strikethrough.js
173 var import_primitives6 = __toESM(require_primitives());
174 var import_jsx_runtime6 = __toESM(require_jsx_runtime());
175 var format_strikethrough_default = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_primitives6.Path, { d: "M9.1 9v-.5c0-.6.2-1.1.7-1.4.5-.3 1.2-.5 2-.5.7 0 1.4.1 2.1.3.7.2 1.4.5 2.1.9l.2-1.9c-.6-.3-1.2-.5-1.9-.7-.8-.1-1.6-.2-2.4-.2-1.5 0-2.7.3-3.6 1-.8.7-1.2 1.5-1.2 2.6V9h2zM20 12H4v1h8.3c.3.1.6.2.8.3.5.2.9.5 1.1.8.3.3.4.7.4 1.2 0 .7-.2 1.1-.8 1.5-.5.3-1.2.5-2.1.5-.8 0-1.6-.1-2.4-.3-.8-.2-1.5-.5-2.2-.8L7 18.1c.5.2 1.2.4 2 .6.8.2 1.6.3 2.4.3 1.7 0 3-.3 3.9-1 .9-.7 1.3-1.6 1.3-2.8 0-.9-.2-1.7-.7-2.2H20v-1z" }) });
176
177 // packages/icons/build-module/library/help.js
178 var import_primitives7 = __toESM(require_primitives());
179 var import_jsx_runtime7 = __toESM(require_jsx_runtime());
180 var help_default = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_primitives7.Path, { d: "M12 4a8 8 0 1 1 .001 16.001A8 8 0 0 1 12 4Zm0 1.5a6.5 6.5 0 1 0-.001 13.001A6.5 6.5 0 0 0 12 5.5Zm.75 11h-1.5V15h1.5v1.5Zm-.445-9.234a3 3 0 0 1 .445 5.89V14h-1.5v-1.25c0-.57.452-.958.917-1.01A1.5 1.5 0 0 0 12 8.75a1.5 1.5 0 0 0-1.5 1.5H9a3 3 0 0 1 3.305-2.984Z" }) });
181
182 // packages/icons/build-module/library/language.js
183 var import_primitives8 = __toESM(require_primitives());
184 var import_jsx_runtime8 = __toESM(require_jsx_runtime());
185 var language_default = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_primitives8.Path, { d: "M17.5 10h-1.7l-3.7 10.5h1.7l.9-2.6h3.9l.9 2.6h1.7L17.5 10zm-2.2 6.3 1.4-4 1.4 4h-2.8zm-4.8-3.8c1.6-1.8 2.9-3.6 3.7-5.7H16V5.2h-5.8V3H8.8v2.2H3v1.5h9.6c-.7 1.6-1.8 3.1-3.1 4.6C8.6 10.2 7.8 9 7.2 8H5.6c.6 1.4 1.7 2.9 2.9 4.4l-2.4 2.4c-.3.4-.7.8-1.1 1.2l1 1 1.2-1.2c.8-.8 1.6-1.5 2.3-2.3.8.9 1.7 1.7 2.5 2.5l.6-1.5c-.7-.6-1.4-1.3-2.1-2z" }) });
186
187 // packages/icons/build-module/library/link.js
188 var import_primitives9 = __toESM(require_primitives());
189 var import_jsx_runtime9 = __toESM(require_jsx_runtime());
190 var link_default = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_primitives9.Path, { d: "M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z" }) });
191
192 // packages/icons/build-module/library/math.js
193 var import_primitives10 = __toESM(require_primitives());
194 var import_jsx_runtime10 = __toESM(require_jsx_runtime());
195 var math_default = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_primitives10.Path, { d: "M11.2 6.8c-.7 0-1.4.5-1.6 1.1l-2.8 7.5-1.2-1.8c-.1-.2-.4-.3-.6-.3H3v1.5h1.6l1.2 1.8c.6.9 1.9.7 2.2-.3l2.9-7.9s.1-.2.2-.2h7.8V6.7h-7.8Zm5.3 3.4-1.9 1.9-1.9-1.9-1.1 1.1 1.9 1.9-1.9 1.9 1.1 1.1 1.9-1.9 1.9 1.9 1.1-1.1-1.9-1.9 1.9-1.9-1.1-1.1Z" }) });
196
197 // packages/icons/build-module/library/subscript.js
198 var import_primitives11 = __toESM(require_primitives());
199 var import_jsx_runtime11 = __toESM(require_jsx_runtime());
200 var subscript_default = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_primitives11.Path, { d: "M16.9 18.3l.8-1.2c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.1-.3-.4-.5-.6-.7-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.2 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3L15 19.4h4.3v-1.2h-2.4zM14.1 7.2h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) });
201
202 // packages/icons/build-module/library/superscript.js
203 var import_primitives12 = __toESM(require_primitives());
204 var import_jsx_runtime12 = __toESM(require_jsx_runtime());
205 var superscript_default = /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_primitives12.Path, { d: "M16.9 10.3l.8-1.3c.4-.6.7-1.2.9-1.6.2-.4.3-.8.3-1.2 0-.3-.1-.7-.2-1-.2-.2-.4-.4-.7-.6-.3-.2-.6-.3-1-.3s-.8.1-1.1.2c-.3.1-.7.3-1 .6l.1 1.3c.3-.3.5-.5.8-.6s.6-.2.9-.2c.3 0 .5.1.7.2.2.2.2.4.2.7 0 .3-.1.5-.2.8-.1.3-.4.7-.8 1.3l-1.8 2.8h4.3v-1.2h-2.2zm-2.8-3.1h-2L9.5 11 6.9 7.2h-2l3.6 5.3L4.7 18h2l2.7-4 2.7 4h2l-3.8-5.5 3.8-5.3z" }) });
206
207 // packages/icons/build-module/library/text-color.js
208 var import_primitives13 = __toESM(require_primitives());
209 var import_jsx_runtime13 = __toESM(require_jsx_runtime());
210 var text_color_default = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_primitives13.Path, { d: "M12.9 6h-2l-4 11h1.9l1.1-3h4.2l1.1 3h1.9L12.9 6zm-2.5 6.5l1.5-4.9 1.7 4.9h-3.2z" }) });
211
212 // packages/format-library/build-module/lock-unlock.js
213 var import_private_apis = __toESM(require_private_apis());
214 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
215 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
216 "@wordpress/format-library"
217 );
218
219 // packages/format-library/build-module/bold/index.js
220 var import_jsx_runtime14 = __toESM(require_jsx_runtime());
221 var { essentialFormatKey } = unlock(import_block_editor.privateApis);
222 var name = "core/bold";
223 var title = (0, import_i18n.__)("Bold");
224 var bold = {
225 name,
226 title,
227 tagName: "strong",
228 className: null,
229 [essentialFormatKey]: true,
230 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
231 function onToggle() {
232 onChange((0, import_rich_text.toggleFormat)(value, { type: name, title }));
233 }
234 function onClick() {
235 onChange((0, import_rich_text.toggleFormat)(value, { type: name }));
236 onFocus();
237 }
238 return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
239 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
240 import_block_editor.RichTextShortcut,
241 {
242 type: "primary",
243 character: "b",
244 onUse: onToggle
245 }
246 ),
247 isVisible && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
248 import_block_editor.RichTextToolbarButton,
249 {
250 name: "bold",
251 icon: format_bold_default,
252 title,
253 onClick,
254 isActive,
255 shortcutType: "primary",
256 shortcutCharacter: "b"
257 }
258 ),
259 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
260 import_block_editor.__unstableRichTextInputEvent,
261 {
262 inputType: "formatBold",
263 onInput: onToggle
264 }
265 )
266 ] });
267 }
268 };
269
270 // packages/format-library/build-module/code/index.js
271 var import_i18n2 = __toESM(require_i18n());
272 var import_rich_text2 = __toESM(require_rich_text());
273 var import_block_editor2 = __toESM(require_block_editor());
274 var import_jsx_runtime15 = __toESM(require_jsx_runtime());
275 var name2 = "core/code";
276 var title2 = (0, import_i18n2.__)("Inline code");
277 var code = {
278 name: name2,
279 title: title2,
280 tagName: "code",
281 className: null,
282 __unstableInputRule(value) {
283 const BACKTICK = "`";
284 const { start, text } = value;
285 const characterBefore = text[start - 1];
286 if (characterBefore !== BACKTICK) {
287 return value;
288 }
289 if (start - 2 < 0) {
290 return value;
291 }
292 const indexBefore = text.lastIndexOf(BACKTICK, start - 2);
293 if (indexBefore === -1) {
294 return value;
295 }
296 const startIndex = indexBefore;
297 const endIndex = start - 2;
298 if (startIndex === endIndex) {
299 return value;
300 }
301 value = (0, import_rich_text2.remove)(value, startIndex, startIndex + 1);
302 value = (0, import_rich_text2.remove)(value, endIndex, endIndex + 1);
303 value = (0, import_rich_text2.applyFormat)(value, { type: name2 }, startIndex, endIndex);
304 return value;
305 },
306 edit({ value, onChange, onFocus, isActive }) {
307 function onClick() {
308 onChange((0, import_rich_text2.toggleFormat)(value, { type: name2, title: title2 }));
309 onFocus();
310 }
311 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
312 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
313 import_block_editor2.RichTextShortcut,
314 {
315 type: "access",
316 character: "x",
317 onUse: onClick
318 }
319 ),
320 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
321 import_block_editor2.RichTextToolbarButton,
322 {
323 icon: code_default,
324 title: title2,
325 onClick,
326 isActive,
327 role: "menuitemcheckbox"
328 }
329 )
330 ] });
331 }
332 };
333
334 // packages/format-library/build-module/image/index.js
335 var import_components = __toESM(require_components());
336 var import_i18n3 = __toESM(require_i18n());
337 var import_element2 = __toESM(require_element());
338 var import_rich_text3 = __toESM(require_rich_text());
339 var import_block_editor3 = __toESM(require_block_editor());
340 var import_jsx_runtime16 = __toESM(require_jsx_runtime());
341 var ALLOWED_MEDIA_TYPES = ["image"];
342 var name3 = "core/image";
343 var title3 = (0, import_i18n3.__)("Inline image");
344 function getCurrentImageId(activeObjectAttributes) {
345 if (!activeObjectAttributes?.className) {
346 return void 0;
347 }
348 const [, id] = activeObjectAttributes.className.match(/wp-image-(\d+)/) ?? [];
349 return id ? parseInt(id, 10) : void 0;
350 }
351 var image = {
352 name: name3,
353 title: title3,
354 keywords: [(0, import_i18n3.__)("photo"), (0, import_i18n3.__)("media")],
355 object: true,
356 tagName: "img",
357 className: null,
358 attributes: {
359 className: "class",
360 style: "style",
361 url: "src",
362 alt: "alt"
363 },
364 edit: Edit
365 };
366 function InlineUI({ value, onChange, activeObjectAttributes, contentRef }) {
367 const { style, alt } = activeObjectAttributes;
368 const width = style?.replace(/\D/g, "");
369 const [editedWidth, setEditedWidth] = (0, import_element2.useState)(width);
370 const [editedAlt, setEditedAlt] = (0, import_element2.useState)(alt);
371 const hasChanged = editedWidth !== width || editedAlt !== alt;
372 const popoverAnchor = (0, import_rich_text3.useAnchor)({
373 editableContentElement: contentRef.current,
374 settings: image
375 });
376 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
377 import_components.Popover,
378 {
379 focusOnMount: false,
380 anchor: popoverAnchor,
381 className: "block-editor-format-toolbar__image-popover",
382 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
383 "form",
384 {
385 className: "block-editor-format-toolbar__image-container-content",
386 onSubmit: (event) => {
387 const newReplacements = value.replacements.slice();
388 newReplacements[value.start] = {
389 type: name3,
390 attributes: {
391 ...activeObjectAttributes,
392 style: editedWidth ? `width: ${editedWidth}px;` : "",
393 alt: editedAlt
394 }
395 };
396 onChange({
397 ...value,
398 replacements: newReplacements
399 });
400 event.preventDefault();
401 },
402 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
403 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
404 import_components.__experimentalNumberControl,
405 {
406 __next40pxDefaultSize: true,
407 label: (0, import_i18n3.__)("Width"),
408 value: editedWidth,
409 min: 1,
410 onChange: (newWidth) => {
411 setEditedWidth(newWidth);
412 }
413 }
414 ),
415 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
416 import_components.TextareaControl,
417 {
418 label: (0, import_i18n3.__)("Alternative text"),
419 __nextHasNoMarginBottom: true,
420 value: editedAlt,
421 onChange: (newAlt) => {
422 setEditedAlt(newAlt);
423 },
424 help: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_jsx_runtime16.Fragment, { children: [
425 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
426 import_components.ExternalLink,
427 {
428 href: (
429 // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.
430 (0, import_i18n3.__)(
431 "https://www.w3.org/WAI/tutorials/images/decision-tree/"
432 )
433 ),
434 children: (0, import_i18n3.__)(
435 "Describe the purpose of the image."
436 )
437 }
438 ),
439 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("br", {}),
440 (0, import_i18n3.__)("Leave empty if decorative.")
441 ] })
442 }
443 ),
444 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.__experimentalHStack, { justify: "right", children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
445 import_components.Button,
446 {
447 disabled: !hasChanged,
448 accessibleWhenDisabled: true,
449 variant: "primary",
450 type: "submit",
451 size: "compact",
452 children: (0, import_i18n3.__)("Apply")
453 }
454 ) })
455 ] })
456 }
457 )
458 }
459 );
460 }
461 function Edit({
462 value,
463 onChange,
464 onFocus,
465 isObjectActive,
466 activeObjectAttributes,
467 contentRef
468 }) {
469 return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_block_editor3.MediaUploadCheck, { children: [
470 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
471 import_block_editor3.MediaUpload,
472 {
473 allowedTypes: ALLOWED_MEDIA_TYPES,
474 value: getCurrentImageId(activeObjectAttributes),
475 onSelect: ({ id, url, alt, width: imgWidth }) => {
476 onChange(
477 (0, import_rich_text3.insertObject)(value, {
478 type: name3,
479 attributes: {
480 className: `wp-image-${id}`,
481 style: `width: ${Math.min(
482 imgWidth,
483 150
484 )}px;`,
485 url,
486 alt
487 }
488 })
489 );
490 onFocus();
491 },
492 render: ({ open }) => /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
493 import_block_editor3.RichTextToolbarButton,
494 {
495 icon: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
496 import_components.SVG,
497 {
498 xmlns: "http://www.w3.org/2000/svg",
499 viewBox: "0 0 24 24",
500 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_components.Path, { d: "M4 18.5h16V17H4v1.5zM16 13v1.5h4V13h-4zM5.1 15h7.8c.6 0 1.1-.5 1.1-1.1V6.1c0-.6-.5-1.1-1.1-1.1H5.1C4.5 5 4 5.5 4 6.1v7.8c0 .6.5 1.1 1.1 1.1zm.4-8.5h7V10l-1-1c-.3-.3-.8-.3-1 0l-1.6 1.5-1.2-.7c-.3-.2-.6-.2-.9 0l-1.3 1V6.5zm0 6.1l1.8-1.3 1.3.8c.3.2.7.2.9-.1l1.5-1.4 1.5 1.4v1.5h-7v-.9z" })
501 }
502 ),
503 title: isObjectActive ? (0, import_i18n3.__)("Replace image") : title3,
504 onClick: open,
505 isActive: isObjectActive
506 }
507 )
508 }
509 ),
510 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
511 InlineUI,
512 {
513 value,
514 onChange,
515 activeObjectAttributes,
516 contentRef
517 }
518 )
519 ] });
520 }
521
522 // packages/format-library/build-module/italic/index.js
523 var import_i18n4 = __toESM(require_i18n());
524 var import_rich_text4 = __toESM(require_rich_text());
525 var import_block_editor4 = __toESM(require_block_editor());
526 var import_jsx_runtime17 = __toESM(require_jsx_runtime());
527 var { essentialFormatKey: essentialFormatKey2 } = unlock(import_block_editor4.privateApis);
528 var name4 = "core/italic";
529 var title4 = (0, import_i18n4.__)("Italic");
530 var italic = {
531 name: name4,
532 title: title4,
533 tagName: "em",
534 className: null,
535 [essentialFormatKey2]: true,
536 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
537 function onToggle() {
538 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4, title: title4 }));
539 }
540 function onClick() {
541 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4 }));
542 onFocus();
543 }
544 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
545 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
546 import_block_editor4.RichTextShortcut,
547 {
548 type: "primary",
549 character: "i",
550 onUse: onToggle
551 }
552 ),
553 isVisible && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
554 import_block_editor4.RichTextToolbarButton,
555 {
556 name: "italic",
557 icon: format_italic_default,
558 title: title4,
559 onClick,
560 isActive,
561 shortcutType: "primary",
562 shortcutCharacter: "i"
563 }
564 ),
565 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
566 import_block_editor4.__unstableRichTextInputEvent,
567 {
568 inputType: "formatItalic",
569 onInput: onToggle
570 }
571 )
572 ] });
573 }
574 };
575
576 // packages/format-library/build-module/link/index.js
577 var import_i18n7 = __toESM(require_i18n());
578 var import_element5 = __toESM(require_element());
579 var import_rich_text6 = __toESM(require_rich_text());
580 var import_url3 = __toESM(require_url());
581 var import_block_editor6 = __toESM(require_block_editor());
582 var import_html_entities = __toESM(require_html_entities());
583 var import_a11y2 = __toESM(require_a11y());
584
585 // packages/format-library/build-module/link/inline.js
586 var import_element4 = __toESM(require_element());
587 var import_i18n6 = __toESM(require_i18n());
588 var import_a11y = __toESM(require_a11y());
589 var import_components3 = __toESM(require_components());
590 var import_url2 = __toESM(require_url());
591 var import_rich_text5 = __toESM(require_rich_text());
592 var import_block_editor5 = __toESM(require_block_editor());
593 var import_data = __toESM(require_data());
594
595 // packages/format-library/build-module/link/utils.js
596 var import_url = __toESM(require_url());
597 function isValidHref(href) {
598 if (!href) {
599 return false;
600 }
601 const trimmedHref = href.trim();
602 if (!trimmedHref) {
603 return false;
604 }
605 if (/^\S+:/.test(trimmedHref)) {
606 const protocol = (0, import_url.getProtocol)(trimmedHref);
607 if (!(0, import_url.isValidProtocol)(protocol)) {
608 return false;
609 }
610 if (protocol.startsWith("http") && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) {
611 return false;
612 }
613 const authority = (0, import_url.getAuthority)(trimmedHref);
614 if (!(0, import_url.isValidAuthority)(authority)) {
615 return false;
616 }
617 const path = (0, import_url.getPath)(trimmedHref);
618 if (path && !(0, import_url.isValidPath)(path)) {
619 return false;
620 }
621 const queryString = (0, import_url.getQueryString)(trimmedHref);
622 if (queryString && !(0, import_url.isValidQueryString)(queryString)) {
623 return false;
624 }
625 const fragment = (0, import_url.getFragment)(trimmedHref);
626 if (fragment && !(0, import_url.isValidFragment)(fragment)) {
627 return false;
628 }
629 }
630 if (trimmedHref.startsWith("#") && !(0, import_url.isValidFragment)(trimmedHref)) {
631 return false;
632 }
633 return true;
634 }
635 function createLinkFormat({
636 url,
637 type,
638 id,
639 opensInNewWindow,
640 nofollow,
641 cssClasses
642 }) {
643 const format = {
644 type: "core/link",
645 attributes: {
646 url
647 }
648 };
649 if (type) {
650 format.attributes.type = type;
651 }
652 if (id) {
653 format.attributes.id = id;
654 }
655 if (opensInNewWindow) {
656 format.attributes.target = "_blank";
657 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " noreferrer noopener" : "noreferrer noopener";
658 }
659 if (nofollow) {
660 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " nofollow" : "nofollow";
661 }
662 const trimmedCssClasses = cssClasses?.trim();
663 if (trimmedCssClasses?.length) {
664 format.attributes.class = trimmedCssClasses;
665 }
666 return format;
667 }
668 function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
669 const EMPTY_BOUNDARIES = {
670 start: null,
671 end: null
672 };
673 const { formats } = value;
674 let targetFormat;
675 let initialIndex;
676 if (!formats?.length) {
677 return EMPTY_BOUNDARIES;
678 }
679 const newFormats = formats.slice();
680 const formatAtStart = newFormats[startIndex]?.find(
681 ({ type }) => type === format.type
682 );
683 const formatAtEnd = newFormats[endIndex]?.find(
684 ({ type }) => type === format.type
685 );
686 const formatAtEndMinusOne = newFormats[endIndex - 1]?.find(
687 ({ type }) => type === format.type
688 );
689 if (!!formatAtStart) {
690 targetFormat = formatAtStart;
691 initialIndex = startIndex;
692 } else if (!!formatAtEnd) {
693 targetFormat = formatAtEnd;
694 initialIndex = endIndex;
695 } else if (!!formatAtEndMinusOne) {
696 targetFormat = formatAtEndMinusOne;
697 initialIndex = endIndex - 1;
698 } else {
699 return EMPTY_BOUNDARIES;
700 }
701 const index = newFormats[initialIndex].indexOf(targetFormat);
702 const walkingArgs = [newFormats, initialIndex, targetFormat, index];
703 startIndex = walkToStart(...walkingArgs);
704 endIndex = walkToEnd(...walkingArgs);
705 startIndex = startIndex < 0 ? 0 : startIndex;
706 return {
707 start: startIndex,
708 end: endIndex
709 };
710 }
711 function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
712 let index = initialIndex;
713 const directions = {
714 forwards: 1,
715 backwards: -1
716 };
717 const directionIncrement = directions[direction] || 1;
718 const inverseDirectionIncrement = directionIncrement * -1;
719 while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
720 index = index + directionIncrement;
721 }
722 index = index + inverseDirectionIncrement;
723 return index;
724 }
725 var partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
726 var walkToStart = partialRight(walkToBoundary, "backwards");
727 var walkToEnd = partialRight(walkToBoundary, "forwards");
728
729 // packages/format-library/build-module/link/css-classes-setting.js
730 var import_element3 = __toESM(require_element());
731 var import_compose = __toESM(require_compose());
732 var import_i18n5 = __toESM(require_i18n());
733 var import_components2 = __toESM(require_components());
734 var import_jsx_runtime18 = __toESM(require_jsx_runtime());
735 var CSSClassesSettingComponent = ({ setting, value, onChange }) => {
736 const hasValue = value ? value?.cssClasses?.length > 0 : false;
737 const [isSettingActive, setIsSettingActive] = (0, import_element3.useState)(hasValue);
738 const instanceId = (0, import_compose.useInstanceId)(CSSClassesSettingComponent);
739 const controlledRegionId = `css-classes-setting-${instanceId}`;
740 const handleSettingChange = (newValue) => {
741 const sanitizedValue = typeof newValue === "string" ? newValue.replace(/,/g, " ").replace(/\s+/g, " ").trim() : newValue;
742 onChange({
743 ...value,
744 [setting.id]: sanitizedValue
745 });
746 };
747 const handleCheckboxChange = () => {
748 if (isSettingActive) {
749 if (hasValue) {
750 handleSettingChange("");
751 }
752 setIsSettingActive(false);
753 } else {
754 setIsSettingActive(true);
755 }
756 };
757 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("fieldset", { children: [
758 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(import_components2.VisuallyHidden, { as: "legend", children: setting.title }),
759 /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_components2.__experimentalVStack, { spacing: 3, children: [
760 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
761 import_components2.CheckboxControl,
762 {
763 __nextHasNoMarginBottom: true,
764 label: setting.title,
765 onChange: handleCheckboxChange,
766 checked: isSettingActive || hasValue,
767 "aria-expanded": isSettingActive,
768 "aria-controls": isSettingActive ? controlledRegionId : void 0
769 }
770 ),
771 isSettingActive && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { id: controlledRegionId, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
772 import_components2.__experimentalInputControl,
773 {
774 label: (0, import_i18n5.__)("CSS classes"),
775 value: value?.cssClasses,
776 onChange: handleSettingChange,
777 help: (0, import_i18n5.__)(
778 "Separate multiple classes with spaces."
779 ),
780 __unstableInputWidth: "100%",
781 __next40pxDefaultSize: true
782 }
783 ) })
784 ] })
785 ] });
786 };
787 var css_classes_setting_default = CSSClassesSettingComponent;
788
789 // packages/format-library/build-module/link/inline.js
790 var import_jsx_runtime19 = __toESM(require_jsx_runtime());
791 var LINK_SETTINGS = [
792 ...import_block_editor5.LinkControl.DEFAULT_LINK_SETTINGS,
793 {
794 id: "nofollow",
795 title: (0, import_i18n6.__)("Mark as nofollow")
796 },
797 {
798 id: "cssClasses",
799 title: (0, import_i18n6.__)("Additional CSS class(es)"),
800 render: (setting, value, onChange) => {
801 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
802 css_classes_setting_default,
803 {
804 setting,
805 value,
806 onChange
807 }
808 );
809 }
810 }
811 ];
812 function InlineLinkUI({
813 isActive,
814 activeAttributes,
815 value,
816 onChange,
817 onFocusOutside,
818 stopAddingLink,
819 contentRef,
820 focusOnMount
821 }) {
822 const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
823 const richTextText = richLinkTextValue.text;
824 const { selectionChange } = (0, import_data.useDispatch)(import_block_editor5.store);
825 const { createPageEntity, userCanCreatePages, selectionStart } = (0, import_data.useSelect)(
826 (select) => {
827 const { getSettings, getSelectionStart } = select(import_block_editor5.store);
828 const _settings = getSettings();
829 return {
830 createPageEntity: _settings.__experimentalCreatePageEntity,
831 userCanCreatePages: _settings.__experimentalUserCanCreatePages,
832 selectionStart: getSelectionStart()
833 };
834 },
835 []
836 );
837 const linkValue = (0, import_element4.useMemo)(
838 () => ({
839 url: activeAttributes.url,
840 type: activeAttributes.type,
841 id: activeAttributes.id,
842 opensInNewTab: activeAttributes.target === "_blank",
843 nofollow: activeAttributes.rel?.includes("nofollow"),
844 title: richTextText,
845 cssClasses: activeAttributes.class
846 }),
847 [
848 activeAttributes.class,
849 activeAttributes.id,
850 activeAttributes.rel,
851 activeAttributes.target,
852 activeAttributes.type,
853 activeAttributes.url,
854 richTextText
855 ]
856 );
857 function removeLink() {
858 const newValue = (0, import_rich_text5.removeFormat)(value, "core/link");
859 onChange(newValue);
860 stopAddingLink();
861 (0, import_a11y.speak)((0, import_i18n6.__)("Link removed."), "assertive");
862 }
863 function onChangeLink(nextValue) {
864 const hasLink = linkValue?.url;
865 const isNewLink = !hasLink;
866 nextValue = {
867 ...linkValue,
868 ...nextValue
869 };
870 const newUrl = (0, import_url2.prependHTTP)(nextValue.url);
871 const linkFormat = createLinkFormat({
872 url: newUrl,
873 type: nextValue.type,
874 id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0,
875 opensInNewWindow: nextValue.opensInNewTab,
876 nofollow: nextValue.nofollow,
877 cssClasses: nextValue.cssClasses
878 });
879 const newText = nextValue.title || newUrl;
880 let newValue;
881 if ((0, import_rich_text5.isCollapsed)(value) && !isActive) {
882 const inserted = (0, import_rich_text5.insert)(value, newText);
883 newValue = (0, import_rich_text5.applyFormat)(
884 inserted,
885 linkFormat,
886 value.start,
887 value.start + newText.length
888 );
889 onChange(newValue);
890 stopAddingLink();
891 selectionChange({
892 clientId: selectionStart.clientId,
893 identifier: selectionStart.attributeKey,
894 start: value.start + newText.length + 1
895 });
896 return;
897 } else if (newText === richTextText) {
898 newValue = (0, import_rich_text5.applyFormat)(value, linkFormat);
899 } else {
900 newValue = (0, import_rich_text5.create)({ text: newText });
901 newValue = (0, import_rich_text5.applyFormat)(newValue, linkFormat, 0, newText.length);
902 const boundary = getFormatBoundary(value, {
903 type: "core/link"
904 });
905 const [valBefore, valAfter] = (0, import_rich_text5.split)(
906 value,
907 boundary.start,
908 boundary.start
909 );
910 const newValAfter = (0, import_rich_text5.replace)(valAfter, richTextText, newValue);
911 newValue = (0, import_rich_text5.concat)(valBefore, newValAfter);
912 }
913 onChange(newValue);
914 if (!isNewLink) {
915 stopAddingLink();
916 }
917 if (!isValidHref(newUrl)) {
918 (0, import_a11y.speak)(
919 (0, import_i18n6.__)(
920 "Warning: the link has been inserted but may have errors. Please test it."
921 ),
922 "assertive"
923 );
924 } else if (isActive) {
925 (0, import_a11y.speak)((0, import_i18n6.__)("Link edited."), "assertive");
926 } else {
927 (0, import_a11y.speak)((0, import_i18n6.__)("Link inserted."), "assertive");
928 }
929 }
930 const popoverAnchor = (0, import_rich_text5.useAnchor)({
931 editableContentElement: contentRef.current,
932 settings: {
933 ...link,
934 isActive
935 }
936 });
937 async function handleCreate(pageTitle) {
938 const page = await createPageEntity({
939 title: pageTitle,
940 status: "draft"
941 });
942 return {
943 id: page.id,
944 type: page.type,
945 title: page.title.rendered,
946 url: page.link,
947 kind: "post-type"
948 };
949 }
950 function createButtonText(searchTerm) {
951 return (0, import_element4.createInterpolateElement)(
952 (0, import_i18n6.sprintf)(
953 /* translators: %s: search term. */
954 (0, import_i18n6.__)("Create page: <mark>%s</mark>"),
955 searchTerm
956 ),
957 { mark: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("mark", {}) }
958 );
959 }
960 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
961 import_components3.Popover,
962 {
963 anchor: popoverAnchor,
964 animate: false,
965 onClose: stopAddingLink,
966 onFocusOutside,
967 placement: "bottom",
968 offset: 8,
969 shift: true,
970 focusOnMount,
971 constrainTabbing: true,
972 children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
973 import_block_editor5.LinkControl,
974 {
975 value: linkValue,
976 onChange: onChangeLink,
977 onRemove: removeLink,
978 hasRichPreviews: true,
979 createSuggestion: createPageEntity && handleCreate,
980 withCreateSuggestion: userCanCreatePages,
981 createSuggestionButtonText: createButtonText,
982 hasTextControl: true,
983 settings: LINK_SETTINGS,
984 showInitialSuggestions: true,
985 suggestionsQuery: {
986 // always show Pages as initial suggestions
987 initialSuggestionsSearchOptions: {
988 type: "post",
989 subtype: "page",
990 perPage: 20
991 }
992 }
993 }
994 )
995 }
996 );
997 }
998 function getRichTextValueFromSelection(value, isActive) {
999 let textStart = value.start;
1000 let textEnd = value.end;
1001 if (isActive) {
1002 const boundary = getFormatBoundary(value, {
1003 type: "core/link"
1004 });
1005 textStart = boundary.start;
1006 textEnd = boundary.end + 1;
1007 }
1008 return (0, import_rich_text5.slice)(value, textStart, textEnd);
1009 }
1010 var inline_default = InlineLinkUI;
1011
1012 // packages/format-library/build-module/link/index.js
1013 var import_jsx_runtime20 = __toESM(require_jsx_runtime());
1014 var { essentialFormatKey: essentialFormatKey3 } = unlock(import_block_editor6.privateApis);
1015 var name5 = "core/link";
1016 var title5 = (0, import_i18n7.__)("Link");
1017 function Edit2({
1018 isActive,
1019 activeAttributes,
1020 value,
1021 onChange,
1022 onFocus,
1023 contentRef,
1024 isVisible = true
1025 }) {
1026 const [addingLink, setAddingLink] = (0, import_element5.useState)(false);
1027 const [openedBy, setOpenedBy] = (0, import_element5.useState)(null);
1028 (0, import_element5.useEffect)(() => {
1029 if (!isActive) {
1030 setAddingLink(false);
1031 }
1032 }, [isActive]);
1033 (0, import_element5.useLayoutEffect)(() => {
1034 const editableContentElement = contentRef.current;
1035 if (!editableContentElement) {
1036 return;
1037 }
1038 function handleClick(event) {
1039 const link2 = event.target.closest("[contenteditable] a");
1040 if (!link2 || // other formats (e.g. bold) may be nested within the link.
1041 !isActive) {
1042 return;
1043 }
1044 setAddingLink(true);
1045 setOpenedBy({
1046 el: link2,
1047 action: "click"
1048 });
1049 }
1050 editableContentElement.addEventListener("click", handleClick);
1051 return () => {
1052 editableContentElement.removeEventListener("click", handleClick);
1053 };
1054 }, [contentRef, isActive]);
1055 function addLink(target) {
1056 const text = (0, import_rich_text6.getTextContent)((0, import_rich_text6.slice)(value));
1057 if (!isActive && text && (0, import_url3.isURL)(text) && isValidHref(text)) {
1058 onChange(
1059 (0, import_rich_text6.applyFormat)(value, {
1060 type: name5,
1061 attributes: { url: text }
1062 })
1063 );
1064 } else if (!isActive && text && (0, import_url3.isEmail)(text)) {
1065 onChange(
1066 (0, import_rich_text6.applyFormat)(value, {
1067 type: name5,
1068 attributes: { url: `mailto:${text}` }
1069 })
1070 );
1071 } else if (!isActive && text && (0, import_url3.isPhoneNumber)(text)) {
1072 onChange(
1073 (0, import_rich_text6.applyFormat)(value, {
1074 type: name5,
1075 attributes: { url: `tel:${text.replace(/\D/g, "")}` }
1076 })
1077 );
1078 } else {
1079 if (target) {
1080 setOpenedBy({
1081 el: target,
1082 action: null
1083 // We don't need to distinguish between click or keyboard here
1084 });
1085 }
1086 setAddingLink(true);
1087 }
1088 }
1089 function stopAddingLink() {
1090 setAddingLink(false);
1091 if (openedBy?.el?.tagName === "BUTTON") {
1092 openedBy.el.focus();
1093 } else {
1094 onFocus();
1095 }
1096 setOpenedBy(null);
1097 }
1098 function onFocusOutside() {
1099 setAddingLink(false);
1100 setOpenedBy(null);
1101 }
1102 function onRemoveFormat() {
1103 onChange((0, import_rich_text6.removeFormat)(value, name5));
1104 (0, import_a11y2.speak)((0, import_i18n7.__)("Link removed."), "assertive");
1105 }
1106 const shouldAutoFocus = !(openedBy?.el?.tagName === "A" && openedBy?.action === "click");
1107 const hasSelection = !(0, import_rich_text6.isCollapsed)(value);
1108 return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
1109 hasSelection && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1110 import_block_editor6.RichTextShortcut,
1111 {
1112 type: "primary",
1113 character: "k",
1114 onUse: addLink
1115 }
1116 ),
1117 /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1118 import_block_editor6.RichTextShortcut,
1119 {
1120 type: "primaryShift",
1121 character: "k",
1122 onUse: onRemoveFormat
1123 }
1124 ),
1125 isVisible && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1126 import_block_editor6.RichTextToolbarButton,
1127 {
1128 name: "link",
1129 icon: link_default,
1130 title: isActive ? (0, import_i18n7.__)("Link") : title5,
1131 onClick: (event) => {
1132 addLink(event.currentTarget);
1133 },
1134 isActive: isActive || addingLink,
1135 shortcutType: "primary",
1136 shortcutCharacter: "k",
1137 "aria-haspopup": "true",
1138 "aria-expanded": addingLink
1139 }
1140 ),
1141 isVisible && addingLink && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1142 inline_default,
1143 {
1144 stopAddingLink,
1145 onFocusOutside,
1146 isActive,
1147 activeAttributes,
1148 value,
1149 onChange,
1150 contentRef,
1151 focusOnMount: shouldAutoFocus ? "firstElement" : false
1152 }
1153 )
1154 ] });
1155 }
1156 var link = {
1157 name: name5,
1158 title: title5,
1159 tagName: "a",
1160 className: null,
1161 attributes: {
1162 url: "href",
1163 type: "data-type",
1164 id: "data-id",
1165 _id: "id",
1166 target: "target",
1167 rel: "rel",
1168 class: "class"
1169 },
1170 [essentialFormatKey3]: true,
1171 __unstablePasteRule(value, { html, plainText }) {
1172 const pastedText = (html || plainText).replace(/<[^>]+>/g, "").trim();
1173 if (!(0, import_url3.isURL)(pastedText) || !/^https?:/.test(pastedText)) {
1174 return value;
1175 }
1176 window.console.log("Created link:\n\n", pastedText);
1177 const format = {
1178 type: name5,
1179 attributes: {
1180 url: (0, import_html_entities.decodeEntities)(pastedText)
1181 }
1182 };
1183 if ((0, import_rich_text6.isCollapsed)(value)) {
1184 return (0, import_rich_text6.insert)(
1185 value,
1186 (0, import_rich_text6.applyFormat)(
1187 (0, import_rich_text6.create)({ text: plainText }),
1188 format,
1189 0,
1190 plainText.length
1191 )
1192 );
1193 }
1194 return (0, import_rich_text6.applyFormat)(value, format);
1195 },
1196 edit: Edit2
1197 };
1198
1199 // packages/format-library/build-module/strikethrough/index.js
1200 var import_i18n8 = __toESM(require_i18n());
1201 var import_rich_text7 = __toESM(require_rich_text());
1202 var import_block_editor7 = __toESM(require_block_editor());
1203 var import_jsx_runtime21 = __toESM(require_jsx_runtime());
1204 var name6 = "core/strikethrough";
1205 var title6 = (0, import_i18n8.__)("Strikethrough");
1206 var strikethrough = {
1207 name: name6,
1208 title: title6,
1209 tagName: "s",
1210 className: null,
1211 edit({ isActive, value, onChange, onFocus }) {
1212 function onClick() {
1213 onChange((0, import_rich_text7.toggleFormat)(value, { type: name6, title: title6 }));
1214 onFocus();
1215 }
1216 return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1217 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1218 import_block_editor7.RichTextShortcut,
1219 {
1220 type: "access",
1221 character: "d",
1222 onUse: onClick
1223 }
1224 ),
1225 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1226 import_block_editor7.RichTextToolbarButton,
1227 {
1228 icon: format_strikethrough_default,
1229 title: title6,
1230 onClick,
1231 isActive,
1232 role: "menuitemcheckbox"
1233 }
1234 )
1235 ] });
1236 }
1237 };
1238
1239 // packages/format-library/build-module/underline/index.js
1240 var import_i18n9 = __toESM(require_i18n());
1241 var import_rich_text8 = __toESM(require_rich_text());
1242 var import_block_editor8 = __toESM(require_block_editor());
1243 var import_jsx_runtime22 = __toESM(require_jsx_runtime());
1244 var name7 = "core/underline";
1245 var title7 = (0, import_i18n9.__)("Underline");
1246 var underline = {
1247 name: name7,
1248 title: title7,
1249 tagName: "span",
1250 className: null,
1251 attributes: {
1252 style: "style"
1253 },
1254 edit({ value, onChange }) {
1255 const onToggle = () => {
1256 onChange(
1257 (0, import_rich_text8.toggleFormat)(value, {
1258 type: name7,
1259 attributes: {
1260 style: "text-decoration: underline;"
1261 },
1262 title: title7
1263 })
1264 );
1265 };
1266 return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
1267 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1268 import_block_editor8.RichTextShortcut,
1269 {
1270 type: "primary",
1271 character: "u",
1272 onUse: onToggle
1273 }
1274 ),
1275 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1276 import_block_editor8.__unstableRichTextInputEvent,
1277 {
1278 inputType: "formatUnderline",
1279 onInput: onToggle
1280 }
1281 )
1282 ] });
1283 }
1284 };
1285
1286 // packages/format-library/build-module/text-color/index.js
1287 var import_i18n11 = __toESM(require_i18n());
1288 var import_element7 = __toESM(require_element());
1289 var import_block_editor10 = __toESM(require_block_editor());
1290 var import_rich_text10 = __toESM(require_rich_text());
1291
1292 // packages/format-library/build-module/text-color/inline.js
1293 var import_element6 = __toESM(require_element());
1294 var import_data2 = __toESM(require_data());
1295 var import_rich_text9 = __toESM(require_rich_text());
1296 var import_block_editor9 = __toESM(require_block_editor());
1297 var import_components4 = __toESM(require_components());
1298 var import_i18n10 = __toESM(require_i18n());
1299 var import_jsx_runtime23 = __toESM(require_jsx_runtime());
1300 var { Tabs } = unlock(import_components4.privateApis);
1301 var TABS = [
1302 { name: "color", title: (0, import_i18n10.__)("Text") },
1303 { name: "backgroundColor", title: (0, import_i18n10.__)("Background") }
1304 ];
1305 function parseCSS(css = "") {
1306 return css.split(";").reduce((accumulator, rule) => {
1307 if (rule) {
1308 const [property, value] = rule.split(":");
1309 if (property === "color") {
1310 accumulator.color = value;
1311 }
1312 if (property === "background-color" && value !== transparentValue) {
1313 accumulator.backgroundColor = value;
1314 }
1315 }
1316 return accumulator;
1317 }, {});
1318 }
1319 function parseClassName(className = "", colorSettings) {
1320 return className.split(" ").reduce((accumulator, name16) => {
1321 if (name16.startsWith("has-") && name16.endsWith("-color")) {
1322 const colorSlug = name16.replace(/^has-/, "").replace(/-color$/, "");
1323 const colorObject = (0, import_block_editor9.getColorObjectByAttributeValues)(
1324 colorSettings,
1325 colorSlug
1326 );
1327 accumulator.color = colorObject.color;
1328 }
1329 return accumulator;
1330 }, {});
1331 }
1332 function getActiveColors(value, name16, colorSettings) {
1333 const activeColorFormat = (0, import_rich_text9.getActiveFormat)(value, name16);
1334 if (!activeColorFormat) {
1335 return {};
1336 }
1337 return {
1338 ...parseCSS(activeColorFormat.attributes.style),
1339 ...parseClassName(activeColorFormat.attributes.class, colorSettings)
1340 };
1341 }
1342 function setColors(value, name16, colorSettings, colors) {
1343 const { color, backgroundColor } = {
1344 ...getActiveColors(value, name16, colorSettings),
1345 ...colors
1346 };
1347 if (!color && !backgroundColor) {
1348 return (0, import_rich_text9.removeFormat)(value, name16);
1349 }
1350 const styles = [];
1351 const classNames = [];
1352 const attributes = {};
1353 if (backgroundColor) {
1354 styles.push(["background-color", backgroundColor].join(":"));
1355 } else {
1356 styles.push(["background-color", transparentValue].join(":"));
1357 }
1358 if (color) {
1359 const colorObject = (0, import_block_editor9.getColorObjectByColorValue)(colorSettings, color);
1360 if (colorObject) {
1361 classNames.push((0, import_block_editor9.getColorClassName)("color", colorObject.slug));
1362 } else {
1363 styles.push(["color", color].join(":"));
1364 }
1365 }
1366 if (styles.length) {
1367 attributes.style = styles.join(";");
1368 }
1369 if (classNames.length) {
1370 attributes.class = classNames.join(" ");
1371 }
1372 return (0, import_rich_text9.applyFormat)(value, { type: name16, attributes });
1373 }
1374 function ColorPicker({ name: name16, property, value, onChange }) {
1375 const colors = (0, import_data2.useSelect)((select) => {
1376 const { getSettings } = select(import_block_editor9.store);
1377 return getSettings().colors ?? [];
1378 }, []);
1379 const activeColors = (0, import_element6.useMemo)(
1380 () => getActiveColors(value, name16, colors),
1381 [name16, value, colors]
1382 );
1383 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1384 import_block_editor9.ColorPalette,
1385 {
1386 value: activeColors[property],
1387 onChange: (color) => {
1388 onChange(
1389 setColors(value, name16, colors, { [property]: color })
1390 );
1391 },
1392 enableAlpha: true,
1393 __experimentalIsRenderedInSidebar: true
1394 }
1395 );
1396 }
1397 function InlineColorUI({
1398 name: name16,
1399 value,
1400 onChange,
1401 onClose,
1402 contentRef,
1403 isActive
1404 }) {
1405 const popoverAnchor = (0, import_rich_text9.useAnchor)({
1406 editableContentElement: contentRef.current,
1407 settings: { ...textColor, isActive }
1408 });
1409 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1410 import_components4.Popover,
1411 {
1412 onClose,
1413 className: "format-library__inline-color-popover",
1414 anchor: popoverAnchor,
1415 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Tabs, { children: [
1416 /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.TabList, { children: TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Tabs.Tab, { tabId: tab.name, children: tab.title }, tab.name)) }),
1417 TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1418 Tabs.TabPanel,
1419 {
1420 tabId: tab.name,
1421 focusable: false,
1422 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1423 ColorPicker,
1424 {
1425 name: name16,
1426 property: tab.name,
1427 value,
1428 onChange
1429 }
1430 )
1431 },
1432 tab.name
1433 ))
1434 ] })
1435 }
1436 );
1437 }
1438
1439 // packages/format-library/build-module/text-color/index.js
1440 var import_jsx_runtime24 = __toESM(require_jsx_runtime());
1441 var transparentValue = "rgba(0, 0, 0, 0)";
1442 var name8 = "core/text-color";
1443 var title8 = (0, import_i18n11.__)("Highlight");
1444 var EMPTY_ARRAY = [];
1445 function getComputedStyleProperty(element, property) {
1446 const { ownerDocument } = element;
1447 const { defaultView } = ownerDocument;
1448 const style = defaultView.getComputedStyle(element);
1449 const value = style.getPropertyValue(property);
1450 if (property === "background-color" && value === transparentValue && element.parentElement) {
1451 return getComputedStyleProperty(element.parentElement, property);
1452 }
1453 return value;
1454 }
1455 function fillComputedColors(element, { color, backgroundColor }) {
1456 if (!color && !backgroundColor) {
1457 return;
1458 }
1459 return {
1460 color: color || getComputedStyleProperty(element, "color"),
1461 backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, "background-color") : backgroundColor
1462 };
1463 }
1464 function TextColorEdit({
1465 value,
1466 onChange,
1467 isActive,
1468 activeAttributes,
1469 contentRef
1470 }) {
1471 const [allowCustomControl, colors = EMPTY_ARRAY] = (0, import_block_editor10.useSettings)(
1472 "color.custom",
1473 "color.palette"
1474 );
1475 const [isAddingColor, setIsAddingColor] = (0, import_element7.useState)(false);
1476 const colorIndicatorStyle = (0, import_element7.useMemo)(
1477 () => fillComputedColors(
1478 contentRef.current,
1479 getActiveColors(value, name8, colors)
1480 ),
1481 [contentRef, value, colors]
1482 );
1483 const hasColorsToChoose = !!colors.length || allowCustomControl;
1484 if (!hasColorsToChoose && !isActive) {
1485 return null;
1486 }
1487 return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
1488 /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1489 import_block_editor10.RichTextToolbarButton,
1490 {
1491 className: "format-library-text-color-button",
1492 isActive,
1493 icon: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1494 icon_default,
1495 {
1496 icon: Object.keys(activeAttributes).length ? text_color_default : color_default,
1497 style: colorIndicatorStyle
1498 }
1499 ),
1500 title: title8,
1501 onClick: hasColorsToChoose ? () => setIsAddingColor(true) : () => onChange((0, import_rich_text10.removeFormat)(value, name8)),
1502 role: "menuitemcheckbox"
1503 }
1504 ),
1505 isAddingColor && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1506 InlineColorUI,
1507 {
1508 name: name8,
1509 onClose: () => setIsAddingColor(false),
1510 activeAttributes,
1511 value,
1512 onChange,
1513 contentRef,
1514 isActive
1515 }
1516 )
1517 ] });
1518 }
1519 var textColor = {
1520 name: name8,
1521 title: title8,
1522 tagName: "mark",
1523 className: "has-inline-color",
1524 attributes: {
1525 style: "style",
1526 class: "class"
1527 },
1528 edit: TextColorEdit
1529 };
1530
1531 // packages/format-library/build-module/subscript/index.js
1532 var import_i18n12 = __toESM(require_i18n());
1533 var import_rich_text11 = __toESM(require_rich_text());
1534 var import_block_editor11 = __toESM(require_block_editor());
1535 var import_jsx_runtime25 = __toESM(require_jsx_runtime());
1536 var name9 = "core/subscript";
1537 var title9 = (0, import_i18n12.__)("Subscript");
1538 var subscript = {
1539 name: name9,
1540 title: title9,
1541 tagName: "sub",
1542 className: null,
1543 edit({ isActive, value, onChange, onFocus }) {
1544 function onToggle() {
1545 onChange((0, import_rich_text11.toggleFormat)(value, { type: name9, title: title9 }));
1546 }
1547 function onClick() {
1548 onToggle();
1549 onFocus();
1550 }
1551 return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
1552 import_block_editor11.RichTextToolbarButton,
1553 {
1554 icon: subscript_default,
1555 title: title9,
1556 onClick,
1557 isActive,
1558 role: "menuitemcheckbox"
1559 }
1560 );
1561 }
1562 };
1563
1564 // packages/format-library/build-module/superscript/index.js
1565 var import_i18n13 = __toESM(require_i18n());
1566 var import_rich_text12 = __toESM(require_rich_text());
1567 var import_block_editor12 = __toESM(require_block_editor());
1568 var import_jsx_runtime26 = __toESM(require_jsx_runtime());
1569 var name10 = "core/superscript";
1570 var title10 = (0, import_i18n13.__)("Superscript");
1571 var superscript = {
1572 name: name10,
1573 title: title10,
1574 tagName: "sup",
1575 className: null,
1576 edit({ isActive, value, onChange, onFocus }) {
1577 function onToggle() {
1578 onChange((0, import_rich_text12.toggleFormat)(value, { type: name10, title: title10 }));
1579 }
1580 function onClick() {
1581 onToggle();
1582 onFocus();
1583 }
1584 return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
1585 import_block_editor12.RichTextToolbarButton,
1586 {
1587 icon: superscript_default,
1588 title: title10,
1589 onClick,
1590 isActive,
1591 role: "menuitemcheckbox"
1592 }
1593 );
1594 }
1595 };
1596
1597 // packages/format-library/build-module/keyboard/index.js
1598 var import_i18n14 = __toESM(require_i18n());
1599 var import_rich_text13 = __toESM(require_rich_text());
1600 var import_block_editor13 = __toESM(require_block_editor());
1601 var import_jsx_runtime27 = __toESM(require_jsx_runtime());
1602 var name11 = "core/keyboard";
1603 var title11 = (0, import_i18n14.__)("Keyboard input");
1604 var keyboard = {
1605 name: name11,
1606 title: title11,
1607 tagName: "kbd",
1608 className: null,
1609 edit({ isActive, value, onChange, onFocus }) {
1610 function onToggle() {
1611 onChange((0, import_rich_text13.toggleFormat)(value, { type: name11, title: title11 }));
1612 }
1613 function onClick() {
1614 onToggle();
1615 onFocus();
1616 }
1617 return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
1618 import_block_editor13.RichTextToolbarButton,
1619 {
1620 icon: button_default,
1621 title: title11,
1622 onClick,
1623 isActive,
1624 role: "menuitemcheckbox"
1625 }
1626 );
1627 }
1628 };
1629
1630 // packages/format-library/build-module/unknown/index.js
1631 var import_i18n15 = __toESM(require_i18n());
1632 var import_rich_text14 = __toESM(require_rich_text());
1633 var import_block_editor14 = __toESM(require_block_editor());
1634 var import_jsx_runtime28 = __toESM(require_jsx_runtime());
1635 var name12 = "core/unknown";
1636 var title12 = (0, import_i18n15.__)("Clear Unknown Formatting");
1637 function selectionContainsUnknownFormats(value) {
1638 if ((0, import_rich_text14.isCollapsed)(value)) {
1639 return false;
1640 }
1641 const selectedValue = (0, import_rich_text14.slice)(value);
1642 return selectedValue.formats.some((formats) => {
1643 return formats.some((format) => format.type === name12);
1644 });
1645 }
1646 var unknown = {
1647 name: name12,
1648 title: title12,
1649 tagName: "*",
1650 className: null,
1651 edit({ isActive, value, onChange, onFocus }) {
1652 if (!isActive && !selectionContainsUnknownFormats(value)) {
1653 return null;
1654 }
1655 function onClick() {
1656 onChange((0, import_rich_text14.removeFormat)(value, name12));
1657 onFocus();
1658 }
1659 return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
1660 import_block_editor14.RichTextToolbarButton,
1661 {
1662 name: "unknown",
1663 icon: help_default,
1664 title: title12,
1665 onClick,
1666 isActive: true
1667 }
1668 );
1669 }
1670 };
1671
1672 // packages/format-library/build-module/language/index.js
1673 var import_i18n16 = __toESM(require_i18n());
1674 var import_block_editor15 = __toESM(require_block_editor());
1675 var import_components5 = __toESM(require_components());
1676 var import_element8 = __toESM(require_element());
1677 var import_rich_text15 = __toESM(require_rich_text());
1678 var import_jsx_runtime29 = __toESM(require_jsx_runtime());
1679 var name13 = "core/language";
1680 var title13 = (0, import_i18n16.__)("Language");
1681 var language = {
1682 name: name13,
1683 tagName: "bdo",
1684 className: null,
1685 edit: Edit3,
1686 title: title13
1687 };
1688 function Edit3({ isActive, value, onChange, contentRef }) {
1689 const [isPopoverVisible, setIsPopoverVisible] = (0, import_element8.useState)(false);
1690 const togglePopover = () => {
1691 setIsPopoverVisible((state) => !state);
1692 };
1693 return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
1694 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1695 import_block_editor15.RichTextToolbarButton,
1696 {
1697 icon: language_default,
1698 label: title13,
1699 title: title13,
1700 onClick: () => {
1701 if (isActive) {
1702 onChange((0, import_rich_text15.removeFormat)(value, name13));
1703 } else {
1704 togglePopover();
1705 }
1706 },
1707 isActive,
1708 role: "menuitemcheckbox"
1709 }
1710 ),
1711 isPopoverVisible && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1712 InlineLanguageUI,
1713 {
1714 value,
1715 onChange,
1716 onClose: togglePopover,
1717 contentRef
1718 }
1719 )
1720 ] });
1721 }
1722 function InlineLanguageUI({ value, contentRef, onChange, onClose }) {
1723 const popoverAnchor = (0, import_rich_text15.useAnchor)({
1724 editableContentElement: contentRef.current,
1725 settings: language
1726 });
1727 const [lang, setLang] = (0, import_element8.useState)("");
1728 const [dir, setDir] = (0, import_element8.useState)("ltr");
1729 return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1730 import_components5.Popover,
1731 {
1732 className: "block-editor-format-toolbar__language-popover",
1733 anchor: popoverAnchor,
1734 onClose,
1735 children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
1736 import_components5.__experimentalVStack,
1737 {
1738 as: "form",
1739 spacing: 4,
1740 className: "block-editor-format-toolbar__language-container-content",
1741 onSubmit: (event) => {
1742 event.preventDefault();
1743 onChange(
1744 (0, import_rich_text15.applyFormat)(value, {
1745 type: name13,
1746 attributes: {
1747 lang,
1748 dir
1749 }
1750 })
1751 );
1752 onClose();
1753 },
1754 children: [
1755 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1756 import_components5.TextControl,
1757 {
1758 __next40pxDefaultSize: true,
1759 __nextHasNoMarginBottom: true,
1760 label: title13,
1761 value: lang,
1762 onChange: (val) => setLang(val),
1763 help: (0, import_i18n16.__)(
1764 'A valid language attribute, like "en" or "fr".'
1765 )
1766 }
1767 ),
1768 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1769 import_components5.SelectControl,
1770 {
1771 __next40pxDefaultSize: true,
1772 __nextHasNoMarginBottom: true,
1773 label: (0, import_i18n16.__)("Text direction"),
1774 value: dir,
1775 options: [
1776 {
1777 label: (0, import_i18n16.__)("Left to right"),
1778 value: "ltr"
1779 },
1780 {
1781 label: (0, import_i18n16.__)("Right to left"),
1782 value: "rtl"
1783 }
1784 ],
1785 onChange: (val) => setDir(val)
1786 }
1787 ),
1788 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_components5.__experimentalHStack, { alignment: "right", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
1789 import_components5.Button,
1790 {
1791 __next40pxDefaultSize: true,
1792 variant: "primary",
1793 type: "submit",
1794 text: (0, import_i18n16.__)("Apply")
1795 }
1796 ) })
1797 ]
1798 }
1799 )
1800 }
1801 );
1802 }
1803
1804 // packages/format-library/build-module/math/index.js
1805 var import_i18n17 = __toESM(require_i18n());
1806 var import_element9 = __toESM(require_element());
1807 var import_rich_text16 = __toESM(require_rich_text());
1808 var import_block_editor16 = __toESM(require_block_editor());
1809 var import_components6 = __toESM(require_components());
1810 var import_a11y3 = __toESM(require_a11y());
1811 var import_jsx_runtime30 = __toESM(require_jsx_runtime());
1812 var { Badge } = unlock(import_components6.privateApis);
1813 var name14 = "core/math";
1814 var title14 = (0, import_i18n17.__)("Math");
1815 function InlineUI2({
1816 value,
1817 onChange,
1818 activeAttributes,
1819 contentRef,
1820 latexToMathML
1821 }) {
1822 const [latex, setLatex] = (0, import_element9.useState)(
1823 activeAttributes?.["data-latex"] || ""
1824 );
1825 const [error, setError] = (0, import_element9.useState)(null);
1826 const popoverAnchor = (0, import_rich_text16.useAnchor)({
1827 editableContentElement: contentRef.current,
1828 settings: math
1829 });
1830 const handleLatexChange = (newLatex) => {
1831 let mathML = "";
1832 setLatex(newLatex);
1833 if (newLatex) {
1834 try {
1835 mathML = latexToMathML(newLatex, { displayMode: false });
1836 setError(null);
1837 } catch (err) {
1838 setError(err.message);
1839 (0, import_a11y3.speak)(
1840 (0, import_i18n17.sprintf)(
1841 /* translators: %s: error message returned when parsing LaTeX. */
1842 (0, import_i18n17.__)("Error parsing mathematical expression: %s"),
1843 err.message
1844 )
1845 );
1846 return;
1847 }
1848 }
1849 const newReplacements = value.replacements.slice();
1850 newReplacements[value.start] = {
1851 type: name14,
1852 attributes: {
1853 "data-latex": newLatex
1854 },
1855 innerHTML: mathML
1856 };
1857 onChange({
1858 ...value,
1859 replacements: newReplacements
1860 });
1861 };
1862 return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1863 import_components6.Popover,
1864 {
1865 placement: "bottom-start",
1866 offset: 8,
1867 focusOnMount: false,
1868 anchor: popoverAnchor,
1869 className: "block-editor-format-toolbar__math-popover",
1870 children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { style: { minWidth: "300px", padding: "4px" }, children: /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_components6.__experimentalVStack, { spacing: 1, children: [
1871 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1872 import_components6.TextControl,
1873 {
1874 __nextHasNoMarginBottom: true,
1875 __next40pxDefaultSize: true,
1876 hideLabelFromVision: true,
1877 label: (0, import_i18n17.__)("LaTeX math syntax"),
1878 value: latex,
1879 onChange: handleLatexChange,
1880 placeholder: (0, import_i18n17.__)("e.g., x^2, \\frac{a}{b}"),
1881 autoComplete: "off",
1882 className: "block-editor-format-toolbar__math-input"
1883 }
1884 ),
1885 error && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
1886 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1887 Badge,
1888 {
1889 intent: "error",
1890 className: "wp-block-math__error",
1891 children: (0, import_i18n17.sprintf)(
1892 /* translators: %s: error message returned when parsing LaTeX. */
1893 (0, import_i18n17.__)("Error: %s"),
1894 error
1895 )
1896 }
1897 ),
1898 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("style", { children: ".wp-block-math__error .components-badge__content{white-space:normal}" })
1899 ] })
1900 ] }) })
1901 }
1902 );
1903 }
1904 function Edit4({
1905 value,
1906 onChange,
1907 onFocus,
1908 isObjectActive,
1909 activeObjectAttributes,
1910 contentRef
1911 }) {
1912 const [latexToMathML, setLatexToMathML] = (0, import_element9.useState)();
1913 (0, import_element9.useEffect)(() => {
1914 import("@wordpress/latex-to-mathml").then((module) => {
1915 setLatexToMathML(() => module.default);
1916 });
1917 }, []);
1918 return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
1919 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1920 import_block_editor16.RichTextToolbarButton,
1921 {
1922 icon: math_default,
1923 title: title14,
1924 onClick: () => {
1925 const newValue = (0, import_rich_text16.insertObject)(value, {
1926 type: name14,
1927 attributes: {
1928 "data-latex": ""
1929 },
1930 innerHTML: ""
1931 });
1932 newValue.start = newValue.end - 1;
1933 onChange(newValue);
1934 onFocus();
1935 },
1936 isActive: isObjectActive
1937 }
1938 ),
1939 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
1940 InlineUI2,
1941 {
1942 value,
1943 onChange,
1944 activeAttributes: activeObjectAttributes,
1945 contentRef,
1946 latexToMathML
1947 }
1948 )
1949 ] });
1950 }
1951 var math = {
1952 name: name14,
1953 title: title14,
1954 tagName: "math",
1955 className: null,
1956 attributes: {
1957 "data-latex": "data-latex"
1958 },
1959 contentEditable: false,
1960 edit: Edit4
1961 };
1962
1963 // packages/format-library/build-module/non-breaking-space/index.js
1964 var import_i18n18 = __toESM(require_i18n());
1965 var import_rich_text17 = __toESM(require_rich_text());
1966 var import_block_editor17 = __toESM(require_block_editor());
1967 var import_jsx_runtime31 = __toESM(require_jsx_runtime());
1968 var name15 = "core/non-breaking-space";
1969 var title15 = (0, import_i18n18.__)("Non breaking space");
1970 var nonBreakingSpace = {
1971 name: name15,
1972 title: title15,
1973 tagName: "nbsp",
1974 className: null,
1975 edit({ value, onChange }) {
1976 function addNonBreakingSpace() {
1977 onChange((0, import_rich_text17.insert)(value, "\xA0"));
1978 }
1979 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
1980 import_block_editor17.RichTextShortcut,
1981 {
1982 type: "primaryShift",
1983 character: " ",
1984 onUse: addNonBreakingSpace
1985 }
1986 );
1987 }
1988 };
1989
1990 // packages/format-library/build-module/default-formats.js
1991 var default_formats_default = [
1992 bold,
1993 code,
1994 image,
1995 italic,
1996 link,
1997 strikethrough,
1998 underline,
1999 textColor,
2000 subscript,
2001 superscript,
2002 keyboard,
2003 unknown,
2004 language,
2005 math,
2006 nonBreakingSpace
2007 ];
2008
2009 // packages/format-library/build-module/index.js
2010 default_formats_default.forEach(
2011 ({ name: name16, ...settings }) => (0, import_rich_text18.registerFormatType)(name16, settings)
2012 );
2013 })();
2014 //# sourceMappingURL=index.js.map
2015