changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
21:48c4eec2b7e6 | 22:8c2e4d02f4ef |
---|---|
98 __webpack_require__.d(actions_namespaceObject, { |
98 __webpack_require__.d(actions_namespaceObject, { |
99 addFormatTypes: () => (addFormatTypes), |
99 addFormatTypes: () => (addFormatTypes), |
100 removeFormatTypes: () => (removeFormatTypes) |
100 removeFormatTypes: () => (removeFormatTypes) |
101 }); |
101 }); |
102 |
102 |
103 ;// CONCATENATED MODULE: external ["wp","data"] |
103 ;// external ["wp","data"] |
104 const external_wp_data_namespaceObject = window["wp"]["data"]; |
104 const external_wp_data_namespaceObject = window["wp"]["data"]; |
105 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/reducer.js |
105 ;// ./node_modules/@wordpress/rich-text/build-module/store/reducer.js |
106 /** |
106 /** |
107 * WordPress dependencies |
107 * WordPress dependencies |
108 */ |
108 */ |
109 |
109 |
110 |
110 |
134 } |
134 } |
135 /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ |
135 /* harmony default export */ const reducer = ((0,external_wp_data_namespaceObject.combineReducers)({ |
136 formatTypes |
136 formatTypes |
137 })); |
137 })); |
138 |
138 |
139 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/selectors.js |
139 ;// ./node_modules/@wordpress/rich-text/build-module/store/selectors.js |
140 /** |
140 /** |
141 * WordPress dependencies |
141 * WordPress dependencies |
142 */ |
142 */ |
143 |
143 |
144 |
144 |
209 * __( 'Not Found' ) |
209 * __( 'Not Found' ) |
210 * ; |
210 * ; |
211 * }; |
211 * }; |
212 * ``` |
212 * ``` |
213 * |
213 * |
214 * @return {Object?} Format type. |
214 * @return {?Object} Format type. |
215 */ |
215 */ |
216 function getFormatType(state, name) { |
216 function getFormatType(state, name) { |
217 return state.formatTypes[name]; |
217 return state.formatTypes[name]; |
218 } |
218 } |
219 |
219 |
296 } |
296 } |
297 return ` ${elementClassName} `.indexOf(` ${className} `) >= 0; |
297 return ` ${elementClassName} `.indexOf(` ${className} `) >= 0; |
298 }); |
298 }); |
299 } |
299 } |
300 |
300 |
301 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/actions.js |
301 ;// ./node_modules/@wordpress/rich-text/build-module/store/actions.js |
302 /** |
302 /** |
303 * Returns an action object used in signalling that format types have been |
303 * Returns an action object used in signalling that format types have been |
304 * added. |
304 * added. |
305 * Ignored from documentation as registerFormatType should be used instead from @wordpress/rich-text |
305 * Ignored from documentation as registerFormatType should be used instead from @wordpress/rich-text |
306 * |
306 * |
333 type: 'REMOVE_FORMAT_TYPES', |
333 type: 'REMOVE_FORMAT_TYPES', |
334 names: Array.isArray(names) ? names : [names] |
334 names: Array.isArray(names) ? names : [names] |
335 }; |
335 }; |
336 } |
336 } |
337 |
337 |
338 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/store/index.js |
338 ;// ./node_modules/@wordpress/rich-text/build-module/store/index.js |
339 /** |
339 /** |
340 * WordPress dependencies |
340 * WordPress dependencies |
341 */ |
341 */ |
342 |
342 |
343 |
343 |
361 selectors: selectors_namespaceObject, |
361 selectors: selectors_namespaceObject, |
362 actions: actions_namespaceObject |
362 actions: actions_namespaceObject |
363 }); |
363 }); |
364 (0,external_wp_data_namespaceObject.register)(store); |
364 (0,external_wp_data_namespaceObject.register)(store); |
365 |
365 |
366 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js |
366 ;// ./node_modules/@wordpress/rich-text/build-module/is-format-equal.js |
367 /** @typedef {import('./types').RichTextFormat} RichTextFormat */ |
367 /** @typedef {import('./types').RichTextFormat} RichTextFormat */ |
368 |
368 |
369 /** |
369 /** |
370 * Optimised equality check for format objects. |
370 * Optimised equality check for format objects. |
371 * |
371 * |
414 } |
414 } |
415 } |
415 } |
416 return true; |
416 return true; |
417 } |
417 } |
418 |
418 |
419 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js |
419 ;// ./node_modules/@wordpress/rich-text/build-module/normalise-formats.js |
420 /** |
420 /** |
421 * Internal dependencies |
421 * Internal dependencies |
422 */ |
422 */ |
423 |
423 |
424 |
424 |
452 ...value, |
452 ...value, |
453 formats: newFormats |
453 formats: newFormats |
454 }; |
454 }; |
455 } |
455 } |
456 |
456 |
457 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/apply-format.js |
457 ;// ./node_modules/@wordpress/rich-text/build-module/apply-format.js |
458 /** |
458 /** |
459 * Internal dependencies |
459 * Internal dependencies |
460 */ |
460 */ |
461 |
461 |
462 |
462 |
540 type |
540 type |
541 }) => type !== format.type) || []), format] |
541 }) => type !== format.type) || []), format] |
542 }); |
542 }); |
543 } |
543 } |
544 |
544 |
545 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create-element.js |
545 ;// ./node_modules/@wordpress/rich-text/build-module/create-element.js |
546 /** |
546 /** |
547 * Parse the given HTML into a body element. |
547 * Parse the given HTML into a body element. |
548 * |
548 * |
549 * Note: The current implementation will return a shared reference, reset on |
549 * Note: The current implementation will return a shared reference, reset on |
550 * each call to `createElement`. Therefore, you should not hold a reference to |
550 * each call to `createElement`. Therefore, you should not hold a reference to |
567 } |
567 } |
568 createElement.body.innerHTML = html; |
568 createElement.body.innerHTML = html; |
569 return createElement.body; |
569 return createElement.body; |
570 } |
570 } |
571 |
571 |
572 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/special-characters.js |
572 ;// ./node_modules/@wordpress/rich-text/build-module/special-characters.js |
573 /** |
573 /** |
574 * Object replacement character, used as a placeholder for objects. |
574 * Object replacement character, used as a placeholder for objects. |
575 */ |
575 */ |
576 const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; |
576 const OBJECT_REPLACEMENT_CHARACTER = '\ufffc'; |
577 |
577 |
579 * Zero width non-breaking space, used as padding in the editable DOM tree when |
579 * Zero width non-breaking space, used as padding in the editable DOM tree when |
580 * it is empty otherwise. |
580 * it is empty otherwise. |
581 */ |
581 */ |
582 const ZWNBSP = '\ufeff'; |
582 const ZWNBSP = '\ufeff'; |
583 |
583 |
584 ;// CONCATENATED MODULE: external ["wp","escapeHtml"] |
584 ;// external ["wp","escapeHtml"] |
585 const external_wp_escapeHtml_namespaceObject = window["wp"]["escapeHtml"]; |
585 const external_wp_escapeHtml_namespaceObject = window["wp"]["escapeHtml"]; |
586 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js |
586 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-formats.js |
587 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
587 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
588 /** @typedef {import('./types').RichTextFormatList} RichTextFormatList */ |
588 /** @typedef {import('./types').RichTextFormatList} RichTextFormatList */ |
589 |
589 |
590 /** |
590 /** |
591 * Internal dependencies |
591 * Internal dependencies |
665 } |
665 } |
666 } |
666 } |
667 return _activeFormats || EMPTY_ACTIVE_FORMATS; |
667 return _activeFormats || EMPTY_ACTIVE_FORMATS; |
668 } |
668 } |
669 |
669 |
670 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-format-type.js |
670 ;// ./node_modules/@wordpress/rich-text/build-module/get-format-type.js |
671 /** |
671 /** |
672 * WordPress dependencies |
672 * WordPress dependencies |
673 */ |
673 */ |
674 |
674 |
675 /** |
675 /** |
688 */ |
688 */ |
689 function get_format_type_getFormatType(name) { |
689 function get_format_type_getFormatType(name) { |
690 return (0,external_wp_data_namespaceObject.select)(store).getFormatType(name); |
690 return (0,external_wp_data_namespaceObject.select)(store).getFormatType(name); |
691 } |
691 } |
692 |
692 |
693 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-tree.js |
693 ;// ./node_modules/@wordpress/rich-text/build-module/to-tree.js |
694 /** |
694 /** |
695 * Internal dependencies |
695 * Internal dependencies |
696 */ |
696 */ |
697 |
697 |
698 |
698 |
894 type, |
894 type, |
895 attributes, |
895 attributes, |
896 innerHTML |
896 innerHTML |
897 } = replacement; |
897 } = replacement; |
898 const formatType = get_format_type_getFormatType(type); |
898 const formatType = get_format_type_getFormatType(type); |
899 if (!isEditableTree && type === 'script') { |
899 if (isEditableTree && type === '#comment') { |
900 pointer = append(getParent(pointer), { |
|
901 type: 'span', |
|
902 attributes: { |
|
903 contenteditable: 'false', |
|
904 'data-rich-text-comment': attributes['data-rich-text-comment'] |
|
905 } |
|
906 }); |
|
907 append(append(pointer, { |
|
908 type: 'span' |
|
909 }), attributes['data-rich-text-comment'].trim()); |
|
910 } else if (!isEditableTree && type === 'script') { |
|
900 pointer = append(getParent(pointer), fromFormat({ |
911 pointer = append(getParent(pointer), fromFormat({ |
901 type: 'script', |
912 type: 'script', |
902 isEditableTree |
913 isEditableTree |
903 })); |
914 })); |
904 append(pointer, { |
915 append(pointer, { |
946 if (onEndIndex && end === i + 1) { |
957 if (onEndIndex && end === i + 1) { |
947 onEndIndex(tree, pointer); |
958 onEndIndex(tree, pointer); |
948 } |
959 } |
949 if (shouldInsertPadding && i === text.length) { |
960 if (shouldInsertPadding && i === text.length) { |
950 append(getParent(pointer), ZWNBSP); |
961 append(getParent(pointer), ZWNBSP); |
962 |
|
963 // We CANNOT use CSS to add a placeholder with pseudo elements on |
|
964 // the main block wrappers because that could clash with theme CSS. |
|
951 if (placeholder && text.length === 0) { |
965 if (placeholder && text.length === 0) { |
952 append(getParent(pointer), { |
966 append(getParent(pointer), { |
953 type: 'span', |
967 type: 'span', |
954 attributes: { |
968 attributes: { |
955 'data-rich-text-placeholder': placeholder, |
969 'data-rich-text-placeholder': placeholder, |
964 lastCharacter = character; |
978 lastCharacter = character; |
965 } |
979 } |
966 return tree; |
980 return tree; |
967 } |
981 } |
968 |
982 |
969 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-html-string.js |
983 ;// ./node_modules/@wordpress/rich-text/build-module/to-html-string.js |
970 /** |
984 /** |
971 * WordPress dependencies |
985 * WordPress dependencies |
972 */ |
986 */ |
973 |
987 |
974 |
988 |
982 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
996 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
983 |
997 |
984 /** |
998 /** |
985 * Create an HTML string from a Rich Text value. |
999 * Create an HTML string from a Rich Text value. |
986 * |
1000 * |
987 * @param {Object} $1 Named argements. |
1001 * @param {Object} $1 Named arguments. |
988 * @param {RichTextValue} $1.value Rich text value. |
1002 * @param {RichTextValue} $1.value Rich text value. |
989 * @param {boolean} [$1.preserveWhiteSpace] Preserves newlines if true. |
1003 * @param {boolean} [$1.preserveWhiteSpace] Preserves newlines if true. |
990 * |
1004 * |
991 * @return {string} HTML string. |
1005 * @return {string} HTML string. |
992 */ |
1006 */ |
1056 type, |
1070 type, |
1057 attributes, |
1071 attributes, |
1058 object, |
1072 object, |
1059 children |
1073 children |
1060 }) { |
1074 }) { |
1075 if (type === '#comment') { |
|
1076 // We can't restore the original comment delimiters, because once parsed |
|
1077 // into DOM nodes, we don't have the information. But in the future we |
|
1078 // could allow comment handlers to specify custom delimiters, for |
|
1079 // example `</{comment-content}>` for Bits, where `comment-content` |
|
1080 // would be `/{bit-name}` or `__{translatable-string}` (TBD). |
|
1081 return `<!--${attributes['data-rich-text-comment']}-->`; |
|
1082 } |
|
1061 let attributeString = ''; |
1083 let attributeString = ''; |
1062 for (const key in attributes) { |
1084 for (const key in attributes) { |
1063 if (!(0,external_wp_escapeHtml_namespaceObject.isValidAttributeName)(key)) { |
1085 if (!(0,external_wp_escapeHtml_namespaceObject.isValidAttributeName)(key)) { |
1064 continue; |
1086 continue; |
1065 } |
1087 } |
1077 } |
1099 } |
1078 return child.text === undefined ? createElementHTML(child) : (0,external_wp_escapeHtml_namespaceObject.escapeEditableHTML)(child.text); |
1100 return child.text === undefined ? createElementHTML(child) : (0,external_wp_escapeHtml_namespaceObject.escapeEditableHTML)(child.text); |
1079 }).join(''); |
1101 }).join(''); |
1080 } |
1102 } |
1081 |
1103 |
1082 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-text-content.js |
1104 ;// ./node_modules/@wordpress/rich-text/build-module/get-text-content.js |
1083 /** |
1105 /** |
1084 * Internal dependencies |
1106 * Internal dependencies |
1085 */ |
1107 */ |
1086 |
1108 |
1087 |
1109 |
1099 text |
1121 text |
1100 }) { |
1122 }) { |
1101 return text.replace(OBJECT_REPLACEMENT_CHARACTER, ''); |
1123 return text.replace(OBJECT_REPLACEMENT_CHARACTER, ''); |
1102 } |
1124 } |
1103 |
1125 |
1104 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/create.js |
1126 ;// ./node_modules/@wordpress/rich-text/build-module/create.js |
1105 /** |
1127 /** |
1106 * WordPress dependencies |
1128 * WordPress dependencies |
1107 */ |
1129 */ |
1108 |
1130 |
1109 |
1131 |
1221 static fromHTMLString(html) { |
1243 static fromHTMLString(html) { |
1222 return new RichTextData(create({ |
1244 return new RichTextData(create({ |
1223 html |
1245 html |
1224 })); |
1246 })); |
1225 } |
1247 } |
1248 /** |
|
1249 * Create a RichTextData instance from an HTML element. |
|
1250 * |
|
1251 * @param {HTMLElement} htmlElement The HTML element to create the instance from. |
|
1252 * @param {{preserveWhiteSpace?: boolean}} options Options. |
|
1253 * @return {RichTextData} The RichTextData instance. |
|
1254 */ |
|
1226 static fromHTMLElement(htmlElement, options = {}) { |
1255 static fromHTMLElement(htmlElement, options = {}) { |
1227 const { |
1256 const { |
1228 preserveWhiteSpace = false |
1257 preserveWhiteSpace = false |
1229 } = options; |
1258 } = options; |
1230 const element = preserveWhiteSpace ? htmlElement : collapseWhiteSpace(htmlElement); |
1259 const element = preserveWhiteSpace ? htmlElement : collapseWhiteSpace(htmlElement); |
1242 toPlainText() { |
1271 toPlainText() { |
1243 return getTextContent(this.#value); |
1272 return getTextContent(this.#value); |
1244 } |
1273 } |
1245 // We could expose `toHTMLElement` at some point as well, but we'd only use |
1274 // We could expose `toHTMLElement` at some point as well, but we'd only use |
1246 // it internally. |
1275 // it internally. |
1276 /** |
|
1277 * Convert the rich text value to an HTML string. |
|
1278 * |
|
1279 * @param {{preserveWhiteSpace?: boolean}} options Options. |
|
1280 * @return {string} The HTML string. |
|
1281 */ |
|
1247 toHTMLString({ |
1282 toHTMLString({ |
1248 preserveWhiteSpace |
1283 preserveWhiteSpace |
1249 } = {}) { |
1284 } = {}) { |
1250 return this.originalHTML || toHTMLString({ |
1285 return this.originalHTML || toHTMLString({ |
1251 value: this.#value, |
1286 value: this.#value, |
1512 } |
1547 } |
1513 |
1548 |
1514 /** |
1549 /** |
1515 * Creates a Rich Text value from a DOM element and range. |
1550 * Creates a Rich Text value from a DOM element and range. |
1516 * |
1551 * |
1517 * @param {Object} $1 Named argements. |
1552 * @param {Object} $1 Named arguments. |
1518 * @param {Element} [$1.element] Element to create value from. |
1553 * @param {Element} [$1.element] Element to create value from. |
1519 * @param {Range} [$1.range] Range to create value from. |
1554 * @param {Range} [$1.range] Range to create value from. |
1520 * @param {boolean} [$1.isEditableTree] |
1555 * @param {boolean} [$1.isEditableTree] |
1521 * |
1556 * |
1522 * @return {RichTextValue} A rich text value. |
1557 * @return {RichTextValue} A rich text value. |
1549 // Create a sparse array of the same length as `text`, in which |
1584 // Create a sparse array of the same length as `text`, in which |
1550 // formats can be added. |
1585 // formats can be added. |
1551 accumulator.formats.length += text.length; |
1586 accumulator.formats.length += text.length; |
1552 accumulator.replacements.length += text.length; |
1587 accumulator.replacements.length += text.length; |
1553 accumulator.text += text; |
1588 accumulator.text += text; |
1589 continue; |
|
1590 } |
|
1591 if (node.nodeType === node.COMMENT_NODE || node.nodeType === node.ELEMENT_NODE && node.tagName === 'SPAN' && node.hasAttribute('data-rich-text-comment')) { |
|
1592 const value = { |
|
1593 formats: [,], |
|
1594 replacements: [{ |
|
1595 type: '#comment', |
|
1596 attributes: { |
|
1597 'data-rich-text-comment': node.nodeType === node.COMMENT_NODE ? node.nodeValue : node.getAttribute('data-rich-text-comment') |
|
1598 } |
|
1599 }], |
|
1600 text: OBJECT_REPLACEMENT_CHARACTER |
|
1601 }; |
|
1602 accumulateSelection(accumulator, node, range, value); |
|
1603 mergePair(accumulator, value); |
|
1554 continue; |
1604 continue; |
1555 } |
1605 } |
1556 if (node.nodeType !== node.ELEMENT_NODE) { |
1606 if (node.nodeType !== node.ELEMENT_NODE) { |
1557 continue; |
1607 continue; |
1558 } |
1608 } |
1654 } |
1704 } |
1655 |
1705 |
1656 /** |
1706 /** |
1657 * Gets the attributes of an element in object shape. |
1707 * Gets the attributes of an element in object shape. |
1658 * |
1708 * |
1659 * @param {Object} $1 Named argements. |
1709 * @param {Object} $1 Named arguments. |
1660 * @param {Element} $1.element Element to get attributes from. |
1710 * @param {Element} $1.element Element to get attributes from. |
1661 * |
1711 * |
1662 * @return {Object|void} Attribute object or `undefined` if the element has no |
1712 * @return {Object|void} Attribute object or `undefined` if the element has no |
1663 * attributes. |
1713 * attributes. |
1664 */ |
1714 */ |
1685 accumulator[safeName] = value; |
1735 accumulator[safeName] = value; |
1686 } |
1736 } |
1687 return accumulator; |
1737 return accumulator; |
1688 } |
1738 } |
1689 |
1739 |
1690 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/concat.js |
1740 ;// ./node_modules/@wordpress/rich-text/build-module/concat.js |
1691 /** |
1741 /** |
1692 * Internal dependencies |
1742 * Internal dependencies |
1693 */ |
1743 */ |
1694 |
1744 |
1695 |
1745 |
1723 */ |
1773 */ |
1724 function concat(...values) { |
1774 function concat(...values) { |
1725 return normaliseFormats(values.reduce(mergePair, create())); |
1775 return normaliseFormats(values.reduce(mergePair, create())); |
1726 } |
1776 } |
1727 |
1777 |
1728 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-format.js |
1778 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-format.js |
1729 /** |
1779 /** |
1730 * Internal dependencies |
1780 * Internal dependencies |
1731 */ |
1781 */ |
1732 |
1782 |
1733 |
1783 |
1750 return getActiveFormats(value).find(({ |
1800 return getActiveFormats(value).find(({ |
1751 type |
1801 type |
1752 }) => type === formatType); |
1802 }) => type === formatType); |
1753 } |
1803 } |
1754 |
1804 |
1755 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/get-active-object.js |
1805 ;// ./node_modules/@wordpress/rich-text/build-module/get-active-object.js |
1756 /** |
1806 /** |
1757 * Internal dependencies |
1807 * Internal dependencies |
1758 */ |
1808 */ |
1759 |
1809 |
1760 |
1810 |
1779 return; |
1829 return; |
1780 } |
1830 } |
1781 return replacements[start]; |
1831 return replacements[start]; |
1782 } |
1832 } |
1783 |
1833 |
1784 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js |
1834 ;// ./node_modules/@wordpress/rich-text/build-module/is-collapsed.js |
1785 /** |
1835 /** |
1786 * Internal dependencies |
1836 * Internal dependencies |
1787 */ |
1837 */ |
1788 |
1838 |
1789 /** |
1839 /** |
1805 return; |
1855 return; |
1806 } |
1856 } |
1807 return start === end; |
1857 return start === end; |
1808 } |
1858 } |
1809 |
1859 |
1810 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-empty.js |
1860 ;// ./node_modules/@wordpress/rich-text/build-module/is-empty.js |
1811 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
1861 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
1812 |
1862 |
1813 /** |
1863 /** |
1814 * Check if a Rich Text value is Empty, meaning it contains no text or any |
1864 * Check if a Rich Text value is Empty, meaning it contains no text or any |
1815 * objects (such as images). |
1865 * objects (such as images). |
1822 text |
1872 text |
1823 }) { |
1873 }) { |
1824 return text.length === 0; |
1874 return text.length === 0; |
1825 } |
1875 } |
1826 |
1876 |
1827 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/join.js |
1877 ;// ./node_modules/@wordpress/rich-text/build-module/join.js |
1828 /** |
1878 /** |
1829 * Internal dependencies |
1879 * Internal dependencies |
1830 */ |
1880 */ |
1831 |
1881 |
1832 |
1882 |
1848 if (typeof separator === 'string') { |
1898 if (typeof separator === 'string') { |
1849 separator = create({ |
1899 separator = create({ |
1850 text: separator |
1900 text: separator |
1851 }); |
1901 }); |
1852 } |
1902 } |
1853 return normaliseFormats(values.reduce((accumlator, { |
1903 return normaliseFormats(values.reduce((accumulator, { |
1854 formats, |
1904 formats, |
1855 replacements, |
1905 replacements, |
1856 text |
1906 text |
1857 }) => ({ |
1907 }) => ({ |
1858 formats: accumlator.formats.concat(separator.formats, formats), |
1908 formats: accumulator.formats.concat(separator.formats, formats), |
1859 replacements: accumlator.replacements.concat(separator.replacements, replacements), |
1909 replacements: accumulator.replacements.concat(separator.replacements, replacements), |
1860 text: accumlator.text + separator.text + text |
1910 text: accumulator.text + separator.text + text |
1861 }))); |
1911 }))); |
1862 } |
1912 } |
1863 |
1913 |
1864 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/register-format-type.js |
1914 ;// ./node_modules/@wordpress/rich-text/build-module/register-format-type.js |
1865 /** |
1915 /** |
1866 * WordPress dependencies |
1916 * WordPress dependencies |
1867 */ |
1917 */ |
1868 |
1918 |
1869 /** |
1919 /** |
1950 } |
2000 } |
1951 (0,external_wp_data_namespaceObject.dispatch)(store).addFormatTypes(settings); |
2001 (0,external_wp_data_namespaceObject.dispatch)(store).addFormatTypes(settings); |
1952 return settings; |
2002 return settings; |
1953 } |
2003 } |
1954 |
2004 |
1955 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove-format.js |
2005 ;// ./node_modules/@wordpress/rich-text/build-module/remove-format.js |
1956 /** |
2006 /** |
1957 * Internal dependencies |
2007 * Internal dependencies |
1958 */ |
2008 */ |
1959 |
2009 |
1960 |
2010 |
2021 } else { |
2071 } else { |
2022 delete formats[index]; |
2072 delete formats[index]; |
2023 } |
2073 } |
2024 } |
2074 } |
2025 |
2075 |
2026 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert.js |
2076 ;// ./node_modules/@wordpress/rich-text/build-module/insert.js |
2027 /** |
2077 /** |
2028 * Internal dependencies |
2078 * Internal dependencies |
2029 */ |
2079 */ |
2030 |
2080 |
2031 |
2081 |
2065 start: index, |
2115 start: index, |
2066 end: index |
2116 end: index |
2067 }); |
2117 }); |
2068 } |
2118 } |
2069 |
2119 |
2070 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/remove.js |
2120 ;// ./node_modules/@wordpress/rich-text/build-module/remove.js |
2071 /** |
2121 /** |
2072 * Internal dependencies |
2122 * Internal dependencies |
2073 */ |
2123 */ |
2074 |
2124 |
2075 |
2125 |
2089 */ |
2139 */ |
2090 function remove_remove(value, startIndex, endIndex) { |
2140 function remove_remove(value, startIndex, endIndex) { |
2091 return insert(value, create(), startIndex, endIndex); |
2141 return insert(value, create(), startIndex, endIndex); |
2092 } |
2142 } |
2093 |
2143 |
2094 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/replace.js |
2144 ;// ./node_modules/@wordpress/rich-text/build-module/replace.js |
2095 /** |
2145 /** |
2096 * Internal dependencies |
2146 * Internal dependencies |
2097 */ |
2147 */ |
2098 |
2148 |
2099 |
2149 |
2156 start, |
2206 start, |
2157 end |
2207 end |
2158 }); |
2208 }); |
2159 } |
2209 } |
2160 |
2210 |
2161 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/insert-object.js |
2211 ;// ./node_modules/@wordpress/rich-text/build-module/insert-object.js |
2162 /** |
2212 /** |
2163 * Internal dependencies |
2213 * Internal dependencies |
2164 */ |
2214 */ |
2165 |
2215 |
2166 |
2216 |
2188 text: OBJECT_REPLACEMENT_CHARACTER |
2238 text: OBJECT_REPLACEMENT_CHARACTER |
2189 }; |
2239 }; |
2190 return insert(value, valueToInsert, startIndex, endIndex); |
2240 return insert(value, valueToInsert, startIndex, endIndex); |
2191 } |
2241 } |
2192 |
2242 |
2193 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/slice.js |
2243 ;// ./node_modules/@wordpress/rich-text/build-module/slice.js |
2194 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
2244 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
2195 |
2245 |
2196 /** |
2246 /** |
2197 * Slice a Rich Text value from `startIndex` to `endIndex`. Indices are |
2247 * Slice a Rich Text value from `startIndex` to `endIndex`. Indices are |
2198 * retrieved from the selection if none are provided. This is similar to |
2248 * retrieved from the selection if none are provided. This is similar to |
2220 replacements: replacements.slice(startIndex, endIndex), |
2270 replacements: replacements.slice(startIndex, endIndex), |
2221 text: text.slice(startIndex, endIndex) |
2271 text: text.slice(startIndex, endIndex) |
2222 }; |
2272 }; |
2223 } |
2273 } |
2224 |
2274 |
2225 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/split.js |
2275 ;// ./node_modules/@wordpress/rich-text/build-module/split.js |
2226 /** |
2276 /** |
2227 * Internal dependencies |
2277 * Internal dependencies |
2228 */ |
2278 */ |
2229 |
2279 |
2230 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
2280 /** @typedef {import('./types').RichTextValue} RichTextValue */ |
2296 end: 0 |
2346 end: 0 |
2297 }; |
2347 }; |
2298 return [before, after]; |
2348 return [before, after]; |
2299 } |
2349 } |
2300 |
2350 |
2301 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/is-range-equal.js |
2351 ;// ./node_modules/@wordpress/rich-text/build-module/is-range-equal.js |
2302 /** |
2352 /** |
2303 * Returns true if two ranges are equal, or false otherwise. Ranges are |
2353 * Returns true if two ranges are equal, or false otherwise. Ranges are |
2304 * considered equal if their start and end occur in the same container and |
2354 * considered equal if their start and end occur in the same container and |
2305 * offset. |
2355 * offset. |
2306 * |
2356 * |
2311 */ |
2361 */ |
2312 function isRangeEqual(a, b) { |
2362 function isRangeEqual(a, b) { |
2313 return a === b || a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset; |
2363 return a === b || a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset; |
2314 } |
2364 } |
2315 |
2365 |
2316 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/to-dom.js |
2366 ;// ./node_modules/@wordpress/rich-text/build-module/to-dom.js |
2317 /** |
2367 /** |
2318 * Internal dependencies |
2368 * Internal dependencies |
2319 */ |
2369 */ |
2320 |
2370 |
2321 |
2371 |
2375 const { |
2425 const { |
2376 type, |
2426 type, |
2377 attributes |
2427 attributes |
2378 } = child; |
2428 } = child; |
2379 if (type) { |
2429 if (type) { |
2380 child = element.ownerDocument.createElement(type); |
2430 if (type === '#comment') { |
2381 for (const key in attributes) { |
2431 child = element.ownerDocument.createComment(attributes['data-rich-text-comment']); |
2382 child.setAttribute(key, attributes[key]); |
2432 } else { |
2433 child = element.ownerDocument.createElement(type); |
|
2434 for (const key in attributes) { |
|
2435 child.setAttribute(key, attributes[key]); |
|
2436 } |
|
2383 } |
2437 } |
2384 } |
2438 } |
2385 return element.appendChild(child); |
2439 return element.appendChild(child); |
2386 } |
2440 } |
2387 function to_dom_appendText(node, text) { |
2441 function to_dom_appendText(node, text) { |
2594 activeElement.focus(); |
2648 activeElement.focus(); |
2595 } |
2649 } |
2596 } |
2650 } |
2597 } |
2651 } |
2598 |
2652 |
2599 ;// CONCATENATED MODULE: external ["wp","a11y"] |
2653 ;// external ["wp","a11y"] |
2600 const external_wp_a11y_namespaceObject = window["wp"]["a11y"]; |
2654 const external_wp_a11y_namespaceObject = window["wp"]["a11y"]; |
2601 ;// CONCATENATED MODULE: external ["wp","i18n"] |
2655 ;// external ["wp","i18n"] |
2602 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
2656 const external_wp_i18n_namespaceObject = window["wp"]["i18n"]; |
2603 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/toggle-format.js |
2657 ;// ./node_modules/@wordpress/rich-text/build-module/toggle-format.js |
2604 /** |
2658 /** |
2605 * WordPress dependencies |
2659 * WordPress dependencies |
2606 */ |
2660 */ |
2607 |
2661 |
2608 |
2662 |
2642 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)((0,external_wp_i18n_namespaceObject.__)('%s applied.'), format.title), 'assertive'); |
2696 (0,external_wp_a11y_namespaceObject.speak)((0,external_wp_i18n_namespaceObject.sprintf)((0,external_wp_i18n_namespaceObject.__)('%s applied.'), format.title), 'assertive'); |
2643 } |
2697 } |
2644 return applyFormat(value, format); |
2698 return applyFormat(value, format); |
2645 } |
2699 } |
2646 |
2700 |
2647 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js |
2701 ;// ./node_modules/@wordpress/rich-text/build-module/unregister-format-type.js |
2648 /** |
2702 /** |
2649 * WordPress dependencies |
2703 * WordPress dependencies |
2650 */ |
2704 */ |
2651 |
2705 |
2652 |
2706 |
2674 } |
2728 } |
2675 (0,external_wp_data_namespaceObject.dispatch)(store).removeFormatTypes(name); |
2729 (0,external_wp_data_namespaceObject.dispatch)(store).removeFormatTypes(name); |
2676 return oldFormat; |
2730 return oldFormat; |
2677 } |
2731 } |
2678 |
2732 |
2679 ;// CONCATENATED MODULE: external ["wp","element"] |
2733 ;// external ["wp","element"] |
2680 const external_wp_element_namespaceObject = window["wp"]["element"]; |
2734 const external_wp_element_namespaceObject = window["wp"]["element"]; |
2681 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
2735 ;// external ["wp","deprecated"] |
2682 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
2736 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
2683 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
2737 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
2684 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js |
2738 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-anchor-ref.js |
2685 /** |
2739 /** |
2686 * WordPress dependencies |
2740 * WordPress dependencies |
2687 */ |
2741 */ |
2688 |
2742 |
2689 |
2743 |
2755 } |
2809 } |
2756 return element.closest(tagName + (className ? '.' + className : '')); |
2810 return element.closest(tagName + (className ? '.' + className : '')); |
2757 }, [activeFormat, value.start, value.end, tagName, className]); |
2811 }, [activeFormat, value.start, value.end, tagName, className]); |
2758 } |
2812 } |
2759 |
2813 |
2760 ;// CONCATENATED MODULE: external ["wp","compose"] |
2814 ;// external ["wp","compose"] |
2761 const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
2815 const external_wp_compose_namespaceObject = window["wp"]["compose"]; |
2762 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-anchor.js |
2816 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-anchor.js |
2763 /** |
2817 /** |
2764 * WordPress dependencies |
2818 * WordPress dependencies |
2765 */ |
2819 */ |
2766 |
2820 |
2767 |
2821 |
2781 * @return {HTMLElement|undefined} The format element, if found. |
2835 * @return {HTMLElement|undefined} The format element, if found. |
2782 */ |
2836 */ |
2783 function getFormatElement(range, editableContentElement, tagName, className) { |
2837 function getFormatElement(range, editableContentElement, tagName, className) { |
2784 let element = range.startContainer; |
2838 let element = range.startContainer; |
2785 |
2839 |
2786 // Even if the active format is defined, the actualy DOM range's start |
2840 // Even if the active format is defined, the actually DOM range's start |
2787 // container may be outside of the format's DOM element: |
2841 // container may be outside of the format's DOM element: |
2788 // `a‸<strong>b</strong>` (DOM) while visually it's `a<strong>‸b</strong>`. |
2842 // `a‸<strong>b</strong>` (DOM) while visually it's `a<strong>‸b</strong>`. |
2789 // So at a given selection index, start with the deepest format DOM element. |
2843 // So at a given selection index, start with the deepest format DOM element. |
2790 if (element.nodeType === element.TEXT_NODE && range.startOffset === element.length && element.nextSibling) { |
2844 if (element.nodeType === element.TEXT_NODE && range.startOffset === element.length && element.nextSibling) { |
2791 element = element.nextSibling; |
2845 element = element.nextSibling; |
2942 }; |
2996 }; |
2943 }, [editableContentElement, tagName, className, isActive, wasActive]); |
2997 }, [editableContentElement, tagName, className, isActive, wasActive]); |
2944 return anchor; |
2998 return anchor; |
2945 } |
2999 } |
2946 |
3000 |
2947 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js |
3001 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-default-style.js |
2948 /** |
3002 /** |
2949 * WordPress dependencies |
3003 * WordPress dependencies |
2950 */ |
3004 */ |
2951 |
3005 |
2952 |
3006 |
2985 element.style.whiteSpace = whiteSpace; |
3039 element.style.whiteSpace = whiteSpace; |
2986 element.style.minWidth = minWidth; |
3040 element.style.minWidth = minWidth; |
2987 }, []); |
3041 }, []); |
2988 } |
3042 } |
2989 |
3043 |
2990 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js |
3044 ;// ./node_modules/@wordpress/rich-text/build-module/component/use-boundary-style.js |
2991 /** |
3045 /** |
2992 * WordPress dependencies |
3046 * WordPress dependencies |
2993 */ |
3047 */ |
2994 |
3048 |
2995 |
3049 |
3041 } |
3095 } |
3042 }, [activeFormats, activeReplacement]); |
3096 }, [activeFormats, activeReplacement]); |
3043 return ref; |
3097 return ref; |
3044 } |
3098 } |
3045 |
3099 |
3046 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/copy-handler.js |
3100 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/copy-handler.js |
3047 /** |
3101 /** |
3048 * Internal dependencies |
3102 * Internal dependencies |
3049 */ |
3103 */ |
3050 |
3104 |
3051 |
3105 |
3084 defaultView.removeEventListener('copy', onCopy); |
3138 defaultView.removeEventListener('copy', onCopy); |
3085 defaultView.removeEventListener('cut', onCopy); |
3139 defaultView.removeEventListener('cut', onCopy); |
3086 }; |
3140 }; |
3087 }); |
3141 }); |
3088 |
3142 |
3089 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/select-object.js |
3143 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/select-object.js |
3090 /* harmony default export */ const select_object = (() => element => { |
3144 /* harmony default export */ const select_object = (() => element => { |
3091 function onClick(event) { |
3145 function onClick(event) { |
3092 const { |
3146 const { |
3093 target |
3147 target |
3094 } = event; |
3148 } = event; |
3131 element.removeEventListener('click', onClick); |
3185 element.removeEventListener('click', onClick); |
3132 element.removeEventListener('focusin', onFocusIn); |
3186 element.removeEventListener('focusin', onFocusIn); |
3133 }; |
3187 }; |
3134 }); |
3188 }); |
3135 |
3189 |
3136 ;// CONCATENATED MODULE: external ["wp","keycodes"] |
3190 ;// external ["wp","keycodes"] |
3137 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
3191 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
3138 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/format-boundaries.js |
3192 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/format-boundaries.js |
3139 /** |
3193 /** |
3140 * WordPress dependencies |
3194 * WordPress dependencies |
3141 */ |
3195 */ |
3142 |
3196 |
3143 |
3197 |
3235 return () => { |
3289 return () => { |
3236 element.removeEventListener('keydown', onKeyDown); |
3290 element.removeEventListener('keydown', onKeyDown); |
3237 }; |
3291 }; |
3238 }); |
3292 }); |
3239 |
3293 |
3240 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/delete.js |
3294 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/delete.js |
3241 /** |
3295 /** |
3242 * WordPress dependencies |
3296 * WordPress dependencies |
3243 */ |
3297 */ |
3244 |
3298 |
3245 |
3299 |
3279 return () => { |
3333 return () => { |
3280 element.removeEventListener('keydown', onKeyDown); |
3334 element.removeEventListener('keydown', onKeyDown); |
3281 }; |
3335 }; |
3282 }); |
3336 }); |
3283 |
3337 |
3284 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/update-formats.js |
3338 ;// ./node_modules/@wordpress/rich-text/build-module/update-formats.js |
3285 /** |
3339 /** |
3286 * Internal dependencies |
3340 * Internal dependencies |
3287 */ |
3341 */ |
3288 |
3342 |
3289 |
3343 |
3336 } |
3390 } |
3337 } |
3391 } |
3338 return value; |
3392 return value; |
3339 } |
3393 } |
3340 |
3394 |
3341 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/input-and-selection.js |
3395 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/input-and-selection.js |
3342 /** |
3396 /** |
3343 * Internal dependencies |
3397 * Internal dependencies |
3344 */ |
3398 */ |
3345 |
3399 |
3346 |
3400 |
3572 element.removeEventListener('compositionend', onCompositionEnd); |
3626 element.removeEventListener('compositionend', onCompositionEnd); |
3573 element.removeEventListener('focus', onFocus); |
3627 element.removeEventListener('focus', onFocus); |
3574 }; |
3628 }; |
3575 }); |
3629 }); |
3576 |
3630 |
3577 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/selection-change-compat.js |
3631 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/selection-change-compat.js |
3578 /** |
3632 /** |
3579 * Internal dependencies |
3633 * Internal dependencies |
3580 */ |
3634 */ |
3581 |
3635 |
3582 |
3636 |
3623 element.removeEventListener('pointerdown', onDown); |
3677 element.removeEventListener('pointerdown', onDown); |
3624 element.removeEventListener('keydown', onDown); |
3678 element.removeEventListener('keydown', onDown); |
3625 }; |
3679 }; |
3626 }); |
3680 }); |
3627 |
3681 |
3628 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/index.js |
3682 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/prevent-focus-capture.js |
3683 /** |
|
3684 * Prevents focus from being captured by the element when clicking _outside_ |
|
3685 * around the element. This may happen when the parent element is flex. |
|
3686 * @see https://github.com/WordPress/gutenberg/pull/65857 |
|
3687 * @see https://github.com/WordPress/gutenberg/pull/66402 |
|
3688 */ |
|
3689 function preventFocusCapture() { |
|
3690 return element => { |
|
3691 const { |
|
3692 ownerDocument |
|
3693 } = element; |
|
3694 const { |
|
3695 defaultView |
|
3696 } = ownerDocument; |
|
3697 let value = null; |
|
3698 function onPointerDown(event) { |
|
3699 // Abort if the event is default prevented, we will not get a pointer up event. |
|
3700 if (event.defaultPrevented) { |
|
3701 return; |
|
3702 } |
|
3703 if (event.target === element) { |
|
3704 return; |
|
3705 } |
|
3706 if (!event.target.contains(element)) { |
|
3707 return; |
|
3708 } |
|
3709 value = element.getAttribute('contenteditable'); |
|
3710 element.setAttribute('contenteditable', 'false'); |
|
3711 defaultView.getSelection().removeAllRanges(); |
|
3712 } |
|
3713 function onPointerUp() { |
|
3714 if (value !== null) { |
|
3715 element.setAttribute('contenteditable', value); |
|
3716 value = null; |
|
3717 } |
|
3718 } |
|
3719 defaultView.addEventListener('pointerdown', onPointerDown); |
|
3720 defaultView.addEventListener('pointerup', onPointerUp); |
|
3721 return () => { |
|
3722 defaultView.removeEventListener('pointerdown', onPointerDown); |
|
3723 defaultView.removeEventListener('pointerup', onPointerUp); |
|
3724 }; |
|
3725 }; |
|
3726 } |
|
3727 |
|
3728 ;// ./node_modules/@wordpress/rich-text/build-module/component/event-listeners/index.js |
|
3629 /** |
3729 /** |
3630 * WordPress dependencies |
3730 * WordPress dependencies |
3631 */ |
3731 */ |
3632 |
3732 |
3633 |
3733 |
3639 |
3739 |
3640 |
3740 |
3641 |
3741 |
3642 |
3742 |
3643 |
3743 |
3644 const allEventListeners = [copy_handler, select_object, format_boundaries, event_listeners_delete, input_and_selection, selection_change_compat]; |
3744 |
3745 const allEventListeners = [copy_handler, select_object, format_boundaries, event_listeners_delete, input_and_selection, selection_change_compat, preventFocusCapture]; |
|
3645 function useEventListeners(props) { |
3746 function useEventListeners(props) { |
3646 const propsRef = (0,external_wp_element_namespaceObject.useRef)(props); |
3747 const propsRef = (0,external_wp_element_namespaceObject.useRef)(props); |
3647 propsRef.current = props; |
3748 (0,external_wp_element_namespaceObject.useInsertionEffect)(() => { |
3749 propsRef.current = props; |
|
3750 }); |
|
3648 const refEffects = (0,external_wp_element_namespaceObject.useMemo)(() => allEventListeners.map(refEffect => refEffect(propsRef)), [propsRef]); |
3751 const refEffects = (0,external_wp_element_namespaceObject.useMemo)(() => allEventListeners.map(refEffect => refEffect(propsRef)), [propsRef]); |
3649 return (0,external_wp_compose_namespaceObject.useRefEffect)(element => { |
3752 return (0,external_wp_compose_namespaceObject.useRefEffect)(element => { |
3650 const cleanups = refEffects.map(effect => effect(element)); |
3753 const cleanups = refEffects.map(effect => effect(element)); |
3651 return () => { |
3754 return () => { |
3652 cleanups.forEach(cleanup => cleanup()); |
3755 cleanups.forEach(cleanup => cleanup()); |
3653 }; |
3756 }; |
3654 }, [refEffects]); |
3757 }, [refEffects]); |
3655 } |
3758 } |
3656 |
3759 |
3657 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/component/index.js |
3760 ;// ./node_modules/@wordpress/rich-text/build-module/component/index.js |
3658 /** |
3761 /** |
3659 * WordPress dependencies |
3762 * WordPress dependencies |
3660 */ |
3763 */ |
3661 |
3764 |
3662 |
3765 |
3714 placeholder |
3817 placeholder |
3715 }); |
3818 }); |
3716 } |
3819 } |
3717 |
3820 |
3718 // Internal values are updated synchronously, unlike props and state. |
3821 // Internal values are updated synchronously, unlike props and state. |
3719 const _value = (0,external_wp_element_namespaceObject.useRef)(value); |
3822 const _valueRef = (0,external_wp_element_namespaceObject.useRef)(value); |
3720 const record = (0,external_wp_element_namespaceObject.useRef)(); |
3823 const recordRef = (0,external_wp_element_namespaceObject.useRef)(); |
3721 function setRecordFromProps() { |
3824 function setRecordFromProps() { |
3722 _value.current = value; |
3825 _valueRef.current = value; |
3723 record.current = value; |
3826 recordRef.current = value; |
3724 if (!(value instanceof RichTextData)) { |
3827 if (!(value instanceof RichTextData)) { |
3725 record.current = value ? RichTextData.fromHTMLString(value, { |
3828 recordRef.current = value ? RichTextData.fromHTMLString(value, { |
3726 preserveWhiteSpace |
3829 preserveWhiteSpace |
3727 }) : RichTextData.empty(); |
3830 }) : RichTextData.empty(); |
3728 } |
3831 } |
3729 // To do: make rich text internally work with RichTextData. |
3832 // To do: make rich text internally work with RichTextData. |
3730 record.current = { |
3833 recordRef.current = { |
3731 text: record.current.text, |
3834 text: recordRef.current.text, |
3732 formats: record.current.formats, |
3835 formats: recordRef.current.formats, |
3733 replacements: record.current.replacements |
3836 replacements: recordRef.current.replacements |
3734 }; |
3837 }; |
3735 if (disableFormats) { |
3838 if (disableFormats) { |
3736 record.current.formats = Array(value.length); |
3839 recordRef.current.formats = Array(value.length); |
3737 record.current.replacements = Array(value.length); |
3840 recordRef.current.replacements = Array(value.length); |
3738 } |
3841 } |
3739 if (__unstableAfterParse) { |
3842 if (__unstableAfterParse) { |
3740 record.current.formats = __unstableAfterParse(record.current); |
3843 recordRef.current.formats = __unstableAfterParse(recordRef.current); |
3741 } |
3844 } |
3742 record.current.start = selectionStart; |
3845 recordRef.current.start = selectionStart; |
3743 record.current.end = selectionEnd; |
3846 recordRef.current.end = selectionEnd; |
3744 } |
3847 } |
3745 const hadSelectionUpdate = (0,external_wp_element_namespaceObject.useRef)(false); |
3848 const hadSelectionUpdateRef = (0,external_wp_element_namespaceObject.useRef)(false); |
3746 if (!record.current) { |
3849 if (!recordRef.current) { |
3747 hadSelectionUpdate.current = isSelected; |
3850 hadSelectionUpdateRef.current = isSelected; |
3748 setRecordFromProps(); |
3851 setRecordFromProps(); |
3749 } else if (selectionStart !== record.current.start || selectionEnd !== record.current.end) { |
3852 } else if (selectionStart !== recordRef.current.start || selectionEnd !== recordRef.current.end) { |
3750 hadSelectionUpdate.current = isSelected; |
3853 hadSelectionUpdateRef.current = isSelected; |
3751 record.current = { |
3854 recordRef.current = { |
3752 ...record.current, |
3855 ...recordRef.current, |
3753 start: selectionStart, |
3856 start: selectionStart, |
3754 end: selectionEnd, |
3857 end: selectionEnd, |
3755 activeFormats: undefined |
3858 activeFormats: undefined |
3756 }; |
3859 }; |
3757 } |
3860 } |
3761 * updated if differences are found. |
3864 * updated if differences are found. |
3762 * |
3865 * |
3763 * @param {Object} newRecord The record to sync and apply. |
3866 * @param {Object} newRecord The record to sync and apply. |
3764 */ |
3867 */ |
3765 function handleChange(newRecord) { |
3868 function handleChange(newRecord) { |
3766 record.current = newRecord; |
3869 recordRef.current = newRecord; |
3767 applyRecord(newRecord); |
3870 applyRecord(newRecord); |
3768 if (disableFormats) { |
3871 if (disableFormats) { |
3769 _value.current = newRecord.text; |
3872 _valueRef.current = newRecord.text; |
3770 } else { |
3873 } else { |
3771 const newFormats = __unstableBeforeSerialize ? __unstableBeforeSerialize(newRecord) : newRecord.formats; |
3874 const newFormats = __unstableBeforeSerialize ? __unstableBeforeSerialize(newRecord) : newRecord.formats; |
3772 newRecord = { |
3875 newRecord = { |
3773 ...newRecord, |
3876 ...newRecord, |
3774 formats: newFormats |
3877 formats: newFormats |
3775 }; |
3878 }; |
3776 if (typeof value === 'string') { |
3879 if (typeof value === 'string') { |
3777 _value.current = toHTMLString({ |
3880 _valueRef.current = toHTMLString({ |
3778 value: newRecord, |
3881 value: newRecord, |
3779 preserveWhiteSpace |
3882 preserveWhiteSpace |
3780 }); |
3883 }); |
3781 } else { |
3884 } else { |
3782 _value.current = new RichTextData(newRecord); |
3885 _valueRef.current = new RichTextData(newRecord); |
3783 } |
3886 } |
3784 } |
3887 } |
3785 const { |
3888 const { |
3786 start, |
3889 start, |
3787 end, |
3890 end, |
3788 formats, |
3891 formats, |
3789 text |
3892 text |
3790 } = record.current; |
3893 } = recordRef.current; |
3791 |
3894 |
3792 // Selection must be updated first, so it is recorded in history when |
3895 // Selection must be updated first, so it is recorded in history when |
3793 // the content change happens. |
3896 // the content change happens. |
3794 // We batch both calls to only attempt to rerender once. |
3897 // We batch both calls to only attempt to rerender once. |
3795 registry.batch(() => { |
3898 registry.batch(() => { |
3796 onSelectionChange(start, end); |
3899 onSelectionChange(start, end); |
3797 onChange(_value.current, { |
3900 onChange(_valueRef.current, { |
3798 __unstableFormats: formats, |
3901 __unstableFormats: formats, |
3799 __unstableText: text |
3902 __unstableText: text |
3800 }); |
3903 }); |
3801 }); |
3904 }); |
3802 forceRender(); |
3905 forceRender(); |
3803 } |
3906 } |
3804 function applyFromProps() { |
3907 function applyFromProps() { |
3805 setRecordFromProps(); |
3908 setRecordFromProps(); |
3806 applyRecord(record.current); |
3909 applyRecord(recordRef.current); |
3807 } |
3910 } |
3808 const didMount = (0,external_wp_element_namespaceObject.useRef)(false); |
3911 const didMountRef = (0,external_wp_element_namespaceObject.useRef)(false); |
3809 |
3912 |
3810 // Value updates must happen synchonously to avoid overwriting newer values. |
3913 // Value updates must happen synchronously to avoid overwriting newer values. |
3811 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
3914 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
3812 if (didMount.current && value !== _value.current) { |
3915 if (didMountRef.current && value !== _valueRef.current) { |
3813 applyFromProps(); |
3916 applyFromProps(); |
3814 forceRender(); |
3917 forceRender(); |
3815 } |
3918 } |
3816 }, [value]); |
3919 }, [value]); |
3817 |
3920 |
3818 // Value updates must happen synchonously to avoid overwriting newer values. |
3921 // Value updates must happen synchronously to avoid overwriting newer values. |
3819 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
3922 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
3820 if (!hadSelectionUpdate.current) { |
3923 if (!hadSelectionUpdateRef.current) { |
3821 return; |
3924 return; |
3822 } |
3925 } |
3823 if (ref.current.ownerDocument.activeElement !== ref.current) { |
3926 if (ref.current.ownerDocument.activeElement !== ref.current) { |
3824 ref.current.focus(); |
3927 ref.current.focus(); |
3825 } |
3928 } |
3826 applyRecord(record.current); |
3929 applyRecord(recordRef.current); |
3827 hadSelectionUpdate.current = false; |
3930 hadSelectionUpdateRef.current = false; |
3828 }, [hadSelectionUpdate.current]); |
3931 }, [hadSelectionUpdateRef.current]); |
3829 const mergedRefs = (0,external_wp_compose_namespaceObject.useMergeRefs)([ref, useDefaultStyle(), useBoundaryStyle({ |
3932 const mergedRefs = (0,external_wp_compose_namespaceObject.useMergeRefs)([ref, useDefaultStyle(), useBoundaryStyle({ |
3830 record |
3933 record: recordRef |
3831 }), useEventListeners({ |
3934 }), useEventListeners({ |
3832 record, |
3935 record: recordRef, |
3833 handleChange, |
3936 handleChange, |
3834 applyRecord, |
3937 applyRecord, |
3835 createRecord, |
3938 createRecord, |
3836 isSelected, |
3939 isSelected, |
3837 onSelectionChange, |
3940 onSelectionChange, |
3838 forceRender |
3941 forceRender |
3839 }), (0,external_wp_compose_namespaceObject.useRefEffect)(() => { |
3942 }), (0,external_wp_compose_namespaceObject.useRefEffect)(() => { |
3840 applyFromProps(); |
3943 applyFromProps(); |
3841 didMount.current = true; |
3944 didMountRef.current = true; |
3842 }, [placeholder, ...__unstableDependencies])]); |
3945 }, [placeholder, ...__unstableDependencies])]); |
3843 return { |
3946 return { |
3844 value: record.current, |
3947 value: recordRef.current, |
3845 // A function to get the most recent value so event handlers in |
3948 // A function to get the most recent value so event handlers in |
3846 // useRichText implementations have access to it. For example when |
3949 // useRichText implementations have access to it. For example when |
3847 // listening to input events, we internally update the state, but this |
3950 // listening to input events, we internally update the state, but this |
3848 // state is not yet available to the input event handler because React |
3951 // state is not yet available to the input event handler because React |
3849 // may re-render asynchronously. |
3952 // may re-render asynchronously. |
3850 getValue: () => record.current, |
3953 getValue: () => recordRef.current, |
3851 onChange: handleChange, |
3954 onChange: handleChange, |
3852 ref: mergedRefs |
3955 ref: mergedRefs |
3853 }; |
3956 }; |
3854 } |
3957 } |
3855 function __experimentalRichText() {} |
3958 function __experimentalRichText() {} |
3856 |
3959 |
3857 ;// CONCATENATED MODULE: ./node_modules/@wordpress/rich-text/build-module/index.js |
3960 ;// ./node_modules/@wordpress/rich-text/build-module/index.js |
3858 |
3961 |
3859 |
3962 |
3860 |
3963 |
3861 |
3964 |
3862 |
3965 |