PluginProbe
Gutenberg / 21.7.0
Gutenberg v21.7.0
24.0.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 All 403 releases
gutenberg / build / format-library / index.js

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

2,023 lines 67.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 var __webpack_exports__ = {};
4
5 ;// external ["wp","richText"]
6 const external_wp_richText_namespaceObject = window["wp"]["richText"];
7 ;// external ["wp","i18n"]
8 const external_wp_i18n_namespaceObject = window["wp"]["i18n"];
9 ;// external ["wp","blockEditor"]
10 const external_wp_blockEditor_namespaceObject = window["wp"]["blockEditor"];
11 ;// external ["wp","primitives"]
12 const external_wp_primitives_namespaceObject = window["wp"]["primitives"];
13 ;// external "ReactJSXRuntime"
14 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
15 ;// ./packages/icons/build-module/library/format-bold.js
16 /**
17 * WordPress dependencies
18 */
19
20
21 const formatBold = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
22 xmlns: "http://www.w3.org/2000/svg",
23 viewBox: "0 0 24 24",
24 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
25 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"
26 })
27 });
28 /* harmony default export */ const format_bold = (formatBold);
29
30 ;// external ["wp","privateApis"]
31 const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
32 ;// ./packages/format-library/build-module/lock-unlock.js
33 /**
34 * WordPress dependencies
35 */
36
37 const {
38 lock,
39 unlock
40 } = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/format-library');
41
42 ;// ./packages/format-library/build-module/bold/index.js
43 /**
44 * WordPress dependencies
45 */
46
47
48
49
50
51 /**
52 * Internal dependencies
53 */
54
55
56 const {
57 essentialFormatKey
58 } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
59 const bold_name = 'core/bold';
60 const title = (0,external_wp_i18n_namespaceObject.__)('Bold');
61 const bold = {
62 name: bold_name,
63 title,
64 tagName: 'strong',
65 className: null,
66 [essentialFormatKey]: true,
67 edit({
68 isActive,
69 value,
70 onChange,
71 onFocus
72 }) {
73 function onToggle() {
74 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
75 type: bold_name,
76 title
77 }));
78 }
79 function onClick() {
80 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
81 type: bold_name
82 }));
83 onFocus();
84 }
85 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
86 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
87 type: "primary",
88 character: "b",
89 onUse: onToggle
90 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
91 name: "bold",
92 icon: format_bold,
93 title: title,
94 onClick: onClick,
95 isActive: isActive,
96 shortcutType: "primary",
97 shortcutCharacter: "b"
98 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__unstableRichTextInputEvent, {
99 inputType: "formatBold",
100 onInput: onToggle
101 })]
102 });
103 }
104 };
105
106 ;// ./packages/icons/build-module/library/code.js
107 /**
108 * WordPress dependencies
109 */
110
111
112 const code = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
113 viewBox: "0 0 24 24",
114 xmlns: "http://www.w3.org/2000/svg",
115 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
116 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"
117 })
118 });
119 /* harmony default export */ const library_code = (code);
120
121 ;// ./packages/format-library/build-module/code/index.js
122 /**
123 * WordPress dependencies
124 */
125
126
127
128
129
130 const code_name = 'core/code';
131 const code_title = (0,external_wp_i18n_namespaceObject.__)('Inline code');
132 const code_code = {
133 name: code_name,
134 title: code_title,
135 tagName: 'code',
136 className: null,
137 __unstableInputRule(value) {
138 const BACKTICK = '`';
139 const {
140 start,
141 text
142 } = value;
143 const characterBefore = text[start - 1];
144
145 // Quick check the text for the necessary character.
146 if (characterBefore !== BACKTICK) {
147 return value;
148 }
149 if (start - 2 < 0) {
150 return value;
151 }
152 const indexBefore = text.lastIndexOf(BACKTICK, start - 2);
153 if (indexBefore === -1) {
154 return value;
155 }
156 const startIndex = indexBefore;
157 const endIndex = start - 2;
158 if (startIndex === endIndex) {
159 return value;
160 }
161 value = (0,external_wp_richText_namespaceObject.remove)(value, startIndex, startIndex + 1);
162 value = (0,external_wp_richText_namespaceObject.remove)(value, endIndex, endIndex + 1);
163 value = (0,external_wp_richText_namespaceObject.applyFormat)(value, {
164 type: code_name
165 }, startIndex, endIndex);
166 return value;
167 },
168 edit({
169 value,
170 onChange,
171 onFocus,
172 isActive
173 }) {
174 function onClick() {
175 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
176 type: code_name,
177 title: code_title
178 }));
179 onFocus();
180 }
181 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
182 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
183 type: "access",
184 character: "x",
185 onUse: onClick
186 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
187 icon: library_code,
188 title: code_title,
189 onClick: onClick,
190 isActive: isActive,
191 role: "menuitemcheckbox"
192 })]
193 });
194 }
195 };
196
197 ;// external ["wp","components"]
198 const external_wp_components_namespaceObject = window["wp"]["components"];
199 ;// external ["wp","element"]
200 const external_wp_element_namespaceObject = window["wp"]["element"];
201 ;// ./packages/format-library/build-module/image/index.js
202 /**
203 * WordPress dependencies
204 */
205
206
207
208
209
210
211 const ALLOWED_MEDIA_TYPES = ['image'];
212 const image_name = 'core/image';
213 const image_title = (0,external_wp_i18n_namespaceObject.__)('Inline image');
214
215 /**
216 * Extracts the image ID from the className attribute.
217 *
218 * @param {Object} activeObjectAttributes The attributes of the active object.
219 * @return {number|undefined} The extracted image ID or undefined if not found.
220 */
221 function getCurrentImageId(activeObjectAttributes) {
222 var _activeObjectAttribut;
223 if (!activeObjectAttributes?.className) {
224 return undefined;
225 }
226 const [, id] = (_activeObjectAttribut = activeObjectAttributes.className.match(/wp-image-(\d+)/)) !== null && _activeObjectAttribut !== void 0 ? _activeObjectAttribut : [];
227 return id ? parseInt(id, 10) : undefined;
228 }
229 const image_image = {
230 name: image_name,
231 title: image_title,
232 keywords: [(0,external_wp_i18n_namespaceObject.__)('photo'), (0,external_wp_i18n_namespaceObject.__)('media')],
233 object: true,
234 tagName: 'img',
235 className: null,
236 attributes: {
237 className: 'class',
238 style: 'style',
239 url: 'src',
240 alt: 'alt'
241 },
242 edit: Edit
243 };
244 function InlineUI({
245 value,
246 onChange,
247 activeObjectAttributes,
248 contentRef
249 }) {
250 const {
251 style,
252 alt
253 } = activeObjectAttributes;
254 const width = style?.replace(/\D/g, '');
255 const [editedWidth, setEditedWidth] = (0,external_wp_element_namespaceObject.useState)(width);
256 const [editedAlt, setEditedAlt] = (0,external_wp_element_namespaceObject.useState)(alt);
257 const hasChanged = editedWidth !== width || editedAlt !== alt;
258 const popoverAnchor = (0,external_wp_richText_namespaceObject.useAnchor)({
259 editableContentElement: contentRef.current,
260 settings: image_image
261 });
262 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
263 placement: "bottom",
264 focusOnMount: false,
265 anchor: popoverAnchor,
266 className: "block-editor-format-toolbar__image-popover",
267 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("form", {
268 className: "block-editor-format-toolbar__image-container-content",
269 onSubmit: event => {
270 const newReplacements = value.replacements.slice();
271 newReplacements[value.start] = {
272 type: image_name,
273 attributes: {
274 ...activeObjectAttributes,
275 style: editedWidth ? `width: ${editedWidth}px;` : '',
276 alt: editedAlt
277 }
278 };
279 onChange({
280 ...value,
281 replacements: newReplacements
282 });
283 event.preventDefault();
284 },
285 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalVStack, {
286 spacing: 4,
287 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.__experimentalNumberControl, {
288 __next40pxDefaultSize: true,
289 label: (0,external_wp_i18n_namespaceObject.__)('Width'),
290 value: editedWidth,
291 min: 1,
292 onChange: newWidth => {
293 setEditedWidth(newWidth);
294 }
295 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.TextareaControl, {
296 label: (0,external_wp_i18n_namespaceObject.__)('Alternative text'),
297 __nextHasNoMarginBottom: true,
298 value: editedAlt,
299 onChange: newAlt => {
300 setEditedAlt(newAlt);
301 },
302 help: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
303 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.ExternalLink, {
304 href:
305 // translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations.
306 (0,external_wp_i18n_namespaceObject.__)('https://www.w3.org/WAI/tutorials/images/decision-tree/'),
307 children: (0,external_wp_i18n_namespaceObject.__)('Describe the purpose of the image.')
308 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("br", {}), (0,external_wp_i18n_namespaceObject.__)('Leave empty if decorative.')]
309 })
310 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.__experimentalHStack, {
311 justify: "right",
312 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
313 disabled: !hasChanged,
314 accessibleWhenDisabled: true,
315 variant: "primary",
316 type: "submit",
317 size: "compact",
318 children: (0,external_wp_i18n_namespaceObject.__)('Apply')
319 })
320 })]
321 })
322 })
323 });
324 }
325 function Edit({
326 value,
327 onChange,
328 onFocus,
329 isObjectActive,
330 activeObjectAttributes,
331 contentRef
332 }) {
333 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_blockEditor_namespaceObject.MediaUploadCheck, {
334 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.MediaUpload, {
335 allowedTypes: ALLOWED_MEDIA_TYPES,
336 value: getCurrentImageId(activeObjectAttributes),
337 onSelect: ({
338 id,
339 url,
340 alt,
341 width: imgWidth
342 }) => {
343 onChange((0,external_wp_richText_namespaceObject.insertObject)(value, {
344 type: image_name,
345 attributes: {
346 className: `wp-image-${id}`,
347 style: `width: ${Math.min(imgWidth, 150)}px;`,
348 url,
349 alt
350 }
351 }));
352 onFocus();
353 },
354 render: ({
355 open
356 }) => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
357 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.SVG, {
358 xmlns: "http://www.w3.org/2000/svg",
359 viewBox: "0 0 24 24",
360 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Path, {
361 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"
362 })
363 }),
364 title: isObjectActive ? (0,external_wp_i18n_namespaceObject.__)('Replace image') : image_title,
365 onClick: open,
366 isActive: isObjectActive
367 })
368 }), isObjectActive && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InlineUI, {
369 value: value,
370 onChange: onChange,
371 activeObjectAttributes: activeObjectAttributes,
372 contentRef: contentRef
373 })]
374 });
375 }
376
377 ;// ./packages/icons/build-module/library/format-italic.js
378 /**
379 * WordPress dependencies
380 */
381
382
383 const formatItalic = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
384 xmlns: "http://www.w3.org/2000/svg",
385 viewBox: "0 0 24 24",
386 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
387 d: "M12.5 5L10 19h1.9l2.5-14z"
388 })
389 });
390 /* harmony default export */ const format_italic = (formatItalic);
391
392 ;// ./packages/format-library/build-module/italic/index.js
393 /**
394 * WordPress dependencies
395 */
396
397
398
399
400
401 /**
402 * Internal dependencies
403 */
404
405
406 const {
407 essentialFormatKey: italic_essentialFormatKey
408 } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
409 const italic_name = 'core/italic';
410 const italic_title = (0,external_wp_i18n_namespaceObject.__)('Italic');
411 const italic = {
412 name: italic_name,
413 title: italic_title,
414 tagName: 'em',
415 className: null,
416 [italic_essentialFormatKey]: true,
417 edit({
418 isActive,
419 value,
420 onChange,
421 onFocus
422 }) {
423 function onToggle() {
424 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
425 type: italic_name,
426 title: italic_title
427 }));
428 }
429 function onClick() {
430 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
431 type: italic_name
432 }));
433 onFocus();
434 }
435 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
436 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
437 type: "primary",
438 character: "i",
439 onUse: onToggle
440 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
441 name: "italic",
442 icon: format_italic,
443 title: italic_title,
444 onClick: onClick,
445 isActive: isActive,
446 shortcutType: "primary",
447 shortcutCharacter: "i"
448 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__unstableRichTextInputEvent, {
449 inputType: "formatItalic",
450 onInput: onToggle
451 })]
452 });
453 }
454 };
455
456 ;// external ["wp","url"]
457 const external_wp_url_namespaceObject = window["wp"]["url"];
458 ;// external ["wp","htmlEntities"]
459 const external_wp_htmlEntities_namespaceObject = window["wp"]["htmlEntities"];
460 ;// ./packages/icons/build-module/library/link.js
461 /**
462 * WordPress dependencies
463 */
464
465
466 const link_link = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
467 xmlns: "http://www.w3.org/2000/svg",
468 viewBox: "0 0 24 24",
469 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
470 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"
471 })
472 });
473 /* harmony default export */ const library_link = (link_link);
474
475 ;// external ["wp","a11y"]
476 const external_wp_a11y_namespaceObject = window["wp"]["a11y"];
477 ;// external ["wp","data"]
478 const external_wp_data_namespaceObject = window["wp"]["data"];
479 ;// ./packages/format-library/build-module/link/utils.js
480 /**
481 * WordPress dependencies
482 */
483
484
485 /**
486 * Check for issues with the provided href.
487 *
488 * @param {string} href The href.
489 *
490 * @return {boolean} Is the href invalid?
491 */
492 function isValidHref(href) {
493 if (!href) {
494 return false;
495 }
496 const trimmedHref = href.trim();
497 if (!trimmedHref) {
498 return false;
499 }
500
501 // Does the href start with something that looks like a URL protocol?
502 if (/^\S+:/.test(trimmedHref)) {
503 const protocol = (0,external_wp_url_namespaceObject.getProtocol)(trimmedHref);
504 if (!(0,external_wp_url_namespaceObject.isValidProtocol)(protocol)) {
505 return false;
506 }
507
508 // Add some extra checks for http(s) URIs, since these are the most common use-case.
509 // This ensures URIs with an http protocol have exactly two forward slashes following the protocol.
510 if (protocol.startsWith('http') && !/^https?:\/\/[^\/\s]/i.test(trimmedHref)) {
511 return false;
512 }
513 const authority = (0,external_wp_url_namespaceObject.getAuthority)(trimmedHref);
514 if (!(0,external_wp_url_namespaceObject.isValidAuthority)(authority)) {
515 return false;
516 }
517 const path = (0,external_wp_url_namespaceObject.getPath)(trimmedHref);
518 if (path && !(0,external_wp_url_namespaceObject.isValidPath)(path)) {
519 return false;
520 }
521 const queryString = (0,external_wp_url_namespaceObject.getQueryString)(trimmedHref);
522 if (queryString && !(0,external_wp_url_namespaceObject.isValidQueryString)(queryString)) {
523 return false;
524 }
525 const fragment = (0,external_wp_url_namespaceObject.getFragment)(trimmedHref);
526 if (fragment && !(0,external_wp_url_namespaceObject.isValidFragment)(fragment)) {
527 return false;
528 }
529 }
530
531 // Validate anchor links.
532 if (trimmedHref.startsWith('#') && !(0,external_wp_url_namespaceObject.isValidFragment)(trimmedHref)) {
533 return false;
534 }
535 return true;
536 }
537
538 /**
539 * Generates the format object that will be applied to the link text.
540 *
541 * @param {Object} options
542 * @param {string} options.url The href of the link.
543 * @param {string} options.type The type of the link.
544 * @param {string} options.id The ID of the link.
545 * @param {boolean} options.opensInNewWindow Whether this link will open in a new window.
546 * @param {boolean} options.nofollow Whether this link is marked as no follow relationship.
547 * @return {Object} The final format object.
548 */
549 function createLinkFormat({
550 url,
551 type,
552 id,
553 opensInNewWindow,
554 nofollow
555 }) {
556 const format = {
557 type: 'core/link',
558 attributes: {
559 url
560 }
561 };
562 if (type) {
563 format.attributes.type = type;
564 }
565 if (id) {
566 format.attributes.id = id;
567 }
568 if (opensInNewWindow) {
569 format.attributes.target = '_blank';
570 format.attributes.rel = format.attributes.rel ? format.attributes.rel + ' noreferrer noopener' : 'noreferrer noopener';
571 }
572 if (nofollow) {
573 format.attributes.rel = format.attributes.rel ? format.attributes.rel + ' nofollow' : 'nofollow';
574 }
575 return format;
576 }
577
578 /* eslint-disable jsdoc/no-undefined-types */
579 /**
580 * Get the start and end boundaries of a given format from a rich text value.
581 *
582 *
583 * @param {RichTextValue} value the rich text value to interrogate.
584 * @param {string} format the identifier for the target format (e.g. `core/link`, `core/bold`).
585 * @param {number?} startIndex optional startIndex to seek from.
586 * @param {number?} endIndex optional endIndex to seek from.
587 * @return {Object} object containing start and end values for the given format.
588 */
589 /* eslint-enable jsdoc/no-undefined-types */
590 function getFormatBoundary(value, format, startIndex = value.start, endIndex = value.end) {
591 const EMPTY_BOUNDARIES = {
592 start: null,
593 end: null
594 };
595 const {
596 formats
597 } = value;
598 let targetFormat;
599 let initialIndex;
600 if (!formats?.length) {
601 return EMPTY_BOUNDARIES;
602 }
603
604 // Clone formats to avoid modifying source formats.
605 const newFormats = formats.slice();
606 const formatAtStart = newFormats[startIndex]?.find(({
607 type
608 }) => type === format.type);
609 const formatAtEnd = newFormats[endIndex]?.find(({
610 type
611 }) => type === format.type);
612 const formatAtEndMinusOne = newFormats[endIndex - 1]?.find(({
613 type
614 }) => type === format.type);
615 if (!!formatAtStart) {
616 // Set values to conform to "start"
617 targetFormat = formatAtStart;
618 initialIndex = startIndex;
619 } else if (!!formatAtEnd) {
620 // Set values to conform to "end"
621 targetFormat = formatAtEnd;
622 initialIndex = endIndex;
623 } else if (!!formatAtEndMinusOne) {
624 // This is an edge case which will occur if you create a format, then place
625 // the caret just before the format and hit the back ARROW key. The resulting
626 // value object will have start and end +1 beyond the edge of the format boundary.
627 targetFormat = formatAtEndMinusOne;
628 initialIndex = endIndex - 1;
629 } else {
630 return EMPTY_BOUNDARIES;
631 }
632 const index = newFormats[initialIndex].indexOf(targetFormat);
633 const walkingArgs = [newFormats, initialIndex, targetFormat, index];
634
635 // Walk the startIndex "backwards" to the leading "edge" of the matching format.
636 startIndex = walkToStart(...walkingArgs);
637
638 // Walk the endIndex "forwards" until the trailing "edge" of the matching format.
639 endIndex = walkToEnd(...walkingArgs);
640
641 // Safe guard: start index cannot be less than 0.
642 startIndex = startIndex < 0 ? 0 : startIndex;
643
644 // // Return the indices of the "edges" as the boundaries.
645 return {
646 start: startIndex,
647 end: endIndex
648 };
649 }
650
651 /**
652 * Walks forwards/backwards towards the boundary of a given format within an
653 * array of format objects. Returns the index of the boundary.
654 *
655 * @param {Array} formats the formats to search for the given format type.
656 * @param {number} initialIndex the starting index from which to walk.
657 * @param {Object} targetFormatRef a reference to the format type object being sought.
658 * @param {number} formatIndex the index at which we expect the target format object to be.
659 * @param {string} direction either 'forwards' or 'backwards' to indicate the direction.
660 * @return {number} the index of the boundary of the given format.
661 */
662 function walkToBoundary(formats, initialIndex, targetFormatRef, formatIndex, direction) {
663 let index = initialIndex;
664 const directions = {
665 forwards: 1,
666 backwards: -1
667 };
668 const directionIncrement = directions[direction] || 1; // invalid direction arg default to forwards
669 const inverseDirectionIncrement = directionIncrement * -1;
670 while (formats[index] && formats[index][formatIndex] === targetFormatRef) {
671 // Increment/decrement in the direction of operation.
672 index = index + directionIncrement;
673 }
674
675 // Restore by one in inverse direction of operation
676 // to avoid out of bounds.
677 index = index + inverseDirectionIncrement;
678 return index;
679 }
680 const partialRight = (fn, ...partialArgs) => (...args) => fn(...args, ...partialArgs);
681 const walkToStart = partialRight(walkToBoundary, 'backwards');
682 const walkToEnd = partialRight(walkToBoundary, 'forwards');
683
684 ;// ./packages/format-library/build-module/link/inline.js
685 /**
686 * WordPress dependencies
687 */
688
689
690
691
692
693
694
695
696
697 /**
698 * Internal dependencies
699 */
700
701
702
703 const LINK_SETTINGS = [...external_wp_blockEditor_namespaceObject.LinkControl.DEFAULT_LINK_SETTINGS, {
704 id: 'nofollow',
705 title: (0,external_wp_i18n_namespaceObject.__)('Mark as nofollow')
706 }];
707 function InlineLinkUI({
708 isActive,
709 activeAttributes,
710 value,
711 onChange,
712 onFocusOutside,
713 stopAddingLink,
714 contentRef,
715 focusOnMount
716 }) {
717 const richLinkTextValue = getRichTextValueFromSelection(value, isActive);
718
719 // Get the text content minus any HTML tags.
720 const richTextText = richLinkTextValue.text;
721 const {
722 selectionChange
723 } = (0,external_wp_data_namespaceObject.useDispatch)(external_wp_blockEditor_namespaceObject.store);
724 const {
725 createPageEntity,
726 userCanCreatePages,
727 selectionStart
728 } = (0,external_wp_data_namespaceObject.useSelect)(select => {
729 const {
730 getSettings,
731 getSelectionStart
732 } = select(external_wp_blockEditor_namespaceObject.store);
733 const _settings = getSettings();
734 return {
735 createPageEntity: _settings.__experimentalCreatePageEntity,
736 userCanCreatePages: _settings.__experimentalUserCanCreatePages,
737 selectionStart: getSelectionStart()
738 };
739 }, []);
740 const linkValue = (0,external_wp_element_namespaceObject.useMemo)(() => ({
741 url: activeAttributes.url,
742 type: activeAttributes.type,
743 id: activeAttributes.id,
744 opensInNewTab: activeAttributes.target === '_blank',
745 nofollow: activeAttributes.rel?.includes('nofollow'),
746 title: richTextText
747 }), [activeAttributes.id, activeAttributes.rel, activeAttributes.target, activeAttributes.type, activeAttributes.url, richTextText]);
748 function removeLink() {
749 const newValue = (0,external_wp_richText_namespaceObject.removeFormat)(value, 'core/link');
750 onChange(newValue);
751 stopAddingLink();
752 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Link removed.'), 'assertive');
753 }
754 function onChangeLink(nextValue) {
755 const hasLink = linkValue?.url;
756 const isNewLink = !hasLink;
757
758 // Merge the next value with the current link value.
759 nextValue = {
760 ...linkValue,
761 ...nextValue
762 };
763 const newUrl = (0,external_wp_url_namespaceObject.prependHTTP)(nextValue.url);
764 const linkFormat = createLinkFormat({
765 url: newUrl,
766 type: nextValue.type,
767 id: nextValue.id !== undefined && nextValue.id !== null ? String(nextValue.id) : undefined,
768 opensInNewWindow: nextValue.opensInNewTab,
769 nofollow: nextValue.nofollow
770 });
771 const newText = nextValue.title || newUrl;
772
773 // Scenario: we have any active text selection or an active format.
774 let newValue;
775 if ((0,external_wp_richText_namespaceObject.isCollapsed)(value) && !isActive) {
776 // Scenario: we don't have any actively selected text or formats.
777 const inserted = (0,external_wp_richText_namespaceObject.insert)(value, newText);
778 newValue = (0,external_wp_richText_namespaceObject.applyFormat)(inserted, linkFormat, value.start, value.start + newText.length);
779 onChange(newValue);
780
781 // Close the Link UI.
782 stopAddingLink();
783
784 // Move the selection to the end of the inserted link outside of the format boundary
785 // so the user can continue typing after the link.
786 selectionChange({
787 clientId: selectionStart.clientId,
788 identifier: selectionStart.attributeKey,
789 start: value.start + newText.length + 1
790 });
791 return;
792 } else if (newText === richTextText) {
793 newValue = (0,external_wp_richText_namespaceObject.applyFormat)(value, linkFormat);
794 } else {
795 // Scenario: Editing an existing link.
796
797 // Create new RichText value for the new text in order that we
798 // can apply formats to it.
799 newValue = (0,external_wp_richText_namespaceObject.create)({
800 text: newText
801 });
802 // Apply the new Link format to this new text value.
803 newValue = (0,external_wp_richText_namespaceObject.applyFormat)(newValue, linkFormat, 0, newText.length);
804
805 // Get the boundaries of the active link format.
806 const boundary = getFormatBoundary(value, {
807 type: 'core/link'
808 });
809
810 // Split the value at the start of the active link format.
811 // Passing "start" as the 3rd parameter is required to ensure
812 // the second half of the split value is split at the format's
813 // start boundary and avoids relying on the value's "end" property
814 // which may not correspond correctly.
815 const [valBefore, valAfter] = (0,external_wp_richText_namespaceObject.split)(value, boundary.start, boundary.start);
816
817 // Update the original (full) RichTextValue replacing the
818 // target text with the *new* RichTextValue containing:
819 // 1. The new text content.
820 // 2. The new link format.
821 // As "replace" will operate on the first match only, it is
822 // run only against the second half of the value which was
823 // split at the active format's boundary. This avoids a bug
824 // with incorrectly targeted replacements.
825 // See: https://github.com/WordPress/gutenberg/issues/41771.
826 // Note original formats will be lost when applying this change.
827 // That is expected behaviour.
828 // See: https://github.com/WordPress/gutenberg/pull/33849#issuecomment-936134179.
829 const newValAfter = (0,external_wp_richText_namespaceObject.replace)(valAfter, richTextText, newValue);
830 newValue = (0,external_wp_richText_namespaceObject.concat)(valBefore, newValAfter);
831 }
832 onChange(newValue);
833
834 // Focus should only be returned to the rich text on submit if this link is not
835 // being created for the first time. If it is then focus should remain within the
836 // Link UI because it should remain open for the user to modify the link they have
837 // just created.
838 if (!isNewLink) {
839 stopAddingLink();
840 }
841 if (!isValidHref(newUrl)) {
842 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Warning: the link has been inserted but may have errors. Please test it.'), 'assertive');
843 } else if (isActive) {
844 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Link edited.'), 'assertive');
845 } else {
846 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Link inserted.'), 'assertive');
847 }
848 }
849 const popoverAnchor = (0,external_wp_richText_namespaceObject.useAnchor)({
850 editableContentElement: contentRef.current,
851 settings: {
852 ...build_module_link_link,
853 isActive
854 }
855 });
856 async function handleCreate(pageTitle) {
857 const page = await createPageEntity({
858 title: pageTitle,
859 status: 'draft'
860 });
861 return {
862 id: page.id,
863 type: page.type,
864 title: page.title.rendered,
865 url: page.link,
866 kind: 'post-type'
867 };
868 }
869 function createButtonText(searchTerm) {
870 return (0,external_wp_element_namespaceObject.createInterpolateElement)((0,external_wp_i18n_namespaceObject.sprintf)(/* translators: %s: search term. */
871 (0,external_wp_i18n_namespaceObject.__)('Create page: <mark>%s</mark>'), searchTerm), {
872 mark: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("mark", {})
873 });
874 }
875 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
876 anchor: popoverAnchor,
877 animate: false,
878 onClose: stopAddingLink,
879 onFocusOutside: onFocusOutside,
880 placement: "bottom",
881 offset: 8,
882 shift: true,
883 focusOnMount: focusOnMount,
884 constrainTabbing: true,
885 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.LinkControl, {
886 value: linkValue,
887 onChange: onChangeLink,
888 onRemove: removeLink,
889 hasRichPreviews: true,
890 createSuggestion: createPageEntity && handleCreate,
891 withCreateSuggestion: userCanCreatePages,
892 createSuggestionButtonText: createButtonText,
893 hasTextControl: true,
894 settings: LINK_SETTINGS,
895 showInitialSuggestions: true,
896 suggestionsQuery: {
897 // always show Pages as initial suggestions
898 initialSuggestionsSearchOptions: {
899 type: 'post',
900 subtype: 'page',
901 perPage: 20
902 }
903 }
904 })
905 });
906 }
907 function getRichTextValueFromSelection(value, isActive) {
908 // Default to the selection ranges on the RichTextValue object.
909 let textStart = value.start;
910 let textEnd = value.end;
911
912 // If the format is currently active then the rich text value
913 // should always be taken from the bounds of the active format
914 // and not the selected text.
915 if (isActive) {
916 const boundary = getFormatBoundary(value, {
917 type: 'core/link'
918 });
919 textStart = boundary.start;
920
921 // Text *selection* always extends +1 beyond the edge of the format.
922 // We account for that here.
923 textEnd = boundary.end + 1;
924 }
925
926 // Get a RichTextValue containing the selected text content.
927 return (0,external_wp_richText_namespaceObject.slice)(value, textStart, textEnd);
928 }
929 /* harmony default export */ const inline = (InlineLinkUI);
930
931 ;// ./packages/format-library/build-module/link/index.js
932 /**
933 * WordPress dependencies
934 */
935
936
937
938
939
940
941
942
943
944 /**
945 * Internal dependencies
946 */
947
948
949
950
951 const {
952 essentialFormatKey: link_essentialFormatKey
953 } = unlock(external_wp_blockEditor_namespaceObject.privateApis);
954 const link_name = 'core/link';
955 const link_title = (0,external_wp_i18n_namespaceObject.__)('Link');
956 function link_Edit({
957 isActive,
958 activeAttributes,
959 value,
960 onChange,
961 onFocus,
962 contentRef
963 }) {
964 const [addingLink, setAddingLink] = (0,external_wp_element_namespaceObject.useState)(false);
965
966 // We only need to store the button element that opened the popover. We can ignore the other states, as they will be handled by the onFocus prop to return to the rich text field.
967 const [openedBy, setOpenedBy] = (0,external_wp_element_namespaceObject.useState)(null);
968 (0,external_wp_element_namespaceObject.useEffect)(() => {
969 // When the link becomes inactive (i.e. isActive is false), reset the editingLink state
970 // and the creatingLink state. This means that if the Link UI is displayed and the link
971 // becomes inactive (e.g. used arrow keys to move cursor outside of link bounds), the UI will close.
972 if (!isActive) {
973 setAddingLink(false);
974 }
975 }, [isActive]);
976 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
977 const editableContentElement = contentRef.current;
978 if (!editableContentElement) {
979 return;
980 }
981 function handleClick(event) {
982 // There is a situation whereby there is an existing link in the rich text
983 // and the user clicks on the leftmost edge of that link and fails to activate
984 // the link format, but the click event still fires on the `<a>` element.
985 // This causes the `editingLink` state to be set to `true` and the link UI
986 // to be rendered in "creating" mode. We need to check isActive to see if
987 // we have an active link format.
988 const link = event.target.closest('[contenteditable] a');
989 if (!link ||
990 // other formats (e.g. bold) may be nested within the link.
991 !isActive) {
992 return;
993 }
994 setAddingLink(true);
995 setOpenedBy({
996 el: link,
997 action: 'click'
998 });
999 }
1000 editableContentElement.addEventListener('click', handleClick);
1001 return () => {
1002 editableContentElement.removeEventListener('click', handleClick);
1003 };
1004 }, [contentRef, isActive]);
1005 function addLink(target) {
1006 const text = (0,external_wp_richText_namespaceObject.getTextContent)((0,external_wp_richText_namespaceObject.slice)(value));
1007 if (!isActive && text && (0,external_wp_url_namespaceObject.isURL)(text) && isValidHref(text)) {
1008 onChange((0,external_wp_richText_namespaceObject.applyFormat)(value, {
1009 type: link_name,
1010 attributes: {
1011 url: text
1012 }
1013 }));
1014 } else if (!isActive && text && (0,external_wp_url_namespaceObject.isEmail)(text)) {
1015 onChange((0,external_wp_richText_namespaceObject.applyFormat)(value, {
1016 type: link_name,
1017 attributes: {
1018 url: `mailto:${text}`
1019 }
1020 }));
1021 } else if (!isActive && text && (0,external_wp_url_namespaceObject.isPhoneNumber)(text)) {
1022 onChange((0,external_wp_richText_namespaceObject.applyFormat)(value, {
1023 type: link_name,
1024 attributes: {
1025 url: `tel:${text.replace(/\D/g, '')}`
1026 }
1027 }));
1028 } else {
1029 if (target) {
1030 setOpenedBy({
1031 el: target,
1032 action: null // We don't need to distinguish between click or keyboard here
1033 });
1034 }
1035 setAddingLink(true);
1036 }
1037 }
1038
1039 /**
1040 * Runs when the popover is closed via escape keypress, unlinking the selected text,
1041 * but _not_ on a click outside the popover. onFocusOutside handles that.
1042 */
1043 function stopAddingLink() {
1044 // Don't let the click handler on the toolbar button trigger again.
1045
1046 // There are two places for us to return focus to on Escape keypress:
1047 // 1. The rich text field.
1048 // 2. The toolbar button.
1049
1050 // The toolbar button is the only one we need to handle returning focus to.
1051 // Otherwise, we rely on the passed in onFocus to return focus to the rich text field.
1052
1053 // Close the popover
1054 setAddingLink(false);
1055
1056 // Return focus to the toolbar button or the rich text field
1057 if (openedBy?.el?.tagName === 'BUTTON') {
1058 openedBy.el.focus();
1059 } else {
1060 onFocus();
1061 }
1062 // Remove the openedBy state
1063 setOpenedBy(null);
1064 }
1065
1066 // Test for this:
1067 // 1. Click on the link button
1068 // 2. Click the Options button in the top right of header
1069 // 3. Focus should be in the dropdown of the Options button
1070 // 4. Press Escape
1071 // 5. Focus should be on the Options button
1072 function onFocusOutside() {
1073 setAddingLink(false);
1074 setOpenedBy(null);
1075 }
1076 function onRemoveFormat() {
1077 onChange((0,external_wp_richText_namespaceObject.removeFormat)(value, link_name));
1078 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.__)('Link removed.'), 'assertive');
1079 }
1080
1081 // Only autofocus if we have clicked a link within the editor
1082 const shouldAutoFocus = !(openedBy?.el?.tagName === 'A' && openedBy?.action === 'click');
1083 const hasSelection = !(0,external_wp_richText_namespaceObject.isCollapsed)(value);
1084 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1085 children: [hasSelection && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
1086 type: "primary",
1087 character: "k",
1088 onUse: addLink
1089 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
1090 type: "primaryShift",
1091 character: "k",
1092 onUse: onRemoveFormat
1093 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1094 name: "link",
1095 icon: library_link,
1096 title: isActive ? (0,external_wp_i18n_namespaceObject.__)('Link') : link_title,
1097 onClick: event => {
1098 addLink(event.currentTarget);
1099 },
1100 isActive: isActive || addingLink,
1101 shortcutType: "primary",
1102 shortcutCharacter: "k",
1103 "aria-haspopup": "true",
1104 "aria-expanded": addingLink
1105 }), addingLink && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(inline, {
1106 stopAddingLink: stopAddingLink,
1107 onFocusOutside: onFocusOutside,
1108 isActive: isActive,
1109 activeAttributes: activeAttributes,
1110 value: value,
1111 onChange: onChange,
1112 contentRef: contentRef,
1113 focusOnMount: shouldAutoFocus ? 'firstElement' : false
1114 })]
1115 });
1116 }
1117 const build_module_link_link = {
1118 name: link_name,
1119 title: link_title,
1120 tagName: 'a',
1121 className: null,
1122 attributes: {
1123 url: 'href',
1124 type: 'data-type',
1125 id: 'data-id',
1126 _id: 'id',
1127 target: 'target',
1128 rel: 'rel'
1129 },
1130 [link_essentialFormatKey]: true,
1131 __unstablePasteRule(value, {
1132 html,
1133 plainText
1134 }) {
1135 const pastedText = (html || plainText).replace(/<[^>]+>/g, '').trim();
1136
1137 // A URL was pasted, turn the selection into a link.
1138 // For the link pasting feature, allow only http(s) protocols.
1139 if (!(0,external_wp_url_namespaceObject.isURL)(pastedText) || !/^https?:/.test(pastedText)) {
1140 return value;
1141 }
1142
1143 // Allows us to ask for this information when we get a report.
1144 window.console.log('Created link:\n\n', pastedText);
1145 const format = {
1146 type: link_name,
1147 attributes: {
1148 url: (0,external_wp_htmlEntities_namespaceObject.decodeEntities)(pastedText)
1149 }
1150 };
1151 if ((0,external_wp_richText_namespaceObject.isCollapsed)(value)) {
1152 return (0,external_wp_richText_namespaceObject.insert)(value, (0,external_wp_richText_namespaceObject.applyFormat)((0,external_wp_richText_namespaceObject.create)({
1153 text: plainText
1154 }), format, 0, plainText.length));
1155 }
1156 return (0,external_wp_richText_namespaceObject.applyFormat)(value, format);
1157 },
1158 edit: link_Edit
1159 };
1160
1161 ;// ./packages/icons/build-module/library/format-strikethrough.js
1162 /**
1163 * WordPress dependencies
1164 */
1165
1166
1167 const formatStrikethrough = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1168 xmlns: "http://www.w3.org/2000/svg",
1169 viewBox: "0 0 24 24",
1170 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1171 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"
1172 })
1173 });
1174 /* harmony default export */ const format_strikethrough = (formatStrikethrough);
1175
1176 ;// ./packages/format-library/build-module/strikethrough/index.js
1177 /**
1178 * WordPress dependencies
1179 */
1180
1181
1182
1183
1184
1185 const strikethrough_name = 'core/strikethrough';
1186 const strikethrough_title = (0,external_wp_i18n_namespaceObject.__)('Strikethrough');
1187 const strikethrough = {
1188 name: strikethrough_name,
1189 title: strikethrough_title,
1190 tagName: 's',
1191 className: null,
1192 edit({
1193 isActive,
1194 value,
1195 onChange,
1196 onFocus
1197 }) {
1198 function onClick() {
1199 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
1200 type: strikethrough_name,
1201 title: strikethrough_title
1202 }));
1203 onFocus();
1204 }
1205 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1206 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
1207 type: "access",
1208 character: "d",
1209 onUse: onClick
1210 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1211 icon: format_strikethrough,
1212 title: strikethrough_title,
1213 onClick: onClick,
1214 isActive: isActive,
1215 role: "menuitemcheckbox"
1216 })]
1217 });
1218 }
1219 };
1220
1221 ;// ./packages/format-library/build-module/underline/index.js
1222 /**
1223 * WordPress dependencies
1224 */
1225
1226
1227
1228
1229 const underline_name = 'core/underline';
1230 const underline_title = (0,external_wp_i18n_namespaceObject.__)('Underline');
1231 const underline = {
1232 name: underline_name,
1233 title: underline_title,
1234 tagName: 'span',
1235 className: null,
1236 attributes: {
1237 style: 'style'
1238 },
1239 edit({
1240 value,
1241 onChange
1242 }) {
1243 const onToggle = () => {
1244 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
1245 type: underline_name,
1246 attributes: {
1247 style: 'text-decoration: underline;'
1248 },
1249 title: underline_title
1250 }));
1251 };
1252 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1253 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
1254 type: "primary",
1255 character: "u",
1256 onUse: onToggle
1257 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.__unstableRichTextInputEvent, {
1258 inputType: "formatUnderline",
1259 onInput: onToggle
1260 })]
1261 });
1262 }
1263 };
1264
1265 ;// ./packages/icons/build-module/icon/index.js
1266 /**
1267 * WordPress dependencies
1268 */
1269
1270
1271 /**
1272 * External dependencies
1273 */
1274
1275 /**
1276 * Return an SVG icon.
1277 *
1278 * @param props The component props.
1279 *
1280 * @return Icon component
1281 */
1282 /* harmony default export */ const icon = ((0,external_wp_element_namespaceObject.forwardRef)(({
1283 icon,
1284 size = 24,
1285 ...props
1286 }, ref) => {
1287 return (0,external_wp_element_namespaceObject.cloneElement)(icon, {
1288 width: size,
1289 height: size,
1290 ...props,
1291 ref
1292 });
1293 }));
1294
1295 ;// ./packages/icons/build-module/library/text-color.js
1296 /**
1297 * WordPress dependencies
1298 */
1299
1300
1301 const textColor = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1302 xmlns: "http://www.w3.org/2000/svg",
1303 viewBox: "0 0 24 24",
1304 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1305 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"
1306 })
1307 });
1308 /* harmony default export */ const text_color = (textColor);
1309
1310 ;// ./packages/icons/build-module/library/color.js
1311 /**
1312 * WordPress dependencies
1313 */
1314
1315
1316 const color = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1317 viewBox: "0 0 24 24",
1318 xmlns: "http://www.w3.org/2000/svg",
1319 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1320 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"
1321 })
1322 });
1323 /* harmony default export */ const library_color = (color);
1324
1325 ;// ./packages/format-library/build-module/text-color/inline.js
1326 /**
1327 * WordPress dependencies
1328 */
1329
1330
1331
1332
1333
1334
1335
1336 /**
1337 * Internal dependencies
1338 */
1339
1340
1341
1342 const {
1343 Tabs
1344 } = unlock(external_wp_components_namespaceObject.privateApis);
1345 const TABS = [{
1346 name: 'color',
1347 title: (0,external_wp_i18n_namespaceObject.__)('Text')
1348 }, {
1349 name: 'backgroundColor',
1350 title: (0,external_wp_i18n_namespaceObject.__)('Background')
1351 }];
1352 function parseCSS(css = '') {
1353 return css.split(';').reduce((accumulator, rule) => {
1354 if (rule) {
1355 const [property, value] = rule.split(':');
1356 if (property === 'color') {
1357 accumulator.color = value;
1358 }
1359 if (property === 'background-color' && value !== transparentValue) {
1360 accumulator.backgroundColor = value;
1361 }
1362 }
1363 return accumulator;
1364 }, {});
1365 }
1366 function parseClassName(className = '', colorSettings) {
1367 return className.split(' ').reduce((accumulator, name) => {
1368 // `colorSlug` could contain dashes, so simply match the start and end.
1369 if (name.startsWith('has-') && name.endsWith('-color')) {
1370 const colorSlug = name.replace(/^has-/, '').replace(/-color$/, '');
1371 const colorObject = (0,external_wp_blockEditor_namespaceObject.getColorObjectByAttributeValues)(colorSettings, colorSlug);
1372 accumulator.color = colorObject.color;
1373 }
1374 return accumulator;
1375 }, {});
1376 }
1377 function getActiveColors(value, name, colorSettings) {
1378 const activeColorFormat = (0,external_wp_richText_namespaceObject.getActiveFormat)(value, name);
1379 if (!activeColorFormat) {
1380 return {};
1381 }
1382 return {
1383 ...parseCSS(activeColorFormat.attributes.style),
1384 ...parseClassName(activeColorFormat.attributes.class, colorSettings)
1385 };
1386 }
1387 function setColors(value, name, colorSettings, colors) {
1388 const {
1389 color,
1390 backgroundColor
1391 } = {
1392 ...getActiveColors(value, name, colorSettings),
1393 ...colors
1394 };
1395 if (!color && !backgroundColor) {
1396 return (0,external_wp_richText_namespaceObject.removeFormat)(value, name);
1397 }
1398 const styles = [];
1399 const classNames = [];
1400 const attributes = {};
1401 if (backgroundColor) {
1402 styles.push(['background-color', backgroundColor].join(':'));
1403 } else {
1404 // Override default browser color for mark element.
1405 styles.push(['background-color', transparentValue].join(':'));
1406 }
1407 if (color) {
1408 const colorObject = (0,external_wp_blockEditor_namespaceObject.getColorObjectByColorValue)(colorSettings, color);
1409 if (colorObject) {
1410 classNames.push((0,external_wp_blockEditor_namespaceObject.getColorClassName)('color', colorObject.slug));
1411 } else {
1412 styles.push(['color', color].join(':'));
1413 }
1414 }
1415 if (styles.length) {
1416 attributes.style = styles.join(';');
1417 }
1418 if (classNames.length) {
1419 attributes.class = classNames.join(' ');
1420 }
1421 return (0,external_wp_richText_namespaceObject.applyFormat)(value, {
1422 type: name,
1423 attributes
1424 });
1425 }
1426 function ColorPicker({
1427 name,
1428 property,
1429 value,
1430 onChange
1431 }) {
1432 const colors = (0,external_wp_data_namespaceObject.useSelect)(select => {
1433 var _getSettings$colors;
1434 const {
1435 getSettings
1436 } = select(external_wp_blockEditor_namespaceObject.store);
1437 return (_getSettings$colors = getSettings().colors) !== null && _getSettings$colors !== void 0 ? _getSettings$colors : [];
1438 }, []);
1439 const activeColors = (0,external_wp_element_namespaceObject.useMemo)(() => getActiveColors(value, name, colors), [name, value, colors]);
1440 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.ColorPalette, {
1441 value: activeColors[property],
1442 onChange: color => {
1443 onChange(setColors(value, name, colors, {
1444 [property]: color
1445 }));
1446 },
1447 enableAlpha: true
1448 // Prevent the text and color picker from overlapping.
1449 ,
1450 __experimentalIsRenderedInSidebar: true
1451 });
1452 }
1453 function InlineColorUI({
1454 name,
1455 value,
1456 onChange,
1457 onClose,
1458 contentRef,
1459 isActive
1460 }) {
1461 const popoverAnchor = (0,external_wp_richText_namespaceObject.useAnchor)({
1462 editableContentElement: contentRef.current,
1463 settings: {
1464 ...text_color_textColor,
1465 isActive
1466 }
1467 });
1468 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
1469 onClose: onClose,
1470 className: "format-library__inline-color-popover",
1471 anchor: popoverAnchor,
1472 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(Tabs, {
1473 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Tabs.TabList, {
1474 children: TABS.map(tab => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Tabs.Tab, {
1475 tabId: tab.name,
1476 children: tab.title
1477 }, tab.name))
1478 }), TABS.map(tab => /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Tabs.TabPanel, {
1479 tabId: tab.name,
1480 focusable: false,
1481 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ColorPicker, {
1482 name: name,
1483 property: tab.name,
1484 value: value,
1485 onChange: onChange
1486 })
1487 }, tab.name))]
1488 })
1489 });
1490 }
1491
1492 ;// ./packages/format-library/build-module/text-color/index.js
1493 /**
1494 * WordPress dependencies
1495 */
1496
1497
1498
1499
1500
1501
1502 /**
1503 * Internal dependencies
1504 */
1505
1506
1507 const transparentValue = 'rgba(0, 0, 0, 0)';
1508 const text_color_name = 'core/text-color';
1509 const text_color_title = (0,external_wp_i18n_namespaceObject.__)('Highlight');
1510 const EMPTY_ARRAY = [];
1511 function getComputedStyleProperty(element, property) {
1512 const {
1513 ownerDocument
1514 } = element;
1515 const {
1516 defaultView
1517 } = ownerDocument;
1518 const style = defaultView.getComputedStyle(element);
1519 const value = style.getPropertyValue(property);
1520 if (property === 'background-color' && value === transparentValue && element.parentElement) {
1521 return getComputedStyleProperty(element.parentElement, property);
1522 }
1523 return value;
1524 }
1525 function fillComputedColors(element, {
1526 color,
1527 backgroundColor
1528 }) {
1529 if (!color && !backgroundColor) {
1530 return;
1531 }
1532 return {
1533 color: color || getComputedStyleProperty(element, 'color'),
1534 backgroundColor: backgroundColor === transparentValue ? getComputedStyleProperty(element, 'background-color') : backgroundColor
1535 };
1536 }
1537 function TextColorEdit({
1538 value,
1539 onChange,
1540 isActive,
1541 activeAttributes,
1542 contentRef
1543 }) {
1544 const [allowCustomControl, colors = EMPTY_ARRAY] = (0,external_wp_blockEditor_namespaceObject.useSettings)('color.custom', 'color.palette');
1545 const [isAddingColor, setIsAddingColor] = (0,external_wp_element_namespaceObject.useState)(false);
1546 const colorIndicatorStyle = (0,external_wp_element_namespaceObject.useMemo)(() => fillComputedColors(contentRef.current, getActiveColors(value, text_color_name, colors)), [contentRef, value, colors]);
1547 const hasColorsToChoose = !!colors.length || allowCustomControl;
1548 if (!hasColorsToChoose && !isActive) {
1549 return null;
1550 }
1551 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1552 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1553 className: "format-library-text-color-button",
1554 isActive: isActive,
1555 icon: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(icon, {
1556 icon: Object.keys(activeAttributes).length ? text_color : library_color,
1557 style: colorIndicatorStyle
1558 }),
1559 title: text_color_title
1560 // If has no colors to choose but a color is active remove the color onClick.
1561 ,
1562 onClick: hasColorsToChoose ? () => setIsAddingColor(true) : () => onChange((0,external_wp_richText_namespaceObject.removeFormat)(value, text_color_name)),
1563 role: "menuitemcheckbox"
1564 }), isAddingColor && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InlineColorUI, {
1565 name: text_color_name,
1566 onClose: () => setIsAddingColor(false),
1567 activeAttributes: activeAttributes,
1568 value: value,
1569 onChange: onChange,
1570 contentRef: contentRef,
1571 isActive: isActive
1572 })]
1573 });
1574 }
1575 const text_color_textColor = {
1576 name: text_color_name,
1577 title: text_color_title,
1578 tagName: 'mark',
1579 className: 'has-inline-color',
1580 attributes: {
1581 style: 'style',
1582 class: 'class'
1583 },
1584 edit: TextColorEdit
1585 };
1586
1587 ;// ./packages/icons/build-module/library/subscript.js
1588 /**
1589 * WordPress dependencies
1590 */
1591
1592
1593 const subscript = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1594 xmlns: "http://www.w3.org/2000/svg",
1595 viewBox: "0 0 24 24",
1596 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1597 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"
1598 })
1599 });
1600 /* harmony default export */ const library_subscript = (subscript);
1601
1602 ;// ./packages/format-library/build-module/subscript/index.js
1603 /**
1604 * WordPress dependencies
1605 */
1606
1607
1608
1609
1610
1611 const subscript_name = 'core/subscript';
1612 const subscript_title = (0,external_wp_i18n_namespaceObject.__)('Subscript');
1613 const subscript_subscript = {
1614 name: subscript_name,
1615 title: subscript_title,
1616 tagName: 'sub',
1617 className: null,
1618 edit({
1619 isActive,
1620 value,
1621 onChange,
1622 onFocus
1623 }) {
1624 function onToggle() {
1625 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
1626 type: subscript_name,
1627 title: subscript_title
1628 }));
1629 }
1630 function onClick() {
1631 onToggle();
1632 onFocus();
1633 }
1634 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1635 icon: library_subscript,
1636 title: subscript_title,
1637 onClick: onClick,
1638 isActive: isActive,
1639 role: "menuitemcheckbox"
1640 });
1641 }
1642 };
1643
1644 ;// ./packages/icons/build-module/library/superscript.js
1645 /**
1646 * WordPress dependencies
1647 */
1648
1649
1650 const superscript = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1651 xmlns: "http://www.w3.org/2000/svg",
1652 viewBox: "0 0 24 24",
1653 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1654 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"
1655 })
1656 });
1657 /* harmony default export */ const library_superscript = (superscript);
1658
1659 ;// ./packages/format-library/build-module/superscript/index.js
1660 /**
1661 * WordPress dependencies
1662 */
1663
1664
1665
1666
1667
1668 const superscript_name = 'core/superscript';
1669 const superscript_title = (0,external_wp_i18n_namespaceObject.__)('Superscript');
1670 const superscript_superscript = {
1671 name: superscript_name,
1672 title: superscript_title,
1673 tagName: 'sup',
1674 className: null,
1675 edit({
1676 isActive,
1677 value,
1678 onChange,
1679 onFocus
1680 }) {
1681 function onToggle() {
1682 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
1683 type: superscript_name,
1684 title: superscript_title
1685 }));
1686 }
1687 function onClick() {
1688 onToggle();
1689 onFocus();
1690 }
1691 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1692 icon: library_superscript,
1693 title: superscript_title,
1694 onClick: onClick,
1695 isActive: isActive,
1696 role: "menuitemcheckbox"
1697 });
1698 }
1699 };
1700
1701 ;// ./packages/icons/build-module/library/button.js
1702 /**
1703 * WordPress dependencies
1704 */
1705
1706
1707 const button_button = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1708 viewBox: "0 0 24 24",
1709 xmlns: "http://www.w3.org/2000/svg",
1710 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1711 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"
1712 })
1713 });
1714 /* harmony default export */ const library_button = (button_button);
1715
1716 ;// ./packages/format-library/build-module/keyboard/index.js
1717 /**
1718 * WordPress dependencies
1719 */
1720
1721
1722
1723
1724
1725 const keyboard_name = 'core/keyboard';
1726 const keyboard_title = (0,external_wp_i18n_namespaceObject.__)('Keyboard input');
1727 const keyboard = {
1728 name: keyboard_name,
1729 title: keyboard_title,
1730 tagName: 'kbd',
1731 className: null,
1732 edit({
1733 isActive,
1734 value,
1735 onChange,
1736 onFocus
1737 }) {
1738 function onToggle() {
1739 onChange((0,external_wp_richText_namespaceObject.toggleFormat)(value, {
1740 type: keyboard_name,
1741 title: keyboard_title
1742 }));
1743 }
1744 function onClick() {
1745 onToggle();
1746 onFocus();
1747 }
1748 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1749 icon: library_button,
1750 title: keyboard_title,
1751 onClick: onClick,
1752 isActive: isActive,
1753 role: "menuitemcheckbox"
1754 });
1755 }
1756 };
1757
1758 ;// ./packages/icons/build-module/library/help.js
1759 /**
1760 * WordPress dependencies
1761 */
1762
1763
1764 const help = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1765 xmlns: "http://www.w3.org/2000/svg",
1766 viewBox: "0 0 24 24",
1767 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1768 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"
1769 })
1770 });
1771 /* harmony default export */ const library_help = (help);
1772
1773 ;// ./packages/format-library/build-module/unknown/index.js
1774 /**
1775 * WordPress dependencies
1776 */
1777
1778
1779
1780
1781
1782 const unknown_name = 'core/unknown';
1783 const unknown_title = (0,external_wp_i18n_namespaceObject.__)('Clear Unknown Formatting');
1784 function selectionContainsUnknownFormats(value) {
1785 if ((0,external_wp_richText_namespaceObject.isCollapsed)(value)) {
1786 return false;
1787 }
1788 const selectedValue = (0,external_wp_richText_namespaceObject.slice)(value);
1789 return selectedValue.formats.some(formats => {
1790 return formats.some(format => format.type === unknown_name);
1791 });
1792 }
1793 const unknown = {
1794 name: unknown_name,
1795 title: unknown_title,
1796 tagName: '*',
1797 className: null,
1798 edit({
1799 isActive,
1800 value,
1801 onChange,
1802 onFocus
1803 }) {
1804 if (!isActive && !selectionContainsUnknownFormats(value)) {
1805 return null;
1806 }
1807 function onClick() {
1808 onChange((0,external_wp_richText_namespaceObject.removeFormat)(value, unknown_name));
1809 onFocus();
1810 }
1811 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1812 name: "unknown",
1813 icon: library_help,
1814 title: unknown_title,
1815 onClick: onClick,
1816 isActive: true
1817 });
1818 }
1819 };
1820
1821 ;// ./packages/icons/build-module/library/language.js
1822 /**
1823 * WordPress dependencies
1824 */
1825
1826
1827 const language = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.SVG, {
1828 xmlns: "http://www.w3.org/2000/svg",
1829 viewBox: "0 0 24 24",
1830 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_primitives_namespaceObject.Path, {
1831 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"
1832 })
1833 });
1834 /* harmony default export */ const library_language = (language);
1835
1836 ;// ./packages/format-library/build-module/language/index.js
1837 /**
1838 * WordPress dependencies
1839 */
1840
1841
1842 /**
1843 * WordPress dependencies
1844 */
1845
1846
1847
1848
1849
1850
1851 const language_name = 'core/language';
1852 const language_title = (0,external_wp_i18n_namespaceObject.__)('Language');
1853 const language_language = {
1854 name: language_name,
1855 tagName: 'bdo',
1856 className: null,
1857 edit: language_Edit,
1858 title: language_title
1859 };
1860 function language_Edit({
1861 isActive,
1862 value,
1863 onChange,
1864 contentRef
1865 }) {
1866 const [isPopoverVisible, setIsPopoverVisible] = (0,external_wp_element_namespaceObject.useState)(false);
1867 const togglePopover = () => {
1868 setIsPopoverVisible(state => !state);
1869 };
1870 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_ReactJSXRuntime_namespaceObject.Fragment, {
1871 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextToolbarButton, {
1872 icon: library_language,
1873 label: language_title,
1874 title: language_title,
1875 onClick: () => {
1876 if (isActive) {
1877 onChange((0,external_wp_richText_namespaceObject.removeFormat)(value, language_name));
1878 } else {
1879 togglePopover();
1880 }
1881 },
1882 isActive: isActive,
1883 role: "menuitemcheckbox"
1884 }), isPopoverVisible && /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(InlineLanguageUI, {
1885 value: value,
1886 onChange: onChange,
1887 onClose: togglePopover,
1888 contentRef: contentRef
1889 })]
1890 });
1891 }
1892 function InlineLanguageUI({
1893 value,
1894 contentRef,
1895 onChange,
1896 onClose
1897 }) {
1898 const popoverAnchor = (0,external_wp_richText_namespaceObject.useAnchor)({
1899 editableContentElement: contentRef.current,
1900 settings: language_language
1901 });
1902 const [lang, setLang] = (0,external_wp_element_namespaceObject.useState)('');
1903 const [dir, setDir] = (0,external_wp_element_namespaceObject.useState)('ltr');
1904 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Popover, {
1905 className: "block-editor-format-toolbar__language-popover",
1906 anchor: popoverAnchor,
1907 onClose: onClose,
1908 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsxs)(external_wp_components_namespaceObject.__experimentalVStack, {
1909 as: "form",
1910 spacing: 4,
1911 className: "block-editor-format-toolbar__language-container-content",
1912 onSubmit: event => {
1913 event.preventDefault();
1914 onChange((0,external_wp_richText_namespaceObject.applyFormat)(value, {
1915 type: language_name,
1916 attributes: {
1917 lang,
1918 dir
1919 }
1920 }));
1921 onClose();
1922 },
1923 children: [/*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.TextControl, {
1924 __next40pxDefaultSize: true,
1925 __nextHasNoMarginBottom: true,
1926 label: language_title,
1927 value: lang,
1928 onChange: val => setLang(val),
1929 help: (0,external_wp_i18n_namespaceObject.__)('A valid language attribute, like "en" or "fr".')
1930 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.SelectControl, {
1931 __next40pxDefaultSize: true,
1932 __nextHasNoMarginBottom: true,
1933 label: (0,external_wp_i18n_namespaceObject.__)('Text direction'),
1934 value: dir,
1935 options: [{
1936 label: (0,external_wp_i18n_namespaceObject.__)('Left to right'),
1937 value: 'ltr'
1938 }, {
1939 label: (0,external_wp_i18n_namespaceObject.__)('Right to left'),
1940 value: 'rtl'
1941 }],
1942 onChange: val => setDir(val)
1943 }), /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.__experimentalHStack, {
1944 alignment: "right",
1945 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_components_namespaceObject.Button, {
1946 __next40pxDefaultSize: true,
1947 variant: "primary",
1948 type: "submit",
1949 text: (0,external_wp_i18n_namespaceObject.__)('Apply')
1950 })
1951 })]
1952 })
1953 });
1954 }
1955
1956 ;// ./packages/format-library/build-module/non-breaking-space/index.js
1957 /**
1958 * WordPress dependencies
1959 */
1960
1961
1962
1963
1964 const non_breaking_space_name = 'core/non-breaking-space';
1965 const non_breaking_space_title = (0,external_wp_i18n_namespaceObject.__)('Non breaking space');
1966 const nonBreakingSpace = {
1967 name: non_breaking_space_name,
1968 title: non_breaking_space_title,
1969 tagName: 'nbsp',
1970 className: null,
1971 edit({
1972 value,
1973 onChange
1974 }) {
1975 function addNonBreakingSpace() {
1976 onChange((0,external_wp_richText_namespaceObject.insert)(value, '\u00a0'));
1977 }
1978 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(external_wp_blockEditor_namespaceObject.RichTextShortcut, {
1979 type: "primaryShift",
1980 character: " ",
1981 onUse: addNonBreakingSpace
1982 });
1983 }
1984 };
1985
1986 ;// ./packages/format-library/build-module/default-formats.js
1987 /**
1988 * Internal dependencies
1989 */
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004 /* harmony default export */ const default_formats = ([bold, code_code, image_image, italic, build_module_link_link, strikethrough, underline, text_color_textColor, subscript_subscript, superscript_superscript, keyboard, unknown, language_language, nonBreakingSpace]);
2005
2006 ;// ./packages/format-library/build-module/index.js
2007 /**
2008 * WordPress dependencies
2009 */
2010
2011
2012 /**
2013 * Internal dependencies
2014 */
2015
2016 default_formats.forEach(({
2017 name,
2018 ...settings
2019 }) => (0,external_wp_richText_namespaceObject.registerFormatType)(name, settings));
2020
2021 (window.wp = window.wp || {}).formatLibrary = __webpack_exports__;
2022 /******/ })()
2023 ;