PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.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 16.2.0, at build/format-library/index.js

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