PluginProbe
Gutenberg / 23.3.0
Gutenberg v23.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 23.3.0, at build/scripts/format-library/index.js

2,603 lines 91.7 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/components
78 var require_components = __commonJS({
79 "package-external:@wordpress/components"(exports, module) {
80 module.exports = window.wp.components;
81 }
82 });
83
84 // package-external:@wordpress/url
85 var require_url = __commonJS({
86 "package-external:@wordpress/url"(exports, module) {
87 module.exports = window.wp.url;
88 }
89 });
90
91 // package-external:@wordpress/html-entities
92 var require_html_entities = __commonJS({
93 "package-external:@wordpress/html-entities"(exports, module) {
94 module.exports = window.wp.htmlEntities;
95 }
96 });
97
98 // package-external:@wordpress/a11y
99 var require_a11y = __commonJS({
100 "package-external:@wordpress/a11y"(exports, module) {
101 module.exports = window.wp.a11y;
102 }
103 });
104
105 // package-external:@wordpress/data
106 var require_data = __commonJS({
107 "package-external:@wordpress/data"(exports, module) {
108 module.exports = window.wp.data;
109 }
110 });
111
112 // package-external:@wordpress/compose
113 var require_compose = __commonJS({
114 "package-external:@wordpress/compose"(exports, module) {
115 module.exports = window.wp.compose;
116 }
117 });
118
119 // vendor-external:react
120 var require_react = __commonJS({
121 "vendor-external:react"(exports, module) {
122 module.exports = window.React;
123 }
124 });
125
126 // package-external:@wordpress/private-apis
127 var require_private_apis = __commonJS({
128 "package-external:@wordpress/private-apis"(exports, module) {
129 module.exports = window.wp.privateApis;
130 }
131 });
132
133 // packages/format-library/build-module/index.mjs
134 var import_rich_text18 = __toESM(require_rich_text(), 1);
135
136 // packages/format-library/build-module/bold/index.mjs
137 var import_i18n = __toESM(require_i18n(), 1);
138 var import_rich_text = __toESM(require_rich_text(), 1);
139 var import_block_editor = __toESM(require_block_editor(), 1);
140
141 // packages/icons/build-module/icon/index.mjs
142 var import_element = __toESM(require_element(), 1);
143 var icon_default = (0, import_element.forwardRef)(
144 ({ icon, size = 24, ...props }, ref) => {
145 return (0, import_element.cloneElement)(
146 icon,
147 {
148 width: size,
149 height: size,
150 ...props,
151 ref
152 }
153 );
154 }
155 );
156
157 // packages/icons/build-module/library/button.mjs
158 var import_primitives = __toESM(require_primitives(), 1);
159 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1);
160 var button_default = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", 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" }) });
161
162 // packages/icons/build-module/library/code.mjs
163 var import_primitives2 = __toESM(require_primitives(), 1);
164 var import_jsx_runtime2 = __toESM(require_jsx_runtime(), 1);
165 var code_default = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_primitives2.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", 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" }) });
166
167 // packages/icons/build-module/library/color.mjs
168 var import_primitives3 = __toESM(require_primitives(), 1);
169 var import_jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
170 var color_default = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_primitives3.SVG, { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", 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" }) });
171
172 // packages/icons/build-module/library/format-bold.mjs
173 var import_primitives4 = __toESM(require_primitives(), 1);
174 var import_jsx_runtime4 = __toESM(require_jsx_runtime(), 1);
175 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" }) });
176
177 // packages/icons/build-module/library/format-italic.mjs
178 var import_primitives5 = __toESM(require_primitives(), 1);
179 var import_jsx_runtime5 = __toESM(require_jsx_runtime(), 1);
180 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" }) });
181
182 // packages/icons/build-module/library/format-strikethrough.mjs
183 var import_primitives6 = __toESM(require_primitives(), 1);
184 var import_jsx_runtime6 = __toESM(require_jsx_runtime(), 1);
185 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" }) });
186
187 // packages/icons/build-module/library/help.mjs
188 var import_primitives7 = __toESM(require_primitives(), 1);
189 var import_jsx_runtime7 = __toESM(require_jsx_runtime(), 1);
190 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" }) });
191
192 // packages/icons/build-module/library/language.mjs
193 var import_primitives8 = __toESM(require_primitives(), 1);
194 var import_jsx_runtime8 = __toESM(require_jsx_runtime(), 1);
195 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" }) });
196
197 // packages/icons/build-module/library/link.mjs
198 var import_primitives9 = __toESM(require_primitives(), 1);
199 var import_jsx_runtime9 = __toESM(require_jsx_runtime(), 1);
200 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" }) });
201
202 // packages/icons/build-module/library/math.mjs
203 var import_primitives10 = __toESM(require_primitives(), 1);
204 var import_jsx_runtime10 = __toESM(require_jsx_runtime(), 1);
205 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" }) });
206
207 // packages/icons/build-module/library/subscript.mjs
208 var import_primitives11 = __toESM(require_primitives(), 1);
209 var import_jsx_runtime11 = __toESM(require_jsx_runtime(), 1);
210 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" }) });
211
212 // packages/icons/build-module/library/superscript.mjs
213 var import_primitives12 = __toESM(require_primitives(), 1);
214 var import_jsx_runtime12 = __toESM(require_jsx_runtime(), 1);
215 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" }) });
216
217 // packages/icons/build-module/library/text-color.mjs
218 var import_primitives13 = __toESM(require_primitives(), 1);
219 var import_jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
220 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" }) });
221
222 // packages/format-library/build-module/bold/index.mjs
223 var import_jsx_runtime14 = __toESM(require_jsx_runtime(), 1);
224 var name = "core/bold";
225 var title = (0, import_i18n.__)("Bold");
226 var bold = {
227 name,
228 title,
229 tagName: "strong",
230 className: null,
231 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
232 function onToggle() {
233 onChange((0, import_rich_text.toggleFormat)(value, { type: name, title }));
234 }
235 function onClick() {
236 onChange((0, import_rich_text.toggleFormat)(value, { type: name }));
237 onFocus();
238 }
239 return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
240 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
241 import_block_editor.RichTextShortcut,
242 {
243 type: "primary",
244 character: "b",
245 onUse: onToggle
246 }
247 ),
248 isVisible && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
249 import_block_editor.RichTextToolbarButton,
250 {
251 name: "bold",
252 icon: format_bold_default,
253 title,
254 onClick,
255 isActive,
256 shortcutType: "primary",
257 shortcutCharacter: "b"
258 }
259 ),
260 /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
261 import_block_editor.__unstableRichTextInputEvent,
262 {
263 inputType: "formatBold",
264 onInput: onToggle
265 }
266 )
267 ] });
268 }
269 };
270
271 // packages/format-library/build-module/code/index.mjs
272 var import_i18n2 = __toESM(require_i18n(), 1);
273 var import_rich_text2 = __toESM(require_rich_text(), 1);
274 var import_block_editor2 = __toESM(require_block_editor(), 1);
275 var import_jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
276 var name2 = "core/code";
277 var title2 = (0, import_i18n2.__)("Inline code");
278 var code = {
279 name: name2,
280 title: title2,
281 tagName: "code",
282 className: null,
283 __unstableInputRule(value) {
284 const BACKTICK = "`";
285 const { start, text } = value;
286 const characterBefore = text[start - 1];
287 if (characterBefore !== BACKTICK) {
288 return value;
289 }
290 if (start - 2 < 0) {
291 return value;
292 }
293 const indexBefore = text.lastIndexOf(BACKTICK, start - 2);
294 if (indexBefore === -1) {
295 return value;
296 }
297 const startIndex = indexBefore;
298 const endIndex = start - 2;
299 if (startIndex === endIndex) {
300 return value;
301 }
302 value = (0, import_rich_text2.remove)(value, startIndex, startIndex + 1);
303 value = (0, import_rich_text2.remove)(value, endIndex, endIndex + 1);
304 value = (0, import_rich_text2.applyFormat)(value, { type: name2 }, startIndex, endIndex);
305 return value;
306 },
307 edit({ value, onChange, onFocus, isActive }) {
308 function onClick() {
309 onChange((0, import_rich_text2.toggleFormat)(value, { type: name2, title: title2 }));
310 onFocus();
311 }
312 return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
313 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
314 import_block_editor2.RichTextShortcut,
315 {
316 type: "access",
317 character: "x",
318 onUse: onClick
319 }
320 ),
321 /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
322 import_block_editor2.RichTextToolbarButton,
323 {
324 icon: code_default,
325 title: title2,
326 onClick,
327 isActive,
328 role: "menuitemcheckbox"
329 }
330 )
331 ] });
332 }
333 };
334
335 // packages/format-library/build-module/image/index.mjs
336 var import_components = __toESM(require_components(), 1);
337 var import_i18n3 = __toESM(require_i18n(), 1);
338 var import_element2 = __toESM(require_element(), 1);
339 var import_rich_text3 = __toESM(require_rich_text(), 1);
340 var import_block_editor3 = __toESM(require_block_editor(), 1);
341 var import_jsx_runtime16 = __toESM(require_jsx_runtime(), 1);
342 var ALLOWED_MEDIA_TYPES = ["image"];
343 var name3 = "core/image";
344 var title3 = (0, import_i18n3.__)("Inline image");
345 function getCurrentImageId(activeObjectAttributes) {
346 if (!activeObjectAttributes?.className) {
347 return void 0;
348 }
349 const [, id] = activeObjectAttributes.className.match(/wp-image-(\d+)/) ?? [];
350 return id ? parseInt(id, 10) : void 0;
351 }
352 var image = {
353 name: name3,
354 title: title3,
355 keywords: [(0, import_i18n3.__)("photo"), (0, import_i18n3.__)("media")],
356 object: true,
357 tagName: "img",
358 className: null,
359 attributes: {
360 className: "class",
361 style: "style",
362 url: "src",
363 alt: "alt"
364 },
365 edit: Edit
366 };
367 function InlineUI({ value, onChange, activeObjectAttributes, contentRef }) {
368 const { style, alt } = activeObjectAttributes;
369 const width = style?.replace(/\D/g, "");
370 const [editedWidth, setEditedWidth] = (0, import_element2.useState)(width);
371 const [editedAlt, setEditedAlt] = (0, import_element2.useState)(alt);
372 const hasChanged = editedWidth !== width || editedAlt !== alt;
373 const popoverAnchor = (0, import_rich_text3.useAnchor)({
374 editableContentElement: contentRef.current,
375 settings: image
376 });
377 return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
378 import_components.Popover,
379 {
380 focusOnMount: false,
381 anchor: popoverAnchor,
382 className: "block-editor-format-toolbar__image-popover",
383 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
384 "form",
385 {
386 className: "block-editor-format-toolbar__image-container-content",
387 onSubmit: (event) => {
388 const newReplacements = value.replacements.slice();
389 newReplacements[value.start] = {
390 type: name3,
391 attributes: {
392 ...activeObjectAttributes,
393 style: editedWidth ? `width: ${editedWidth}px;` : "",
394 alt: editedAlt
395 }
396 };
397 onChange({
398 ...value,
399 replacements: newReplacements
400 });
401 event.preventDefault();
402 },
403 children: /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(import_components.__experimentalVStack, { spacing: 4, children: [
404 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
405 import_components.__experimentalNumberControl,
406 {
407 __next40pxDefaultSize: true,
408 label: (0, import_i18n3.__)("Width"),
409 value: editedWidth,
410 min: 1,
411 onChange: (newWidth) => {
412 setEditedWidth(newWidth);
413 }
414 }
415 ),
416 /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
417 import_components.TextareaControl,
418 {
419 label: (0, import_i18n3.__)("Alternative text"),
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.mjs
523 var import_i18n4 = __toESM(require_i18n(), 1);
524 var import_rich_text4 = __toESM(require_rich_text(), 1);
525 var import_block_editor4 = __toESM(require_block_editor(), 1);
526 var import_jsx_runtime17 = __toESM(require_jsx_runtime(), 1);
527 var name4 = "core/italic";
528 var title4 = (0, import_i18n4.__)("Italic");
529 var italic = {
530 name: name4,
531 title: title4,
532 tagName: "em",
533 className: null,
534 edit({ isActive, value, onChange, onFocus, isVisible = true }) {
535 function onToggle() {
536 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4, title: title4 }));
537 }
538 function onClick() {
539 onChange((0, import_rich_text4.toggleFormat)(value, { type: name4 }));
540 onFocus();
541 }
542 return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
543 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
544 import_block_editor4.RichTextShortcut,
545 {
546 type: "primary",
547 character: "i",
548 onUse: onToggle
549 }
550 ),
551 isVisible && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
552 import_block_editor4.RichTextToolbarButton,
553 {
554 name: "italic",
555 icon: format_italic_default,
556 title: title4,
557 onClick,
558 isActive,
559 shortcutType: "primary",
560 shortcutCharacter: "i"
561 }
562 ),
563 /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
564 import_block_editor4.__unstableRichTextInputEvent,
565 {
566 inputType: "formatItalic",
567 onInput: onToggle
568 }
569 )
570 ] });
571 }
572 };
573
574 // packages/format-library/build-module/link/index.mjs
575 var import_i18n7 = __toESM(require_i18n(), 1);
576 var import_element6 = __toESM(require_element(), 1);
577 var import_rich_text6 = __toESM(require_rich_text(), 1);
578 var import_url3 = __toESM(require_url(), 1);
579 var import_block_editor6 = __toESM(require_block_editor(), 1);
580 var import_html_entities = __toESM(require_html_entities(), 1);
581 var import_a11y2 = __toESM(require_a11y(), 1);
582
583 // packages/format-library/build-module/link/inline.mjs
584 var import_element5 = __toESM(require_element(), 1);
585 var import_i18n6 = __toESM(require_i18n(), 1);
586 var import_a11y = __toESM(require_a11y(), 1);
587 var import_components3 = __toESM(require_components(), 1);
588 var import_url2 = __toESM(require_url(), 1);
589 var import_rich_text5 = __toESM(require_rich_text(), 1);
590 var import_block_editor5 = __toESM(require_block_editor(), 1);
591 var import_data = __toESM(require_data(), 1);
592
593 // packages/format-library/build-module/link/utils.mjs
594 var import_url = __toESM(require_url(), 1);
595 function isValidHref(href) {
596 if (!href) {
597 return false;
598 }
599 const trimmedHref = href.trim();
600 if (!trimmedHref) {
601 return false;
602 }
603 if (/^\S+:/.test(trimmedHref)) {
604 const protocol = (0, import_url.getProtocol)(trimmedHref);
605 if (!(0, import_url.isValidProtocol)(protocol)) {
606 return false;
607 }
608 if (protocol.startsWith("http") && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) {
609 return false;
610 }
611 const authority = (0, import_url.getAuthority)(trimmedHref);
612 if (!(0, import_url.isValidAuthority)(authority)) {
613 return false;
614 }
615 const path = (0, import_url.getPath)(trimmedHref);
616 if (path && !(0, import_url.isValidPath)(path)) {
617 return false;
618 }
619 const queryString = (0, import_url.getQueryString)(trimmedHref);
620 if (queryString && !(0, import_url.isValidQueryString)(queryString)) {
621 return false;
622 }
623 const fragment = (0, import_url.getFragment)(trimmedHref);
624 if (fragment && !(0, import_url.isValidFragment)(fragment)) {
625 return false;
626 }
627 }
628 if (trimmedHref.startsWith("#") && !(0, import_url.isValidFragment)(trimmedHref)) {
629 return false;
630 }
631 return true;
632 }
633 function createLinkFormat({
634 url,
635 type,
636 id,
637 opensInNewWindow,
638 nofollow,
639 cssClasses
640 }) {
641 const format = {
642 type: "core/link",
643 attributes: {
644 url
645 }
646 };
647 if (type) {
648 format.attributes.type = type;
649 }
650 if (id) {
651 format.attributes.id = id;
652 }
653 if (opensInNewWindow) {
654 format.attributes.target = "_blank";
655 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " noopener" : "noopener";
656 }
657 if (nofollow) {
658 format.attributes.rel = format.attributes.rel ? format.attributes.rel + " nofollow" : "nofollow";
659 }
660 const trimmedCssClasses = cssClasses?.trim();
661 if (trimmedCssClasses?.length) {
662 format.attributes.class = trimmedCssClasses;
663 }
664 return format;
665 }
666 function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
667 const EMPTY_BOUNDARIES = {
668 start: void 0,
669 end: void 0
670 };
671 const { formats } = value;
672 let targetFormat;
673 let initialIndex;
674 if (!formats?.length) {
675 return EMPTY_BOUNDARIES;
676 }
677 const newFormats = formats.slice();
678 const formatAtStart = newFormats[startIndex]?.find(
679 ({ type }) => type === format.type
680 );
681 const formatAtEnd = newFormats[endIndex]?.find(
682 ({ type }) => type === format.type
683 );
684 const formatAtEndMinusOne = newFormats[endIndex - 1]?.find(
685 ({ type }) => type === format.type
686 );
687 if (!!formatAtStart) {
688 targetFormat = formatAtStart;
689 initialIndex = startIndex;
690 } else if (!!formatAtEnd) {
691 targetFormat = formatAtEnd;
692 initialIndex = endIndex;
693 } else if (!!formatAtEndMinusOne) {
694 targetFormat = formatAtEndMinusOne;
695 initialIndex = endIndex - 1;
696 } else {
697 return EMPTY_BOUNDARIES;
698 }
699 const index = newFormats[initialIndex].indexOf(targetFormat);
700 const walkingArgs = [newFormats, initialIndex, targetFormat, index];
701 startIndex = walkToStart(...walkingArgs);
702 endIndex = walkToEnd(...walkingArgs);
703 startIndex = startIndex < 0 ? 0 : startIndex;
704 return {
705 start: startIndex,
706 end: endIndex + 1
707 };
708 }
709 function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
710 let index = initialIndex;
711 const directions = {
712 forwards: 1,
713 backwards: -1
714 };
715 const directionIncrement = directions[direction] || 1;
716 const inverseDirectionIncrement = directionIncrement * -1;
717 while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
718 index = index + directionIncrement;
719 }
720 index = index + inverseDirectionIncrement;
721 return index;
722 }
723 var partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
724 var walkToStart = partialRight(walkToBoundary, "backwards");
725 var walkToEnd = partialRight(walkToBoundary, "forwards");
726
727 // packages/format-library/build-module/link/css-classes-setting.mjs
728 var import_element4 = __toESM(require_element(), 1);
729 var import_compose = __toESM(require_compose(), 1);
730 var import_i18n5 = __toESM(require_i18n(), 1);
731 var import_components2 = __toESM(require_components(), 1);
732
733 // node_modules/@base-ui/utils/esm/useRefWithInit.js
734 var React = __toESM(require_react(), 1);
735 var UNINITIALIZED = {};
736 function useRefWithInit(init, initArg) {
737 const ref = React.useRef(UNINITIALIZED);
738 if (ref.current === UNINITIALIZED) {
739 ref.current = init(initArg);
740 }
741 return ref;
742 }
743
744 // node_modules/@base-ui/utils/esm/warn.js
745 var set;
746 if (true) {
747 set = /* @__PURE__ */ new Set();
748 }
749 function warn(...messages) {
750 if (true) {
751 const messageKey = messages.join(" ");
752 if (!set.has(messageKey)) {
753 set.add(messageKey);
754 console.warn(`Base UI: ${messageKey}`);
755 }
756 }
757 }
758
759 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
760 var React4 = __toESM(require_react(), 1);
761
762 // node_modules/@base-ui/utils/esm/useMergedRefs.js
763 function useMergedRefs(a, b, c, d) {
764 const forkRef = useRefWithInit(createForkRef).current;
765 if (didChange(forkRef, a, b, c, d)) {
766 update(forkRef, [a, b, c, d]);
767 }
768 return forkRef.callback;
769 }
770 function useMergedRefsN(refs) {
771 const forkRef = useRefWithInit(createForkRef).current;
772 if (didChangeN(forkRef, refs)) {
773 update(forkRef, refs);
774 }
775 return forkRef.callback;
776 }
777 function createForkRef() {
778 return {
779 callback: null,
780 cleanup: null,
781 refs: []
782 };
783 }
784 function didChange(forkRef, a, b, c, d) {
785 return forkRef.refs[0] !== a || forkRef.refs[1] !== b || forkRef.refs[2] !== c || forkRef.refs[3] !== d;
786 }
787 function didChangeN(forkRef, newRefs) {
788 return forkRef.refs.length !== newRefs.length || forkRef.refs.some((ref, index) => ref !== newRefs[index]);
789 }
790 function update(forkRef, refs) {
791 forkRef.refs = refs;
792 if (refs.every((ref) => ref == null)) {
793 forkRef.callback = null;
794 return;
795 }
796 forkRef.callback = (instance) => {
797 if (forkRef.cleanup) {
798 forkRef.cleanup();
799 forkRef.cleanup = null;
800 }
801 if (instance != null) {
802 const cleanupCallbacks = Array(refs.length).fill(null);
803 for (let i = 0; i < refs.length; i += 1) {
804 const ref = refs[i];
805 if (ref == null) {
806 continue;
807 }
808 switch (typeof ref) {
809 case "function": {
810 const refCleanup = ref(instance);
811 if (typeof refCleanup === "function") {
812 cleanupCallbacks[i] = refCleanup;
813 }
814 break;
815 }
816 case "object": {
817 ref.current = instance;
818 break;
819 }
820 default:
821 }
822 }
823 forkRef.cleanup = () => {
824 for (let i = 0; i < refs.length; i += 1) {
825 const ref = refs[i];
826 if (ref == null) {
827 continue;
828 }
829 switch (typeof ref) {
830 case "function": {
831 const cleanupCallback = cleanupCallbacks[i];
832 if (typeof cleanupCallback === "function") {
833 cleanupCallback();
834 } else {
835 ref(null);
836 }
837 break;
838 }
839 case "object": {
840 ref.current = null;
841 break;
842 }
843 default:
844 }
845 }
846 };
847 }
848 };
849 }
850
851 // node_modules/@base-ui/utils/esm/getReactElementRef.js
852 var React3 = __toESM(require_react(), 1);
853
854 // node_modules/@base-ui/utils/esm/reactVersion.js
855 var React2 = __toESM(require_react(), 1);
856 var majorVersion = parseInt(React2.version, 10);
857 function isReactVersionAtLeast(reactVersionToCheck) {
858 return majorVersion >= reactVersionToCheck;
859 }
860
861 // node_modules/@base-ui/utils/esm/getReactElementRef.js
862 function getReactElementRef(element) {
863 if (!/* @__PURE__ */ React3.isValidElement(element)) {
864 return null;
865 }
866 const reactElement = element;
867 const propsWithRef = reactElement.props;
868 return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
869 }
870
871 // node_modules/@base-ui/utils/esm/mergeObjects.js
872 function mergeObjects(a, b) {
873 if (a && !b) {
874 return a;
875 }
876 if (!a && b) {
877 return b;
878 }
879 if (a || b) {
880 return {
881 ...a,
882 ...b
883 };
884 }
885 return void 0;
886 }
887
888 // node_modules/@base-ui/utils/esm/empty.js
889 var EMPTY_ARRAY = Object.freeze([]);
890 var EMPTY_OBJECT = Object.freeze({});
891
892 // node_modules/@base-ui/react/esm/internals/getStateAttributesProps.js
893 function getStateAttributesProps(state, customMapping) {
894 const props = {};
895 for (const key in state) {
896 const value = state[key];
897 if (customMapping?.hasOwnProperty(key)) {
898 const customProps = customMapping[key](value);
899 if (customProps != null) {
900 Object.assign(props, customProps);
901 }
902 continue;
903 }
904 if (value === true) {
905 props[`data-${key.toLowerCase()}`] = "";
906 } else if (value) {
907 props[`data-${key.toLowerCase()}`] = value.toString();
908 }
909 }
910 return props;
911 }
912
913 // node_modules/@base-ui/react/esm/utils/resolveClassName.js
914 function resolveClassName(className, state) {
915 return typeof className === "function" ? className(state) : className;
916 }
917
918 // node_modules/@base-ui/react/esm/utils/resolveStyle.js
919 function resolveStyle(style, state) {
920 return typeof style === "function" ? style(state) : style;
921 }
922
923 // node_modules/@base-ui/react/esm/merge-props/mergeProps.js
924 var EMPTY_PROPS = {};
925 function mergeProps(a, b, c, d, e) {
926 if (!c && !d && !e && !a) {
927 return createInitialMergedProps(b);
928 }
929 let merged = createInitialMergedProps(a);
930 if (b) {
931 merged = mergeInto(merged, b);
932 }
933 if (c) {
934 merged = mergeInto(merged, c);
935 }
936 if (d) {
937 merged = mergeInto(merged, d);
938 }
939 if (e) {
940 merged = mergeInto(merged, e);
941 }
942 return merged;
943 }
944 function mergePropsN(props) {
945 if (props.length === 0) {
946 return EMPTY_PROPS;
947 }
948 if (props.length === 1) {
949 return createInitialMergedProps(props[0]);
950 }
951 let merged = createInitialMergedProps(props[0]);
952 for (let i = 1; i < props.length; i += 1) {
953 merged = mergeInto(merged, props[i]);
954 }
955 return merged;
956 }
957 function createInitialMergedProps(inputProps) {
958 if (isPropsGetter(inputProps)) {
959 return {
960 ...resolvePropsGetter(inputProps, EMPTY_PROPS)
961 };
962 }
963 return copyInitialProps(inputProps);
964 }
965 function mergeInto(merged, inputProps) {
966 if (isPropsGetter(inputProps)) {
967 return resolvePropsGetter(inputProps, merged);
968 }
969 return mutablyMergeInto(merged, inputProps);
970 }
971 function copyInitialProps(inputProps) {
972 const copiedProps = {
973 ...inputProps
974 };
975 for (const propName in copiedProps) {
976 const propValue = copiedProps[propName];
977 if (isEventHandler(propName, propValue)) {
978 copiedProps[propName] = wrapEventHandler(propValue);
979 }
980 }
981 return copiedProps;
982 }
983 function mutablyMergeInto(mergedProps, externalProps) {
984 if (!externalProps) {
985 return mergedProps;
986 }
987 for (const propName in externalProps) {
988 const externalPropValue = externalProps[propName];
989 switch (propName) {
990 case "style": {
991 mergedProps[propName] = mergeObjects(mergedProps.style, externalPropValue);
992 break;
993 }
994 case "className": {
995 mergedProps[propName] = mergeClassNames(mergedProps.className, externalPropValue);
996 break;
997 }
998 default: {
999 if (isEventHandler(propName, externalPropValue)) {
1000 mergedProps[propName] = mergeEventHandlers(mergedProps[propName], externalPropValue);
1001 } else {
1002 mergedProps[propName] = externalPropValue;
1003 }
1004 }
1005 }
1006 }
1007 return mergedProps;
1008 }
1009 function isEventHandler(key, value) {
1010 const code0 = key.charCodeAt(0);
1011 const code1 = key.charCodeAt(1);
1012 const code2 = key.charCodeAt(2);
1013 return code0 === 111 && code1 === 110 && code2 >= 65 && code2 <= 90 && (typeof value === "function" || typeof value === "undefined");
1014 }
1015 function isPropsGetter(inputProps) {
1016 return typeof inputProps === "function";
1017 }
1018 function resolvePropsGetter(inputProps, previousProps) {
1019 if (isPropsGetter(inputProps)) {
1020 return inputProps(previousProps);
1021 }
1022 return inputProps ?? EMPTY_PROPS;
1023 }
1024 function mergeEventHandlers(ourHandler, theirHandler) {
1025 if (!theirHandler) {
1026 return ourHandler;
1027 }
1028 if (!ourHandler) {
1029 return wrapEventHandler(theirHandler);
1030 }
1031 return (...args) => {
1032 const event = args[0];
1033 if (isSyntheticEvent(event)) {
1034 const baseUIEvent = event;
1035 makeEventPreventable(baseUIEvent);
1036 const result2 = theirHandler(...args);
1037 if (!baseUIEvent.baseUIHandlerPrevented) {
1038 ourHandler?.(...args);
1039 }
1040 return result2;
1041 }
1042 const result = theirHandler(...args);
1043 ourHandler?.(...args);
1044 return result;
1045 };
1046 }
1047 function wrapEventHandler(handler) {
1048 if (!handler) {
1049 return handler;
1050 }
1051 return (...args) => {
1052 const event = args[0];
1053 if (isSyntheticEvent(event)) {
1054 makeEventPreventable(event);
1055 }
1056 return handler(...args);
1057 };
1058 }
1059 function makeEventPreventable(event) {
1060 event.preventBaseUIHandler = () => {
1061 event.baseUIHandlerPrevented = true;
1062 };
1063 return event;
1064 }
1065 function mergeClassNames(ourClassName, theirClassName) {
1066 if (theirClassName) {
1067 if (ourClassName) {
1068 return theirClassName + " " + ourClassName;
1069 }
1070 return theirClassName;
1071 }
1072 return ourClassName;
1073 }
1074 function isSyntheticEvent(event) {
1075 return event != null && typeof event === "object" && "nativeEvent" in event;
1076 }
1077
1078 // node_modules/@base-ui/react/esm/internals/useRenderElement.js
1079 var import_react = __toESM(require_react(), 1);
1080 function useRenderElement(element, componentProps, params = {}) {
1081 const renderProp = componentProps.render;
1082 const outProps = useRenderElementProps(componentProps, params);
1083 if (params.enabled === false) {
1084 return null;
1085 }
1086 const state = params.state ?? EMPTY_OBJECT;
1087 return evaluateRenderProp(element, renderProp, outProps, state);
1088 }
1089 function useRenderElementProps(componentProps, params = {}) {
1090 const {
1091 className: classNameProp,
1092 style: styleProp,
1093 render: renderProp
1094 } = componentProps;
1095 const {
1096 state = EMPTY_OBJECT,
1097 ref,
1098 props,
1099 stateAttributesMapping,
1100 enabled = true
1101 } = params;
1102 const className = enabled ? resolveClassName(classNameProp, state) : void 0;
1103 const style = enabled ? resolveStyle(styleProp, state) : void 0;
1104 const stateProps = enabled ? getStateAttributesProps(state, stateAttributesMapping) : EMPTY_OBJECT;
1105 const resolvedProps = enabled && props ? resolveRenderFunctionProps(props) : void 0;
1106 const outProps = enabled ? mergeObjects(stateProps, resolvedProps) ?? {} : EMPTY_OBJECT;
1107 if (typeof document !== "undefined") {
1108 if (!enabled) {
1109 useMergedRefs(null, null);
1110 } else if (Array.isArray(ref)) {
1111 outProps.ref = useMergedRefsN([outProps.ref, getReactElementRef(renderProp), ...ref]);
1112 } else {
1113 outProps.ref = useMergedRefs(outProps.ref, getReactElementRef(renderProp), ref);
1114 }
1115 }
1116 if (!enabled) {
1117 return EMPTY_OBJECT;
1118 }
1119 if (className !== void 0) {
1120 outProps.className = mergeClassNames(outProps.className, className);
1121 }
1122 if (style !== void 0) {
1123 outProps.style = mergeObjects(outProps.style, style);
1124 }
1125 return outProps;
1126 }
1127 function resolveRenderFunctionProps(props) {
1128 if (Array.isArray(props)) {
1129 return mergePropsN(props);
1130 }
1131 return mergeProps(void 0, props);
1132 }
1133 var REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy");
1134 var COMPONENT_IDENTIFIER_PATTERN = /^[A-Z][A-Za-z0-9$]*$/;
1135 var LOWERCASE_CHARACTER_PATTERN = /[a-z]/;
1136 function evaluateRenderProp(element, render, props, state) {
1137 if (render) {
1138 if (typeof render === "function") {
1139 if (true) {
1140 warnIfRenderPropLooksLikeComponent(render);
1141 }
1142 return render(props, state);
1143 }
1144 const mergedProps = mergeProps(props, render.props);
1145 mergedProps.ref = props.ref;
1146 let newElement = render;
1147 if (newElement?.$$typeof === REACT_LAZY_TYPE) {
1148 const children = React4.Children.toArray(render);
1149 newElement = children[0];
1150 }
1151 if (true) {
1152 if (!/* @__PURE__ */ React4.isValidElement(newElement)) {
1153 throw new Error(["Base UI: The `render` prop was provided an invalid React element as `React.isValidElement(render)` is `false`.", "A valid React element must be provided to the `render` prop because it is cloned with props to replace the default element.", "https://base-ui.com/r/invalid-render-prop"].join("\n"));
1154 }
1155 }
1156 return /* @__PURE__ */ React4.cloneElement(newElement, mergedProps);
1157 }
1158 if (element) {
1159 if (typeof element === "string") {
1160 return renderTag(element, props);
1161 }
1162 }
1163 throw new Error(true ? "Base UI: Render element or function are not defined." : formatErrorMessage_default(8));
1164 }
1165 function warnIfRenderPropLooksLikeComponent(renderFn) {
1166 const functionName = renderFn.name;
1167 if (functionName.length === 0) {
1168 return;
1169 }
1170 if (!COMPONENT_IDENTIFIER_PATTERN.test(functionName)) {
1171 return;
1172 }
1173 if (!LOWERCASE_CHARACTER_PATTERN.test(functionName)) {
1174 return;
1175 }
1176 warn(`The \`render\` prop received a function named \`${functionName}\` that starts with an uppercase letter.`, "This usually means a React component was passed directly as `render={Component}`.", "Base UI calls `render` as a plain function, which can break the Rules of Hooks during reconciliation.", "If this is an intentional render callback, rename it to start with a lowercase letter.", "Use `render={<Component />}` or `render={(props) => <Component {...props} />}` instead.", "https://base-ui.com/r/invalid-render-prop");
1177 }
1178 function renderTag(Tag, props) {
1179 if (Tag === "button") {
1180 return /* @__PURE__ */ (0, import_react.createElement)("button", {
1181 type: "button",
1182 ...props,
1183 key: props.key
1184 });
1185 }
1186 if (Tag === "img") {
1187 return /* @__PURE__ */ (0, import_react.createElement)("img", {
1188 alt: "",
1189 ...props,
1190 key: props.key
1191 });
1192 }
1193 return /* @__PURE__ */ React4.createElement(Tag, props);
1194 }
1195
1196 // node_modules/@base-ui/react/esm/use-render/useRender.js
1197 function useRender(params) {
1198 return useRenderElement(params.defaultTagName ?? "div", params, params);
1199 }
1200
1201 // packages/ui/build-module/visually-hidden/visually-hidden.mjs
1202 var import_element3 = __toESM(require_element(), 1);
1203 var STYLE_HASH_ATTRIBUTE = "data-wp-hash";
1204 function getRuntime() {
1205 const globalScope = globalThis;
1206 if (globalScope.__wpStyleRuntime) {
1207 return globalScope.__wpStyleRuntime;
1208 }
1209 globalScope.__wpStyleRuntime = {
1210 documents: /* @__PURE__ */ new Map(),
1211 styles: /* @__PURE__ */ new Map(),
1212 injectedStyles: /* @__PURE__ */ new WeakMap()
1213 };
1214 if (typeof document !== "undefined") {
1215 registerDocument(document);
1216 }
1217 return globalScope.__wpStyleRuntime;
1218 }
1219 function documentContainsStyleHash(targetDocument, hash) {
1220 if (!targetDocument.head) {
1221 return false;
1222 }
1223 for (const style of targetDocument.head.querySelectorAll(
1224 `style[${STYLE_HASH_ATTRIBUTE}]`
1225 )) {
1226 if (style.getAttribute(STYLE_HASH_ATTRIBUTE) === hash) {
1227 return true;
1228 }
1229 }
1230 return false;
1231 }
1232 function injectStyle(targetDocument, hash, css) {
1233 if (!targetDocument.head) {
1234 return;
1235 }
1236 const runtime = getRuntime();
1237 let injectedStyles = runtime.injectedStyles.get(targetDocument);
1238 if (!injectedStyles) {
1239 injectedStyles = /* @__PURE__ */ new Set();
1240 runtime.injectedStyles.set(targetDocument, injectedStyles);
1241 }
1242 if (injectedStyles.has(hash)) {
1243 return;
1244 }
1245 if (documentContainsStyleHash(targetDocument, hash)) {
1246 injectedStyles.add(hash);
1247 return;
1248 }
1249 const style = targetDocument.createElement("style");
1250 style.setAttribute(STYLE_HASH_ATTRIBUTE, hash);
1251 style.appendChild(targetDocument.createTextNode(css));
1252 targetDocument.head.appendChild(style);
1253 injectedStyles.add(hash);
1254 }
1255 function registerDocument(targetDocument) {
1256 const runtime = getRuntime();
1257 runtime.documents.set(
1258 targetDocument,
1259 (runtime.documents.get(targetDocument) ?? 0) + 1
1260 );
1261 for (const [hash, css] of runtime.styles) {
1262 injectStyle(targetDocument, hash, css);
1263 }
1264 return () => {
1265 const count = runtime.documents.get(targetDocument);
1266 if (count === void 0) {
1267 return;
1268 }
1269 if (count <= 1) {
1270 runtime.documents.delete(targetDocument);
1271 return;
1272 }
1273 runtime.documents.set(targetDocument, count - 1);
1274 };
1275 }
1276 function registerStyle(hash, css) {
1277 const runtime = getRuntime();
1278 runtime.styles.set(hash, css);
1279 for (const targetDocument of runtime.documents.keys()) {
1280 injectStyle(targetDocument, hash, css);
1281 }
1282 }
1283 if (typeof process === "undefined" || true) {
1284 registerStyle("c46e8cb841", "@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;@layer wp-ui-components{.f37b9e2e191ebd66__visually-hidden{word-wrap:normal;border:0;clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-break:normal}}");
1285 }
1286 var style_default = { "visually-hidden": "f37b9e2e191ebd66__visually-hidden" };
1287 var VisuallyHidden = (0, import_element3.forwardRef)(
1288 function VisuallyHidden2({ render, ...restProps }, ref) {
1289 const element = useRender({
1290 render,
1291 ref,
1292 props: mergeProps(
1293 { className: style_default["visually-hidden"] },
1294 restProps,
1295 {
1296 // @ts-expect-error Arbitrary data-* attributes aren't indexable on the typed div props. Kept hardcoded so consumers can't change or remove it.
1297 "data-visually-hidden": ""
1298 }
1299 )
1300 });
1301 return element;
1302 }
1303 );
1304
1305 // packages/format-library/build-module/link/css-classes-setting.mjs
1306 var import_jsx_runtime18 = __toESM(require_jsx_runtime(), 1);
1307 var CSSClassesSettingComponent = ({ setting, value, onChange }) => {
1308 const hasValue = value ? value?.cssClasses?.length > 0 : false;
1309 const [isSettingActive, setIsSettingActive] = (0, import_element4.useState)(hasValue);
1310 const instanceId = (0, import_compose.useInstanceId)(CSSClassesSettingComponent);
1311 const controlledRegionId = `css-classes-setting-${instanceId}`;
1312 const handleSettingChange = (newValue) => {
1313 const sanitizedValue = typeof newValue === "string" ? newValue.replace(/,/g, " ").replace(/\s+/g, " ").trim() : newValue;
1314 onChange({
1315 ...value,
1316 [setting.id]: sanitizedValue
1317 });
1318 };
1319 const handleCheckboxChange = () => {
1320 if (isSettingActive) {
1321 if (hasValue) {
1322 handleSettingChange("");
1323 }
1324 setIsSettingActive(false);
1325 } else {
1326 setIsSettingActive(true);
1327 }
1328 };
1329 return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)("fieldset", { children: [
1330 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(VisuallyHidden, { render: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("legend", {}), children: setting.title }),
1331 /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(import_components2.__experimentalVStack, { spacing: 3, children: [
1332 /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1333 import_components2.CheckboxControl,
1334 {
1335 label: setting.title,
1336 onChange: handleCheckboxChange,
1337 checked: isSettingActive || hasValue,
1338 "aria-expanded": isSettingActive,
1339 "aria-controls": isSettingActive ? controlledRegionId : void 0
1340 }
1341 ),
1342 isSettingActive && /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { id: controlledRegionId, children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1343 import_components2.__experimentalInputControl,
1344 {
1345 label: (0, import_i18n5.__)("CSS classes"),
1346 value: value?.cssClasses,
1347 onChange: handleSettingChange,
1348 help: (0, import_i18n5.__)(
1349 "Separate multiple classes with spaces."
1350 ),
1351 __unstableInputWidth: "100%",
1352 __next40pxDefaultSize: true
1353 }
1354 ) })
1355 ] })
1356 ] });
1357 };
1358 var css_classes_setting_default = CSSClassesSettingComponent;
1359
1360 // packages/format-library/build-module/link/inline.mjs
1361 var import_jsx_runtime19 = __toESM(require_jsx_runtime(), 1);
1362 var LINK_SETTINGS = [
1363 ...import_block_editor5.LinkControl.DEFAULT_LINK_SETTINGS,
1364 {
1365 id: "nofollow",
1366 title: (0, import_i18n6.__)("Mark as nofollow")
1367 },
1368 {
1369 id: "cssClasses",
1370 title: (0, import_i18n6.__)("Additional CSS class(es)"),
1371 render: (setting, value, onChange) => {
1372 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1373 css_classes_setting_default,
1374 {
1375 setting,
1376 value,
1377 onChange
1378 }
1379 );
1380 }
1381 }
1382 ];
1383 function InlineLinkUI({
1384 isActive,
1385 activeAttributes,
1386 value,
1387 onChange,
1388 onFocusOutside,
1389 stopAddingLink,
1390 contentRef,
1391 focusOnMount
1392 }) {
1393 const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
1394 const richTextText = richLinkTextValue.text;
1395 const { selectionChange } = (0, import_data.useDispatch)(import_block_editor5.store);
1396 const { createPageEntity, userCanCreatePages, selectionStart } = (0, import_data.useSelect)(
1397 (select) => {
1398 const { getSettings, getSelectionStart } = select(import_block_editor5.store);
1399 const _settings = getSettings();
1400 return {
1401 createPageEntity: _settings.__experimentalCreatePageEntity,
1402 userCanCreatePages: _settings.__experimentalUserCanCreatePages,
1403 selectionStart: getSelectionStart()
1404 };
1405 },
1406 []
1407 );
1408 const linkValue = (0, import_element5.useMemo)(
1409 () => ({
1410 url: activeAttributes.url,
1411 type: activeAttributes.type,
1412 id: activeAttributes.id,
1413 opensInNewTab: activeAttributes.target === "_blank",
1414 nofollow: activeAttributes.rel?.includes("nofollow"),
1415 title: richTextText,
1416 cssClasses: activeAttributes.class
1417 }),
1418 [
1419 activeAttributes.class,
1420 activeAttributes.id,
1421 activeAttributes.rel,
1422 activeAttributes.target,
1423 activeAttributes.type,
1424 activeAttributes.url,
1425 richTextText
1426 ]
1427 );
1428 function removeLink() {
1429 const newValue = (0, import_rich_text5.removeFormat)(value, "core/link");
1430 onChange(newValue);
1431 stopAddingLink();
1432 (0, import_a11y.speak)((0, import_i18n6.__)("Link removed."), "assertive");
1433 }
1434 function onChangeLink(nextValue) {
1435 const hasLink = linkValue?.url;
1436 const isNewLink = !hasLink;
1437 nextValue = {
1438 ...linkValue,
1439 ...nextValue
1440 };
1441 const newUrl = (0, import_url2.prependHTTPS)(nextValue.url);
1442 const linkFormat = createLinkFormat({
1443 url: newUrl,
1444 type: nextValue.type,
1445 id: nextValue.id !== void 0 && nextValue.id !== null ? String(nextValue.id) : void 0,
1446 opensInNewWindow: nextValue.opensInNewTab,
1447 nofollow: nextValue.nofollow,
1448 cssClasses: nextValue.cssClasses
1449 });
1450 const newText = nextValue.title || newUrl;
1451 let newValue;
1452 if ((0, import_rich_text5.isCollapsed)(value) && !isActive) {
1453 const inserted = (0, import_rich_text5.insert)(value, newText);
1454 newValue = (0, import_rich_text5.applyFormat)(
1455 inserted,
1456 linkFormat,
1457 value.start,
1458 value.start + newText.length
1459 );
1460 onChange(newValue);
1461 stopAddingLink();
1462 selectionChange({
1463 clientId: selectionStart.clientId,
1464 identifier: selectionStart.attributeKey,
1465 start: value.start + newText.length + 1
1466 });
1467 return;
1468 } else if (newText === richTextText) {
1469 const boundary = getFormatBoundary(value, {
1470 type: "core/link"
1471 });
1472 newValue = (0, import_rich_text5.applyFormat)(
1473 value,
1474 linkFormat,
1475 boundary.start,
1476 boundary.end
1477 );
1478 } else {
1479 newValue = (0, import_rich_text5.create)({ text: newText });
1480 newValue = (0, import_rich_text5.applyFormat)(newValue, linkFormat, 0, newText.length);
1481 const boundary = getFormatBoundary(value, {
1482 type: "core/link"
1483 });
1484 const [valBefore, valAfter] = (0, import_rich_text5.split)(
1485 value,
1486 boundary.start,
1487 boundary.start
1488 );
1489 const newValAfter = (0, import_rich_text5.replace)(valAfter, richTextText, newValue);
1490 newValue = (0, import_rich_text5.concat)(valBefore, newValAfter);
1491 }
1492 onChange(newValue);
1493 if (!isNewLink) {
1494 stopAddingLink();
1495 }
1496 if (!isValidHref(newUrl)) {
1497 (0, import_a11y.speak)(
1498 (0, import_i18n6.__)(
1499 "Warning: the link has been inserted but may have errors. Please test it."
1500 ),
1501 "assertive"
1502 );
1503 } else if (isActive) {
1504 (0, import_a11y.speak)((0, import_i18n6.__)("Link edited."), "assertive");
1505 } else {
1506 (0, import_a11y.speak)((0, import_i18n6.__)("Link inserted."), "assertive");
1507 }
1508 }
1509 const popoverAnchor = (0, import_rich_text5.useAnchor)({
1510 editableContentElement: contentRef.current,
1511 settings: {
1512 ...link,
1513 isActive
1514 }
1515 });
1516 async function handleCreate(pageTitle) {
1517 const page = await createPageEntity({
1518 title: pageTitle,
1519 status: "draft"
1520 });
1521 return {
1522 id: page.id,
1523 type: page.type,
1524 title: page.title.rendered,
1525 url: page.link,
1526 kind: "post-type"
1527 };
1528 }
1529 function createButtonText(searchTerm) {
1530 return (0, import_element5.createInterpolateElement)(
1531 (0, import_i18n6.sprintf)(
1532 /* translators: %s: search term. */
1533 (0, import_i18n6.__)("Create page: <mark>%s</mark>"),
1534 searchTerm
1535 ),
1536 { mark: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("mark", {}) }
1537 );
1538 }
1539 return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1540 import_components3.Popover,
1541 {
1542 anchor: popoverAnchor,
1543 animate: false,
1544 onClose: stopAddingLink,
1545 onFocusOutside,
1546 placement: "bottom",
1547 offset: 8,
1548 shift: true,
1549 focusOnMount,
1550 constrainTabbing: true,
1551 children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1552 import_block_editor5.LinkControl,
1553 {
1554 value: linkValue,
1555 onChange: onChangeLink,
1556 onRemove: removeLink,
1557 hasRichPreviews: true,
1558 createSuggestion: createPageEntity && handleCreate,
1559 withCreateSuggestion: userCanCreatePages,
1560 createSuggestionButtonText: createButtonText,
1561 hasTextControl: true,
1562 settings: LINK_SETTINGS,
1563 showInitialSuggestions: true,
1564 suggestionsQuery: {
1565 // always show Pages as initial suggestions
1566 initialSuggestionsSearchOptions: {
1567 type: "post",
1568 subtype: "page",
1569 perPage: 20
1570 }
1571 }
1572 }
1573 )
1574 }
1575 );
1576 }
1577 function getRichTextValueFromSelection(value, isActive) {
1578 let textStart = value.start;
1579 let textEnd = value.end;
1580 if (isActive) {
1581 const boundary = getFormatBoundary(value, {
1582 type: "core/link"
1583 });
1584 textStart = boundary.start;
1585 textEnd = boundary.end;
1586 }
1587 return (0, import_rich_text5.slice)(value, textStart, textEnd);
1588 }
1589 var inline_default = InlineLinkUI;
1590
1591 // packages/format-library/build-module/link/index.mjs
1592 var import_jsx_runtime20 = __toESM(require_jsx_runtime(), 1);
1593 var name5 = "core/link";
1594 var title5 = (0, import_i18n7.__)("Link");
1595 function Edit2({
1596 isActive,
1597 activeAttributes,
1598 value,
1599 onChange,
1600 onFocus,
1601 contentRef,
1602 isVisible = true
1603 }) {
1604 const [addingLink, setAddingLink] = (0, import_element6.useState)(false);
1605 const [openedBy, setOpenedBy] = (0, import_element6.useState)(null);
1606 (0, import_element6.useEffect)(() => {
1607 if (!isActive) {
1608 setAddingLink(false);
1609 }
1610 }, [isActive]);
1611 (0, import_element6.useLayoutEffect)(() => {
1612 const editableContentElement = contentRef.current;
1613 if (!editableContentElement) {
1614 return;
1615 }
1616 function handleClick(event) {
1617 const link2 = event.target.closest("[contenteditable] a");
1618 if (!link2 || // other formats (e.g. bold) may be nested within the link.
1619 !isActive) {
1620 return;
1621 }
1622 setAddingLink(true);
1623 setOpenedBy({
1624 el: link2,
1625 action: "click"
1626 });
1627 }
1628 editableContentElement.addEventListener("click", handleClick);
1629 return () => {
1630 editableContentElement.removeEventListener("click", handleClick);
1631 };
1632 }, [contentRef, isActive]);
1633 function addLink(target) {
1634 const text = (0, import_rich_text6.getTextContent)((0, import_rich_text6.slice)(value));
1635 if (!isActive && text && (0, import_url3.isURL)(text) && isValidHref(text)) {
1636 onChange(
1637 (0, import_rich_text6.applyFormat)(value, {
1638 type: name5,
1639 attributes: { url: text }
1640 })
1641 );
1642 } else if (!isActive && text && (0, import_url3.isEmail)(text)) {
1643 onChange(
1644 (0, import_rich_text6.applyFormat)(value, {
1645 type: name5,
1646 attributes: { url: `mailto:${text}` }
1647 })
1648 );
1649 } else if (!isActive && text && (0, import_url3.isPhoneNumber)(text)) {
1650 onChange(
1651 (0, import_rich_text6.applyFormat)(value, {
1652 type: name5,
1653 attributes: { url: `tel:${text.replace(/\D/g, "")}` }
1654 })
1655 );
1656 } else {
1657 if (target) {
1658 setOpenedBy({
1659 el: target,
1660 action: null
1661 // We don't need to distinguish between click or keyboard here
1662 });
1663 }
1664 setAddingLink(true);
1665 }
1666 }
1667 function stopAddingLink() {
1668 setAddingLink(false);
1669 if (openedBy?.el?.tagName === "BUTTON") {
1670 openedBy.el.focus();
1671 } else {
1672 onFocus();
1673 }
1674 setOpenedBy(null);
1675 }
1676 function onFocusOutside() {
1677 setAddingLink(false);
1678 setOpenedBy(null);
1679 }
1680 function onRemoveFormat() {
1681 onChange((0, import_rich_text6.removeFormat)(value, name5));
1682 (0, import_a11y2.speak)((0, import_i18n7.__)("Link removed."), "assertive");
1683 }
1684 const shouldAutoFocus = !(openedBy?.el?.tagName === "A" && openedBy?.action === "click");
1685 const hasSelection = !(0, import_rich_text6.isCollapsed)(value);
1686 return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
1687 hasSelection && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1688 import_block_editor6.RichTextShortcut,
1689 {
1690 type: "primary",
1691 character: "k",
1692 onUse: addLink
1693 }
1694 ),
1695 /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1696 import_block_editor6.RichTextShortcut,
1697 {
1698 type: "primaryShift",
1699 character: "k",
1700 onUse: onRemoveFormat
1701 }
1702 ),
1703 isVisible && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1704 import_block_editor6.RichTextToolbarButton,
1705 {
1706 name: "link",
1707 icon: link_default,
1708 title: isActive ? (0, import_i18n7.__)("Link") : title5,
1709 onClick: (event) => {
1710 addLink(event.currentTarget);
1711 },
1712 isActive: isActive || addingLink,
1713 shortcutType: "primary",
1714 shortcutCharacter: "k",
1715 "aria-haspopup": "true",
1716 "aria-expanded": addingLink
1717 }
1718 ),
1719 isVisible && addingLink && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
1720 inline_default,
1721 {
1722 stopAddingLink,
1723 onFocusOutside,
1724 isActive,
1725 activeAttributes,
1726 value,
1727 onChange,
1728 contentRef,
1729 focusOnMount: shouldAutoFocus ? "firstElement" : false
1730 }
1731 )
1732 ] });
1733 }
1734 var link = {
1735 name: name5,
1736 title: title5,
1737 tagName: "a",
1738 className: null,
1739 attributes: {
1740 url: "href",
1741 type: "data-type",
1742 id: "data-id",
1743 _id: "id",
1744 target: "target",
1745 rel: "rel",
1746 class: "class"
1747 },
1748 __unstablePasteRule(value, { html, plainText }) {
1749 const pastedText = (html || plainText).replace(/<[^>]+>/g, "").trim();
1750 if (!(0, import_url3.isURL)(pastedText) || !/^https?:/.test(pastedText)) {
1751 return value;
1752 }
1753 window.console.log("Created link:\n\n", pastedText);
1754 const format = {
1755 type: name5,
1756 attributes: {
1757 url: (0, import_html_entities.decodeEntities)(pastedText)
1758 }
1759 };
1760 if ((0, import_rich_text6.isCollapsed)(value)) {
1761 return (0, import_rich_text6.insert)(
1762 value,
1763 (0, import_rich_text6.applyFormat)(
1764 (0, import_rich_text6.create)({ text: plainText }),
1765 format,
1766 0,
1767 plainText.length
1768 )
1769 );
1770 }
1771 return (0, import_rich_text6.applyFormat)(value, format);
1772 },
1773 edit: Edit2
1774 };
1775
1776 // packages/format-library/build-module/strikethrough/index.mjs
1777 var import_i18n8 = __toESM(require_i18n(), 1);
1778 var import_rich_text7 = __toESM(require_rich_text(), 1);
1779 var import_block_editor7 = __toESM(require_block_editor(), 1);
1780 var import_jsx_runtime21 = __toESM(require_jsx_runtime(), 1);
1781 var name6 = "core/strikethrough";
1782 var title6 = (0, import_i18n8.__)("Strikethrough");
1783 var strikethrough = {
1784 name: name6,
1785 title: title6,
1786 tagName: "s",
1787 className: null,
1788 edit({ isActive, value, onChange, onFocus }) {
1789 function onClick() {
1790 onChange((0, import_rich_text7.toggleFormat)(value, { type: name6, title: title6 }));
1791 onFocus();
1792 }
1793 return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
1794 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1795 import_block_editor7.RichTextShortcut,
1796 {
1797 type: "access",
1798 character: "d",
1799 onUse: onClick
1800 }
1801 ),
1802 /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
1803 import_block_editor7.RichTextToolbarButton,
1804 {
1805 icon: format_strikethrough_default,
1806 title: title6,
1807 onClick,
1808 isActive,
1809 role: "menuitemcheckbox"
1810 }
1811 )
1812 ] });
1813 }
1814 };
1815
1816 // packages/format-library/build-module/underline/index.mjs
1817 var import_i18n9 = __toESM(require_i18n(), 1);
1818 var import_rich_text8 = __toESM(require_rich_text(), 1);
1819 var import_block_editor8 = __toESM(require_block_editor(), 1);
1820 var import_jsx_runtime22 = __toESM(require_jsx_runtime(), 1);
1821 var name7 = "core/underline";
1822 var title7 = (0, import_i18n9.__)("Underline");
1823 var underline = {
1824 name: name7,
1825 title: title7,
1826 tagName: "span",
1827 className: null,
1828 attributes: {
1829 style: "style"
1830 },
1831 edit({ value, onChange }) {
1832 const onToggle = () => {
1833 onChange(
1834 (0, import_rich_text8.toggleFormat)(value, {
1835 type: name7,
1836 attributes: {
1837 style: "text-decoration: underline;"
1838 },
1839 title: title7
1840 })
1841 );
1842 };
1843 return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
1844 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1845 import_block_editor8.RichTextShortcut,
1846 {
1847 type: "primary",
1848 character: "u",
1849 onUse: onToggle
1850 }
1851 ),
1852 /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
1853 import_block_editor8.__unstableRichTextInputEvent,
1854 {
1855 inputType: "formatUnderline",
1856 onInput: onToggle
1857 }
1858 )
1859 ] });
1860 }
1861 };
1862
1863 // packages/format-library/build-module/text-color/index.mjs
1864 var import_i18n11 = __toESM(require_i18n(), 1);
1865 var import_element8 = __toESM(require_element(), 1);
1866 var import_block_editor10 = __toESM(require_block_editor(), 1);
1867 var import_rich_text10 = __toESM(require_rich_text(), 1);
1868
1869 // packages/format-library/build-module/text-color/inline.mjs
1870 var import_element7 = __toESM(require_element(), 1);
1871 var import_data2 = __toESM(require_data(), 1);
1872 var import_rich_text9 = __toESM(require_rich_text(), 1);
1873 var import_block_editor9 = __toESM(require_block_editor(), 1);
1874 var import_components4 = __toESM(require_components(), 1);
1875 var import_i18n10 = __toESM(require_i18n(), 1);
1876
1877 // packages/format-library/build-module/lock-unlock.mjs
1878 var import_private_apis = __toESM(require_private_apis(), 1);
1879 var { lock, unlock } = (0, import_private_apis.__dangerousOptInToUnstableAPIsOnlyForCoreModules)(
1880 "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
1881 "@wordpress/format-library"
1882 );
1883
1884 // packages/format-library/build-module/text-color/inline.mjs
1885 var import_jsx_runtime23 = __toESM(require_jsx_runtime(), 1);
1886 var { Tabs } = unlock(import_components4.privateApis);
1887 var TABS = [
1888 { name: "color", title: (0, import_i18n10.__)("Text") },
1889 { name: "backgroundColor", title: (0, import_i18n10.__)("Background") }
1890 ];
1891 function parseCSS(css = "") {
1892 return css.split(";").reduce((accumulator, rule) => {
1893 if (rule) {
1894 const [property, value] = rule.split(":");
1895 if (property === "color") {
1896 accumulator.color = value;
1897 }
1898 if (property === "background-color" && value !== transparentValue) {
1899 accumulator.backgroundColor = value;
1900 }
1901 }
1902 return accumulator;
1903 }, {});
1904 }
1905 function parseClassName(className = "", colorSettings) {
1906 return className.split(" ").reduce((accumulator, name16) => {
1907 if (name16.startsWith("has-") && name16.endsWith("-color")) {
1908 const colorSlug = name16.replace(/^has-/, "").replace(/-color$/, "");
1909 const colorObject = (0, import_block_editor9.getColorObjectByAttributeValues)(
1910 colorSettings,
1911 colorSlug
1912 );
1913 accumulator.color = colorObject.color;
1914 }
1915 return accumulator;
1916 }, {});
1917 }
1918 function getActiveColors(value, name16, colorSettings) {
1919 const activeColorFormat = (0, import_rich_text9.getActiveFormat)(value, name16);
1920 if (!activeColorFormat) {
1921 return {};
1922 }
1923 return {
1924 ...parseCSS(activeColorFormat.attributes.style),
1925 ...parseClassName(activeColorFormat.attributes.class, colorSettings)
1926 };
1927 }
1928 function setColors(value, name16, colorSettings, colors) {
1929 const { color, backgroundColor } = {
1930 ...getActiveColors(value, name16, colorSettings),
1931 ...colors
1932 };
1933 if (!color && !backgroundColor) {
1934 return (0, import_rich_text9.removeFormat)(value, name16);
1935 }
1936 const styles = [];
1937 const classNames = [];
1938 const attributes = {};
1939 if (backgroundColor) {
1940 styles.push(["background-color", backgroundColor].join(":"));
1941 } else {
1942 styles.push(["background-color", transparentValue].join(":"));
1943 }
1944 if (color) {
1945 const colorObject = (0, import_block_editor9.getColorObjectByColorValue)(colorSettings, color);
1946 if (colorObject) {
1947 classNames.push((0, import_block_editor9.getColorClassName)("color", colorObject.slug));
1948 } else {
1949 styles.push(["color", color].join(":"));
1950 }
1951 }
1952 if (styles.length) {
1953 attributes.style = styles.join(";");
1954 }
1955 if (classNames.length) {
1956 attributes.class = classNames.join(" ");
1957 }
1958 return (0, import_rich_text9.applyFormat)(value, { type: name16, attributes });
1959 }
1960 function ColorPicker({ name: name16, property, value, onChange }) {
1961 const colors = (0, import_data2.useSelect)((select) => {
1962 const { getSettings } = select(import_block_editor9.store);
1963 return getSettings().colors ?? [];
1964 }, []);
1965 const activeColors = (0, import_element7.useMemo)(
1966 () => getActiveColors(value, name16, colors),
1967 [name16, value, colors]
1968 );
1969 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1970 import_block_editor9.ColorPalette,
1971 {
1972 value: activeColors[property],
1973 onChange: (color) => {
1974 onChange(
1975 setColors(value, name16, colors, { [property]: color })
1976 );
1977 },
1978 enableAlpha: true,
1979 __experimentalIsRenderedInSidebar: true
1980 }
1981 );
1982 }
1983 function InlineColorUI({
1984 name: name16,
1985 value,
1986 onChange,
1987 onClose,
1988 contentRef,
1989 isActive
1990 }) {
1991 const popoverAnchor = (0, import_rich_text9.useAnchor)({
1992 editableContentElement: contentRef.current,
1993 settings: { ...textColor, isActive }
1994 });
1995 return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
1996 import_components4.Popover,
1997 {
1998 onClose,
1999 className: "format-library__inline-color-popover",
2000 anchor: popoverAnchor,
2001 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Tabs, { children: [
2002 /* @__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)) }),
2003 TABS.map((tab) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2004 Tabs.TabPanel,
2005 {
2006 tabId: tab.name,
2007 focusable: false,
2008 children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
2009 ColorPicker,
2010 {
2011 name: name16,
2012 property: tab.name,
2013 value,
2014 onChange
2015 }
2016 )
2017 },
2018 tab.name
2019 ))
2020 ] })
2021 }
2022 );
2023 }
2024
2025 // packages/format-library/build-module/text-color/index.mjs
2026 var import_jsx_runtime24 = __toESM(require_jsx_runtime(), 1);
2027 var transparentValue = "rgba(0, 0, 0, 0)";
2028 var name8 = "core/text-color";
2029 var title8 = (0, import_i18n11.__)("Highlight");
2030 var EMPTY_ARRAY2 = [];
2031 function getComputedStyleProperty(element, property) {
2032 const { ownerDocument } = element;
2033 const { defaultView } = ownerDocument;
2034 const style = defaultView.getComputedStyle(element);
2035 const value = style.getPropertyValue(property);
2036 if (property === "background-color" && value === transparentValue && element.parentElement) {
2037 return getComputedStyleProperty(element.parentElement, property);
2038 }
2039 return value;
2040 }
2041 function fillComputedColors(element, { color, backgroundColor }) {
2042 if (!color && !backgroundColor) {
2043 return;
2044 }
2045 return {
2046 color: color || getComputedStyleProperty(element, "color"),
2047 backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, "background-color") : backgroundColor
2048 };
2049 }
2050 function TextColorEdit({
2051 value,
2052 onChange,
2053 isActive,
2054 activeAttributes,
2055 contentRef
2056 }) {
2057 const [allowCustomControl, colors = EMPTY_ARRAY2] = (0, import_block_editor10.useSettings)(
2058 "color.custom",
2059 "color.palette"
2060 );
2061 const [isAddingColor, setIsAddingColor] = (0, import_element8.useState)(false);
2062 const colorIndicatorStyle = (0, import_element8.useMemo)(
2063 () => fillComputedColors(
2064 contentRef.current,
2065 getActiveColors(value, name8, colors)
2066 ),
2067 [contentRef, value, colors]
2068 );
2069 const hasColorsToChoose = !!colors.length || allowCustomControl;
2070 if (!hasColorsToChoose && !isActive) {
2071 return null;
2072 }
2073 return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_jsx_runtime24.Fragment, { children: [
2074 /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2075 import_block_editor10.RichTextToolbarButton,
2076 {
2077 className: "format-library-text-color-button",
2078 isActive,
2079 icon: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2080 icon_default,
2081 {
2082 icon: Object.keys(activeAttributes).length ? text_color_default : color_default,
2083 style: colorIndicatorStyle
2084 }
2085 ),
2086 title: title8,
2087 onClick: hasColorsToChoose ? () => setIsAddingColor(true) : () => onChange((0, import_rich_text10.removeFormat)(value, name8)),
2088 role: "menuitemcheckbox"
2089 }
2090 ),
2091 isAddingColor && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2092 InlineColorUI,
2093 {
2094 name: name8,
2095 onClose: () => setIsAddingColor(false),
2096 activeAttributes,
2097 value,
2098 onChange,
2099 contentRef,
2100 isActive
2101 }
2102 )
2103 ] });
2104 }
2105 var textColor = {
2106 name: name8,
2107 title: title8,
2108 tagName: "mark",
2109 className: "has-inline-color",
2110 attributes: {
2111 style: "style",
2112 class: "class"
2113 },
2114 edit: TextColorEdit
2115 };
2116
2117 // packages/format-library/build-module/subscript/index.mjs
2118 var import_i18n12 = __toESM(require_i18n(), 1);
2119 var import_rich_text11 = __toESM(require_rich_text(), 1);
2120 var import_block_editor11 = __toESM(require_block_editor(), 1);
2121 var import_jsx_runtime25 = __toESM(require_jsx_runtime(), 1);
2122 var name9 = "core/subscript";
2123 var title9 = (0, import_i18n12.__)("Subscript");
2124 var subscript = {
2125 name: name9,
2126 title: title9,
2127 tagName: "sub",
2128 className: null,
2129 edit({ isActive, value, onChange, onFocus }) {
2130 function onToggle() {
2131 onChange((0, import_rich_text11.toggleFormat)(value, { type: name9, title: title9 }));
2132 }
2133 function onClick() {
2134 onToggle();
2135 onFocus();
2136 }
2137 return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
2138 import_block_editor11.RichTextToolbarButton,
2139 {
2140 icon: subscript_default,
2141 title: title9,
2142 onClick,
2143 isActive,
2144 role: "menuitemcheckbox"
2145 }
2146 );
2147 }
2148 };
2149
2150 // packages/format-library/build-module/superscript/index.mjs
2151 var import_i18n13 = __toESM(require_i18n(), 1);
2152 var import_rich_text12 = __toESM(require_rich_text(), 1);
2153 var import_block_editor12 = __toESM(require_block_editor(), 1);
2154 var import_jsx_runtime26 = __toESM(require_jsx_runtime(), 1);
2155 var name10 = "core/superscript";
2156 var title10 = (0, import_i18n13.__)("Superscript");
2157 var superscript = {
2158 name: name10,
2159 title: title10,
2160 tagName: "sup",
2161 className: null,
2162 edit({ isActive, value, onChange, onFocus }) {
2163 function onToggle() {
2164 onChange((0, import_rich_text12.toggleFormat)(value, { type: name10, title: title10 }));
2165 }
2166 function onClick() {
2167 onToggle();
2168 onFocus();
2169 }
2170 return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
2171 import_block_editor12.RichTextToolbarButton,
2172 {
2173 icon: superscript_default,
2174 title: title10,
2175 onClick,
2176 isActive,
2177 role: "menuitemcheckbox"
2178 }
2179 );
2180 }
2181 };
2182
2183 // packages/format-library/build-module/keyboard/index.mjs
2184 var import_i18n14 = __toESM(require_i18n(), 1);
2185 var import_rich_text13 = __toESM(require_rich_text(), 1);
2186 var import_block_editor13 = __toESM(require_block_editor(), 1);
2187 var import_jsx_runtime27 = __toESM(require_jsx_runtime(), 1);
2188 var name11 = "core/keyboard";
2189 var title11 = (0, import_i18n14.__)("Keyboard input");
2190 var keyboard = {
2191 name: name11,
2192 title: title11,
2193 tagName: "kbd",
2194 className: null,
2195 edit({ isActive, value, onChange, onFocus }) {
2196 function onToggle() {
2197 onChange((0, import_rich_text13.toggleFormat)(value, { type: name11, title: title11 }));
2198 }
2199 function onClick() {
2200 onToggle();
2201 onFocus();
2202 }
2203 return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
2204 import_block_editor13.RichTextToolbarButton,
2205 {
2206 icon: button_default,
2207 title: title11,
2208 onClick,
2209 isActive,
2210 role: "menuitemcheckbox"
2211 }
2212 );
2213 }
2214 };
2215
2216 // packages/format-library/build-module/unknown/index.mjs
2217 var import_i18n15 = __toESM(require_i18n(), 1);
2218 var import_rich_text14 = __toESM(require_rich_text(), 1);
2219 var import_block_editor14 = __toESM(require_block_editor(), 1);
2220 var import_jsx_runtime28 = __toESM(require_jsx_runtime(), 1);
2221 var name12 = "core/unknown";
2222 var title12 = (0, import_i18n15.__)("Clear Unknown Formatting");
2223 function selectionContainsUnknownFormats(value) {
2224 if ((0, import_rich_text14.isCollapsed)(value)) {
2225 return false;
2226 }
2227 const selectedValue = (0, import_rich_text14.slice)(value);
2228 return selectedValue.formats.some((formats) => {
2229 return formats.some((format) => format.type === name12);
2230 });
2231 }
2232 var unknown = {
2233 name: name12,
2234 title: title12,
2235 tagName: "*",
2236 className: null,
2237 edit({ isActive, value, onChange, onFocus }) {
2238 if (!isActive && !selectionContainsUnknownFormats(value)) {
2239 return null;
2240 }
2241 function onClick() {
2242 onChange((0, import_rich_text14.removeFormat)(value, name12));
2243 onFocus();
2244 }
2245 return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
2246 import_block_editor14.RichTextToolbarButton,
2247 {
2248 name: "unknown",
2249 icon: help_default,
2250 title: title12,
2251 onClick,
2252 isActive: true
2253 }
2254 );
2255 }
2256 };
2257
2258 // packages/format-library/build-module/language/index.mjs
2259 var import_i18n16 = __toESM(require_i18n(), 1);
2260 var import_block_editor15 = __toESM(require_block_editor(), 1);
2261 var import_components5 = __toESM(require_components(), 1);
2262 var import_element9 = __toESM(require_element(), 1);
2263 var import_rich_text15 = __toESM(require_rich_text(), 1);
2264 var import_jsx_runtime29 = __toESM(require_jsx_runtime(), 1);
2265 var name13 = "core/language";
2266 var title13 = (0, import_i18n16.__)("Language");
2267 var language = {
2268 name: name13,
2269 title: title13,
2270 tagName: "bdo",
2271 className: null,
2272 attributes: {
2273 lang: "lang",
2274 dir: "dir"
2275 },
2276 edit: Edit3
2277 };
2278 function Edit3({ isActive, value, onChange, contentRef }) {
2279 const [isPopoverVisible, setIsPopoverVisible] = (0, import_element9.useState)(false);
2280 const togglePopover = () => {
2281 setIsPopoverVisible((state) => !state);
2282 };
2283 return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(import_jsx_runtime29.Fragment, { children: [
2284 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2285 import_block_editor15.RichTextToolbarButton,
2286 {
2287 icon: language_default,
2288 label: title13,
2289 title: title13,
2290 onClick: () => {
2291 if (isActive) {
2292 onChange((0, import_rich_text15.removeFormat)(value, name13));
2293 } else {
2294 togglePopover();
2295 }
2296 },
2297 isActive,
2298 role: "menuitemcheckbox"
2299 }
2300 ),
2301 isPopoverVisible && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2302 InlineLanguageUI,
2303 {
2304 value,
2305 onChange,
2306 onClose: togglePopover,
2307 contentRef
2308 }
2309 )
2310 ] });
2311 }
2312 function InlineLanguageUI({ value, contentRef, onChange, onClose }) {
2313 const popoverAnchor = (0, import_rich_text15.useAnchor)({
2314 editableContentElement: contentRef.current,
2315 settings: language
2316 });
2317 const [lang, setLang] = (0, import_element9.useState)("");
2318 const [dir, setDir] = (0, import_element9.useState)("ltr");
2319 return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2320 import_components5.Popover,
2321 {
2322 className: "block-editor-format-toolbar__language-popover",
2323 anchor: popoverAnchor,
2324 onClose,
2325 children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
2326 import_components5.__experimentalVStack,
2327 {
2328 as: "form",
2329 spacing: 4,
2330 className: "block-editor-format-toolbar__language-container-content",
2331 onSubmit: (event) => {
2332 event.preventDefault();
2333 onChange(
2334 (0, import_rich_text15.applyFormat)(value, {
2335 type: name13,
2336 attributes: {
2337 lang,
2338 dir
2339 }
2340 })
2341 );
2342 onClose();
2343 },
2344 children: [
2345 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2346 import_components5.TextControl,
2347 {
2348 __next40pxDefaultSize: true,
2349 label: title13,
2350 value: lang,
2351 onChange: (val) => setLang(val),
2352 help: (0, import_i18n16.__)(
2353 'A valid language attribute, like "en" or "fr".'
2354 )
2355 }
2356 ),
2357 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2358 import_components5.SelectControl,
2359 {
2360 __next40pxDefaultSize: true,
2361 label: (0, import_i18n16.__)("Text direction"),
2362 value: dir,
2363 options: [
2364 {
2365 label: (0, import_i18n16.__)("Left to right"),
2366 value: "ltr"
2367 },
2368 {
2369 label: (0, import_i18n16.__)("Right to left"),
2370 value: "rtl"
2371 }
2372 ],
2373 onChange: (val) => setDir(val)
2374 }
2375 ),
2376 /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_components5.__experimentalHStack, { alignment: "right", children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
2377 import_components5.Button,
2378 {
2379 __next40pxDefaultSize: true,
2380 variant: "primary",
2381 type: "submit",
2382 text: (0, import_i18n16.__)("Apply")
2383 }
2384 ) })
2385 ]
2386 }
2387 )
2388 }
2389 );
2390 }
2391
2392 // packages/format-library/build-module/math/index.mjs
2393 var import_i18n17 = __toESM(require_i18n(), 1);
2394 var import_element10 = __toESM(require_element(), 1);
2395 var import_rich_text16 = __toESM(require_rich_text(), 1);
2396 var import_block_editor16 = __toESM(require_block_editor(), 1);
2397 var import_components6 = __toESM(require_components(), 1);
2398 var import_a11y3 = __toESM(require_a11y(), 1);
2399 var import_jsx_runtime30 = __toESM(require_jsx_runtime(), 1);
2400 var { Badge: WCBadge } = unlock(import_components6.privateApis);
2401 var name14 = "core/math";
2402 var title14 = (0, import_i18n17.__)("Math");
2403 function InlineUI2({
2404 value,
2405 onChange,
2406 activeAttributes,
2407 contentRef,
2408 latexToMathML
2409 }) {
2410 const [latex, setLatex] = (0, import_element10.useState)(
2411 activeAttributes?.["data-latex"] || ""
2412 );
2413 const [error, setError] = (0, import_element10.useState)(null);
2414 const popoverAnchor = (0, import_rich_text16.useAnchor)({
2415 editableContentElement: contentRef.current,
2416 settings: math
2417 });
2418 const handleLatexChange = (newLatex) => {
2419 let mathML = "";
2420 setLatex(newLatex);
2421 if (newLatex) {
2422 try {
2423 mathML = latexToMathML(newLatex, { displayMode: false });
2424 setError(null);
2425 } catch (err) {
2426 setError(err.message);
2427 (0, import_a11y3.speak)(
2428 (0, import_i18n17.sprintf)(
2429 /* translators: %s: error message returned when parsing LaTeX. */
2430 (0, import_i18n17.__)("Error parsing mathematical expression: %s"),
2431 err.message
2432 )
2433 );
2434 return;
2435 }
2436 }
2437 const newReplacements = value.replacements.slice();
2438 newReplacements[value.start] = {
2439 type: name14,
2440 attributes: {
2441 "data-latex": newLatex
2442 },
2443 innerHTML: mathML
2444 };
2445 onChange({
2446 ...value,
2447 replacements: newReplacements
2448 });
2449 };
2450 return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2451 import_components6.Popover,
2452 {
2453 placement: "bottom-start",
2454 offset: 8,
2455 focusOnMount: false,
2456 anchor: popoverAnchor,
2457 className: "block-editor-format-toolbar__math-popover",
2458 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: [
2459 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2460 import_components6.TextControl,
2461 {
2462 __next40pxDefaultSize: true,
2463 hideLabelFromVision: true,
2464 label: (0, import_i18n17.__)("LaTeX math syntax"),
2465 value: latex,
2466 onChange: handleLatexChange,
2467 placeholder: (0, import_i18n17.__)("e.g., x^2, \\frac{a}{b}"),
2468 autoComplete: "off",
2469 className: "block-editor-format-toolbar__math-input"
2470 }
2471 ),
2472 error && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
2473 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2474 WCBadge,
2475 {
2476 intent: "error",
2477 className: "wp-block-math__error",
2478 children: (0, import_i18n17.sprintf)(
2479 /* translators: %s: error message returned when parsing LaTeX. */
2480 (0, import_i18n17.__)("Error: %s"),
2481 error
2482 )
2483 }
2484 ),
2485 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("style", { children: ".wp-block-math__error .components-badge__content{white-space:normal}" })
2486 ] })
2487 ] }) })
2488 }
2489 );
2490 }
2491 function Edit4({
2492 value,
2493 onChange,
2494 onFocus,
2495 isObjectActive,
2496 activeObjectAttributes,
2497 contentRef
2498 }) {
2499 const [latexToMathML, setLatexToMathML] = (0, import_element10.useState)();
2500 (0, import_element10.useEffect)(() => {
2501 import("@wordpress/latex-to-mathml").then((module) => {
2502 setLatexToMathML(() => module.default);
2503 });
2504 }, []);
2505 return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(import_jsx_runtime30.Fragment, { children: [
2506 /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2507 import_block_editor16.RichTextToolbarButton,
2508 {
2509 icon: math_default,
2510 title: title14,
2511 onClick: () => {
2512 const newValue = (0, import_rich_text16.insertObject)(value, {
2513 type: name14,
2514 attributes: {
2515 "data-latex": ""
2516 },
2517 innerHTML: ""
2518 });
2519 newValue.start = newValue.end - 1;
2520 onChange(newValue);
2521 onFocus();
2522 },
2523 isActive: isObjectActive
2524 }
2525 ),
2526 isObjectActive && /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
2527 InlineUI2,
2528 {
2529 value,
2530 onChange,
2531 activeAttributes: activeObjectAttributes,
2532 contentRef,
2533 latexToMathML
2534 }
2535 )
2536 ] });
2537 }
2538 var math = {
2539 name: name14,
2540 title: title14,
2541 tagName: "math",
2542 className: null,
2543 attributes: {
2544 "data-latex": "data-latex"
2545 },
2546 contentEditable: false,
2547 edit: Edit4
2548 };
2549
2550 // packages/format-library/build-module/non-breaking-space/index.mjs
2551 var import_i18n18 = __toESM(require_i18n(), 1);
2552 var import_rich_text17 = __toESM(require_rich_text(), 1);
2553 var import_block_editor17 = __toESM(require_block_editor(), 1);
2554 var import_jsx_runtime31 = __toESM(require_jsx_runtime(), 1);
2555 var name15 = "core/non-breaking-space";
2556 var title15 = (0, import_i18n18.__)("Non breaking space");
2557 var nonBreakingSpace = {
2558 name: name15,
2559 title: title15,
2560 tagName: "nbsp",
2561 className: null,
2562 edit({ value, onChange }) {
2563 function addNonBreakingSpace() {
2564 onChange((0, import_rich_text17.insert)(value, "\xA0"));
2565 }
2566 return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
2567 import_block_editor17.RichTextShortcut,
2568 {
2569 type: "primaryShift",
2570 character: " ",
2571 onUse: addNonBreakingSpace
2572 }
2573 );
2574 }
2575 };
2576
2577 // packages/format-library/build-module/default-formats.mjs
2578 var default_formats_default = [
2579 bold,
2580 code,
2581 image,
2582 italic,
2583 link,
2584 strikethrough,
2585 underline,
2586 textColor,
2587 subscript,
2588 superscript,
2589 keyboard,
2590 unknown,
2591 language,
2592 math,
2593 nonBreakingSpace
2594 ];
2595
2596 // packages/format-library/build-module/index.mjs
2597 default_formats_default.forEach(
2598 ({ name: name16, ...settings }) => (0, import_rich_text18.registerFormatType)(name16, settings)
2599 );
2600 })();
2601 if(wp.formatLibrary&&typeof wp.formatLibrary==='object'){wp.formatLibrary=Object.assign({},wp.formatLibrary);}
2602 //# sourceMappingURL=index.js.map
2603