| @@ -1,4 +1,5 @@ | ||
| 1 | +(function() { | |
| 1 | 2 | "use strict"; |
| 2 | 3 | var wp; |
| 3 | 4 | (wp ||= {}).richText = (() => { |
| 4 | 5 | var __create = Object.create; |
| @@ -256,10 +257,10 @@ | ||
| 256 | 257 | if (keys1.length !== keys2.length) { |
| 257 | 258 | return false; |
| 258 | 259 | } |
| 259 | 260 | const length = keys1.length; |
| 260 | - for (let i2 = 0; i2 < length; i2++) { | |
| 261 | - const name = keys1[i2]; | |
| 261 | + for (let i = 0; i < length; i++) { | |
| 262 | + const name = keys1[i]; | |
| 262 | 263 | if (attributes1[name] !== attributes2[name]) { |
| 263 | 264 | return false; |
| 264 | 265 | } |
| 265 | 266 | } |
| @@ -396,11 +397,11 @@ | ||
| 396 | 397 | return EMPTY_ACTIVE_FORMATS3; |
| 397 | 398 | } |
| 398 | 399 | const selectedFormats = formats.slice(start, end); |
| 399 | 400 | const _activeFormats = [...selectedFormats[0]]; |
| 400 | - let i2 = selectedFormats.length; | |
| 401 | - while (i2--) { | |
| 402 | - const formatsAtIndex = selectedFormats[i2]; | |
| 401 | + let i = selectedFormats.length; | |
| 402 | + while (i--) { | |
| 403 | + const formatsAtIndex = selectedFormats[i]; | |
| 403 | 404 | if (!formatsAtIndex) { |
| 404 | 405 | return EMPTY_ACTIVE_FORMATS3; |
| 405 | 406 | } |
| 406 | 407 | let ii = _activeFormats.length; |
| @@ -488,11 +489,11 @@ | ||
| 488 | 489 | object: formatType.object, |
| 489 | 490 | attributes: restoreOnAttributes(elementAttributes, isEditableTree) |
| 490 | 491 | }; |
| 491 | 492 | } |
| 492 | - function isEqualUntil(a2, b2, index) { | |
| 493 | + function isEqualUntil(a, b, index) { | |
| 493 | 494 | do { |
| 494 | - if (a2[index] !== b2[index]) { | |
| 495 | + if (a[index] !== b[index]) { | |
| 495 | 496 | return false; |
| 496 | 497 | } |
| 497 | 498 | } while (index--); |
| 498 | 499 | return true; |
| @@ -520,15 +521,15 @@ | ||
| 520 | 521 | const deepestActiveFormat = activeFormats[activeFormats.length - 1]; |
| 521 | 522 | let lastCharacterFormats; |
| 522 | 523 | let lastCharacter; |
| 523 | 524 | append3(tree, ""); |
| 524 | - for (let i2 = 0; i2 < formatsLength; i2++) { | |
| 525 | - const character = text.charAt(i2); | |
| 525 | + for (let i = 0; i < formatsLength; i++) { | |
| 526 | + const character = text.charAt(i); | |
| 526 | 527 | const shouldInsertPadding = isEditableTree && // Pad the line if the line is empty. |
| 527 | 528 | (!lastCharacter || // Pad the line if the previous character is a line break, otherwise |
| 528 | 529 | // the line break won't be visible. |
| 529 | 530 | lastCharacter === "\n"); |
| 530 | - const characterFormats = formats[i2]; | |
| 531 | + const characterFormats = formats[i]; | |
| 531 | 532 | let pointer = getLastChild3(tree); |
| 532 | 533 | if (characterFormats) { |
| 533 | 534 | characterFormats.forEach((format, formatIndex) => { |
| 534 | 535 | if (pointer && lastCharacterFormats && // Reuse the last element if all formats remain the same. |
| @@ -559,9 +560,9 @@ | ||
| 559 | 560 | } |
| 560 | 561 | pointer = append3(newNode, ""); |
| 561 | 562 | }); |
| 562 | 563 | } |
| 563 | - if (i2 === 0) { | |
| 564 | + if (i === 0) { | |
| 564 | 565 | if (onStartIndex && start === 0) { |
| 565 | 566 | onStartIndex(tree, pointer); |
| 566 | 567 | } |
| 567 | 568 | if (onEndIndex && end === 0) { |
| @@ -568,9 +569,9 @@ | ||
| 568 | 569 | onEndIndex(tree, pointer); |
| 569 | 570 | } |
| 570 | 571 | } |
| 571 | 572 | if (character === OBJECT_REPLACEMENT_CHARACTER) { |
| 572 | - const replacement = replacements[i2]; | |
| 573 | + const replacement = replacements[i]; | |
| 573 | 574 | if (!replacement) { |
| 574 | 575 | continue; |
| 575 | 576 | } |
| 576 | 577 | const { type, attributes, innerHTML } = replacement; |
| @@ -607,9 +608,9 @@ | ||
| 607 | 608 | const attrs = { |
| 608 | 609 | contenteditable: "false", |
| 609 | 610 | "data-rich-text-bogus": true |
| 610 | 611 | }; |
| 611 | - if (start === i2 && end === i2 + 1) { | |
| 612 | + if (start === i && end === i + 1) { | |
| 612 | 613 | attrs["data-rich-text-format-boundary"] = true; |
| 613 | 614 | } |
| 614 | 615 | pointer = append3(pointer, { |
| 615 | 616 | type: "span", |
| @@ -614,9 +615,9 @@ | ||
| 614 | 615 | pointer = append3(pointer, { |
| 615 | 616 | type: "span", |
| 616 | 617 | attributes: attrs |
| 617 | 618 | }); |
| 618 | - if (isEditableTree && i2 + 1 === text.length) { | |
| 619 | + if (isEditableTree && i + 1 === text.length) { | |
| 619 | 620 | append3(getParent3(pointer), ZWNBSP); |
| 620 | 621 | } |
| 621 | 622 | } |
| 622 | 623 | pointer = append3( |
| @@ -656,16 +657,16 @@ | ||
| 656 | 657 | pointer = append3(getParent3(pointer), character); |
| 657 | 658 | } else { |
| 658 | 659 | appendText3(pointer, character); |
| 659 | 660 | } |
| 660 | - if (onStartIndex && start === i2 + 1) { | |
| 661 | + if (onStartIndex && start === i + 1) { | |
| 661 | 662 | onStartIndex(tree, pointer); |
| 662 | 663 | } |
| 663 | - if (onEndIndex && end === i2 + 1) { | |
| 664 | + if (onEndIndex && end === i + 1) { | |
| 664 | 665 | onEndIndex(tree, pointer); |
| 665 | 666 | } |
| 666 | - if (shouldInsertPadding && i2 === text.length) { | |
| 667 | - append3(getParent3(pointer), ZWNBSP); | |
| 667 | + if (shouldInsertPadding && i === text.length) { | |
| 668 | + appendText3(pointer, ZWNBSP); | |
| 668 | 669 | if (placeholder && text.length === 0) { |
| 669 | 670 | append3(getParent3(pointer), { |
| 670 | 671 | type: "span", |
| 671 | 672 | attributes: { |
| @@ -985,9 +986,9 @@ | ||
| 985 | 986 | } |
| 986 | 987 | function collapseWhiteSpace(element, isRoot = true, hasPrecedingSpace = false, hasTrailingSpace = false) { |
| 987 | 988 | const clone = element.cloneNode(true); |
| 988 | 989 | clone.normalize(); |
| 989 | - Array.from(clone.childNodes).forEach((node, i2, nodes) => { | |
| 990 | + Array.from(clone.childNodes).forEach((node, i, nodes) => { | |
| 990 | 991 | if (node.nodeType === node.TEXT_NODE) { |
| 991 | 992 | let newNodeValue = node.nodeValue; |
| 992 | 993 | if (/[\n\t\r\f]/.test(newNodeValue)) { |
| 993 | 994 | newNodeValue = newNodeValue.replace(/[\n\t\r\f]+/g, " "); |
| @@ -994,12 +995,12 @@ | ||
| 994 | 995 | } |
| 995 | 996 | if (newNodeValue.indexOf(" ") !== -1) { |
| 996 | 997 | newNodeValue = newNodeValue.replace(/ {2,}/g, " "); |
| 997 | 998 | } |
| 998 | - if (i2 === 0 && newNodeValue.startsWith(" ") && (isRoot || hasPrecedingSpace)) { | |
| 999 | + if (i === 0 && newNodeValue.startsWith(" ") && (isRoot || hasPrecedingSpace)) { | |
| 999 | 1000 | newNodeValue = newNodeValue.slice(1); |
| 1000 | 1001 | } |
| 1001 | - if (i2 === nodes.length - 1 && newNodeValue.endsWith(" ") && (isRoot || hasTrailingSpace)) { | |
| 1002 | + if (i === nodes.length - 1 && newNodeValue.endsWith(" ") && (isRoot || hasTrailingSpace)) { | |
| 1002 | 1003 | newNodeValue = newNodeValue.slice(0, -1); |
| 1003 | 1004 | } |
| 1004 | 1005 | node.nodeValue = newNodeValue; |
| 1005 | 1006 | } else if (node.nodeType === node.ELEMENT_NODE) { |
| @@ -1162,10 +1163,10 @@ | ||
| 1162 | 1163 | return; |
| 1163 | 1164 | } |
| 1164 | 1165 | const length = element.attributes.length; |
| 1165 | 1166 | let accumulator; |
| 1166 | - for (let i2 = 0; i2 < length; i2++) { | |
| 1167 | - const { name, value } = element.attributes[i2]; | |
| 1167 | + for (let i = 0; i < length; i++) { | |
| 1168 | + const { name, value } = element.attributes[i]; | |
| 1168 | 1169 | if (name.indexOf("data-rich-text-") === 0) { |
| 1169 | 1170 | continue; |
| 1170 | 1171 | } |
| 1171 | 1172 | const safeName = /^on/i.test(name) ? "data-disable-rich-text-" + name : name; |
| @@ -1175,13 +1176,13 @@ | ||
| 1175 | 1176 | return accumulator; |
| 1176 | 1177 | } |
| 1177 | 1178 | |
| 1178 | 1179 | // packages/rich-text/build-module/concat.mjs |
| 1179 | - function mergePair(a2, b2) { | |
| 1180 | - a2.formats = a2.formats.concat(b2.formats); | |
| 1181 | - a2.replacements = a2.replacements.concat(b2.replacements); | |
| 1182 | - a2.text += b2.text; | |
| 1183 | - return a2; | |
| 1180 | + function mergePair(a, b) { | |
| 1181 | + a.formats = a.formats.concat(b.formats); | |
| 1182 | + a.replacements = a.replacements.concat(b.replacements); | |
| 1183 | + a.text += b.text; | |
| 1184 | + return a; | |
| 1184 | 1185 | } |
| 1185 | 1186 | function concat(...values) { |
| 1186 | 1187 | return normaliseFormats(values.reduce(mergePair, create())); |
| 1187 | 1188 | } |
| @@ -1337,11 +1338,11 @@ | ||
| 1337 | 1338 | endIndex++; |
| 1338 | 1339 | } |
| 1339 | 1340 | } |
| 1340 | 1341 | } else { |
| 1341 | - for (let i2 = startIndex; i2 < endIndex; i2++) { | |
| 1342 | - if (newFormats[i2]) { | |
| 1343 | - filterFormats(newFormats, i2, formatType); | |
| 1342 | + for (let i = startIndex; i < endIndex; i++) { | |
| 1343 | + if (newFormats[i]) { | |
| 1344 | + filterFormats(newFormats, i, formatType); | |
| 1344 | 1345 | } |
| 1345 | 1346 | } |
| 1346 | 1347 | } |
| 1347 | 1348 | return normaliseFormats({ |
| @@ -1493,10 +1494,10 @@ | ||
| 1493 | 1494 | return [before, after]; |
| 1494 | 1495 | } |
| 1495 | 1496 | |
| 1496 | 1497 | // packages/rich-text/build-module/is-range-equal.mjs |
| 1497 | - function isRangeEqual(a2, b2) { | |
| 1498 | - return a2 === b2 || a2 && b2 && a2.startContainer === b2.startContainer && a2.startOffset === b2.startOffset && a2.endContainer === b2.endContainer && a2.endOffset === b2.endOffset; | |
| 1498 | + function isRangeEqual(a, b) { | |
| 1499 | + return a === b || a && b && a.startContainer === b.startContainer && a.startOffset === b.startOffset && a.endContainer === b.endContainer && a.endOffset === b.endOffset; | |
| 1499 | 1500 | } |
| 1500 | 1501 | |
| 1501 | 1502 | // packages/rich-text/build-module/to-dom.mjs |
| 1502 | 1503 | var MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML"; |
| @@ -1501,13 +1502,13 @@ | ||
| 1501 | 1502 | // packages/rich-text/build-module/to-dom.mjs |
| 1502 | 1503 | var MATHML_NAMESPACE = "http://www.w3.org/1998/Math/MathML"; |
| 1503 | 1504 | function createPathToNode(node, rootNode, path) { |
| 1504 | 1505 | const parentNode = node.parentNode; |
| 1505 | - let i2 = 0; | |
| 1506 | + let i = 0; | |
| 1506 | 1507 | while (node = node.previousSibling) { |
| 1507 | - i2++; | |
| 1508 | + i++; | |
| 1508 | 1509 | } |
| 1509 | - path = [i2, ...path]; | |
| 1510 | + path = [i, ...path]; | |
| 1510 | 1511 | if (parentNode !== rootNode) { |
| 1511 | 1512 | path = createPathToNode(parentNode, rootNode, path); |
| 1512 | 1513 | } |
| 1513 | 1514 | return path; |
| @@ -1641,12 +1642,12 @@ | ||
| 1641 | 1642 | applySelection(selection, current); |
| 1642 | 1643 | } |
| 1643 | 1644 | } |
| 1644 | 1645 | function applyValue(future, current) { |
| 1645 | - let i2 = 0; | |
| 1646 | + let i = 0; | |
| 1646 | 1647 | let futureChild; |
| 1647 | 1648 | while (futureChild = future.firstChild) { |
| 1648 | - const currentChild = current.childNodes[i2]; | |
| 1649 | + const currentChild = current.childNodes[i]; | |
| 1649 | 1650 | if (!currentChild) { |
| 1650 | 1651 | current.appendChild(futureChild); |
| 1651 | 1652 | } else if (!currentChild.isEqualNode(futureChild)) { |
| 1652 | 1653 | if (currentChild.nodeName !== futureChild.nodeName || currentChild.nodeType === currentChild.TEXT_NODE && currentChild.data !== futureChild.data) { |
| @@ -1676,12 +1677,12 @@ | ||
| 1676 | 1677 | } |
| 1677 | 1678 | } else { |
| 1678 | 1679 | future.removeChild(futureChild); |
| 1679 | 1680 | } |
| 1680 | - i2++; | |
| 1681 | + i++; | |
| 1681 | 1682 | } |
| 1682 | - while (current.childNodes[i2]) { | |
| 1683 | - current.removeChild(current.childNodes[i2]); | |
| 1683 | + while (current.childNodes[i]) { | |
| 1684 | + current.removeChild(current.childNodes[i]); | |
| 1684 | 1685 | } |
| 1685 | 1686 | } |
| 1686 | 1687 | function applySelection({ startPath, endPath }, current) { |
| 1687 | 1688 | const { node: startContainer, offset: startOffset } = getNodeByPath( |
| @@ -1749,9 +1750,9 @@ | ||
| 1749 | 1750 | ); |
| 1750 | 1751 | |
| 1751 | 1752 | // packages/rich-text/build-module/hook/index.mjs |
| 1752 | 1753 | var import_element5 = __toESM(require_element(), 1); |
| 1753 | - var import_compose9 = __toESM(require_compose(), 1); | |
| 1754 | + var import_compose8 = __toESM(require_compose(), 1); | |
| 1754 | 1755 | var import_data9 = __toESM(require_data(), 1); |
| 1755 | 1756 | var import_deprecated = __toESM(require_deprecated(), 1); |
| 1756 | 1757 | |
| 1757 | 1758 | // packages/rich-text/build-module/hook/use-default-style.mjs |
| @@ -1766,163 +1767,176 @@ | ||
| 1766 | 1767 | }, []); |
| 1767 | 1768 | } |
| 1768 | 1769 | |
| 1769 | 1770 | // node_modules/colord/index.mjs |
| 1770 | - var r = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }; | |
| 1771 | - var t = function(r2) { | |
| 1771 | + for (r = { grad: 0.9, turn: 360, rad: 360 / (2 * Math.PI) }, t = function(r2) { | |
| 1772 | 1772 | return "string" == typeof r2 ? r2.length > 0 : "number" == typeof r2; |
| 1773 | - }; | |
| 1774 | - var n = function(r2, t2, n2) { | |
| 1773 | + }, n = function(r2, t2, n2) { | |
| 1775 | 1774 | return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = Math.pow(10, t2)), Math.round(n2 * r2) / n2 + 0; |
| 1776 | - }; | |
| 1777 | - var e = function(r2, t2, n2) { | |
| 1775 | + }, u = function(r2, t2, n2) { | |
| 1778 | 1776 | return void 0 === t2 && (t2 = 0), void 0 === n2 && (n2 = 1), r2 > n2 ? n2 : r2 > t2 ? r2 : t2; |
| 1779 | - }; | |
| 1780 | - var u = function(r2) { | |
| 1781 | - return (r2 = isFinite(r2) ? r2 % 360 : 0) > 0 ? r2 : r2 + 360; | |
| 1782 | - }; | |
| 1783 | - var a = function(r2) { | |
| 1784 | - return { r: e(r2.r, 0, 255), g: e(r2.g, 0, 255), b: e(r2.b, 0, 255), a: e(r2.a) }; | |
| 1785 | - }; | |
| 1786 | - var o = function(r2) { | |
| 1777 | + }, e = function(r2) { | |
| 1778 | + return (r2 = isFinite(r2) ? r2 % 360 : 0) < 0 ? r2 + 360 : r2; | |
| 1779 | + }, o = function(r2, t2) { | |
| 1780 | + return void 0 === t2 && (t2 = 0), n(r2, t2) % 360; | |
| 1781 | + }, a = function(r2) { | |
| 1782 | + return { r: u(r2.r, 0, 255), g: u(r2.g, 0, 255), b: u(r2.b, 0, 255), a: u(r2.a) }; | |
| 1783 | + }, i = function(r2) { | |
| 1787 | 1784 | return { r: n(r2.r), g: n(r2.g), b: n(r2.b), a: n(r2.a, 3) }; |
| 1785 | + }, s = /^#([0-9a-f]{3,8})$/i, d = function(r2, t2) { | |
| 1786 | + var n2 = r2.charCodeAt(t2); | |
| 1787 | + return (15 & n2) + 9 * (n2 >> 6); | |
| 1788 | + }, h = function(r2, t2) { | |
| 1789 | + return d(r2, t2) << 4 | d(r2, t2 + 1); | |
| 1790 | + }, b = [], f = 0; f < 256; f++) b.push((f < 16 ? "0" : "") + f.toString(16)); | |
| 1791 | + var r; | |
| 1792 | + var t; | |
| 1793 | + var n; | |
| 1794 | + var u; | |
| 1795 | + var e; | |
| 1796 | + var o; | |
| 1797 | + var a; | |
| 1798 | + var i; | |
| 1799 | + var s; | |
| 1800 | + var d; | |
| 1801 | + var h; | |
| 1802 | + var b; | |
| 1803 | + var f; | |
| 1804 | + var g = function(r) { | |
| 1805 | + return b[u(r, 0, 255)]; | |
| 1788 | 1806 | }; |
| 1789 | - var i = /^#([0-9a-f]{3,8})$/i; | |
| 1790 | - var s = function(r2) { | |
| 1791 | - var t2 = r2.toString(16); | |
| 1792 | - return t2.length < 2 ? "0" + t2 : t2; | |
| 1807 | + var c = function(r) { | |
| 1808 | + var t = r.r, n = r.g, u = r.b, e = r.a, o = Math.max(t, n, u), a = o - Math.min(t, n, u), i = a ? o === t ? (n - u) / a : o === n ? 2 + (u - t) / a : 4 + (t - n) / a : 0; | |
| 1809 | + return { h: 60 * (i < 0 ? i + 6 : i), s: o ? a / o * 100 : 0, v: o / 255 * 100, a: e }; | |
| 1793 | 1810 | }; |
| 1794 | - var h = function(r2) { | |
| 1795 | - var t2 = r2.r, n2 = r2.g, e2 = r2.b, u2 = r2.a, a2 = Math.max(t2, n2, e2), o2 = a2 - Math.min(t2, n2, e2), i2 = o2 ? a2 === t2 ? (n2 - e2) / o2 : a2 === n2 ? 2 + (e2 - t2) / o2 : 4 + (t2 - n2) / o2 : 0; | |
| 1796 | - return { h: 60 * (i2 < 0 ? i2 + 6 : i2), s: a2 ? o2 / a2 * 100 : 0, v: a2 / 255 * 100, a: u2 }; | |
| 1811 | + var v = function(r) { | |
| 1812 | + var t = r.h, n = r.s, u = r.v, e = r.a; | |
| 1813 | + t = t / 360 * 6, n /= 100, u /= 100; | |
| 1814 | + var o = Math.floor(t), a = u * (1 - n), i = u * (1 - (t - o) * n), s = u * (1 - (1 - t + o) * n), d = o % 6; | |
| 1815 | + return { r: 255 * [u, i, a, a, s, u][d], g: 255 * [s, u, u, i, a, a][d], b: 255 * [a, a, s, u, u, i][d], a: e }; | |
| 1797 | 1816 | }; |
| 1798 | - var b = function(r2) { | |
| 1799 | - var t2 = r2.h, n2 = r2.s, e2 = r2.v, u2 = r2.a; | |
| 1800 | - t2 = t2 / 360 * 6, n2 /= 100, e2 /= 100; | |
| 1801 | - var a2 = Math.floor(t2), o2 = e2 * (1 - n2), i2 = e2 * (1 - (t2 - a2) * n2), s2 = e2 * (1 - (1 - t2 + a2) * n2), h2 = a2 % 6; | |
| 1802 | - return { r: 255 * [e2, i2, o2, o2, s2, e2][h2], g: 255 * [s2, e2, e2, i2, o2, o2][h2], b: 255 * [o2, o2, s2, e2, e2, i2][h2], a: u2 }; | |
| 1817 | + var l = function(r) { | |
| 1818 | + return { h: e(r.h), s: u(r.s, 0, 100), l: u(r.l, 0, 100), a: u(r.a) }; | |
| 1803 | 1819 | }; |
| 1804 | - var g = function(r2) { | |
| 1805 | - return { h: u(r2.h), s: e(r2.s, 0, 100), l: e(r2.l, 0, 100), a: e(r2.a) }; | |
| 1820 | + var p = function(r) { | |
| 1821 | + return { h: o(r.h), s: n(r.s), l: n(r.l), a: n(r.a, 3) }; | |
| 1806 | 1822 | }; |
| 1807 | - var d = function(r2) { | |
| 1808 | - return { h: n(r2.h), s: n(r2.s), l: n(r2.l), a: n(r2.a, 3) }; | |
| 1823 | + var m = function(r) { | |
| 1824 | + return v((n = (t = r).s, { h: t.h, s: (n *= ((u = t.l) < 50 ? u : 100 - u) / 100) > 0 ? 2 * n / (u + n) * 100 : 0, v: u + n, a: t.a })); | |
| 1825 | + var t, n, u; | |
| 1809 | 1826 | }; |
| 1810 | - var f = function(r2) { | |
| 1811 | - return b((n2 = (t2 = r2).s, { h: t2.h, s: (n2 *= ((e2 = t2.l) < 50 ? e2 : 100 - e2) / 100) > 0 ? 2 * n2 / (e2 + n2) * 100 : 0, v: e2 + n2, a: t2.a })); | |
| 1812 | - var t2, n2, e2; | |
| 1827 | + var y = function(r) { | |
| 1828 | + return { h: (t = c(r)).h, s: (e = (200 - (n = t.s)) * (u = t.v) / 100) > 0 && e < 200 ? n * u / 100 / (e <= 100 ? e : 200 - e) * 100 : 0, l: e / 2, a: t.a }; | |
| 1829 | + var t, n, u, e; | |
| 1813 | 1830 | }; |
| 1814 | - var c = function(r2) { | |
| 1815 | - return { h: (t2 = h(r2)).h, s: (u2 = (200 - (n2 = t2.s)) * (e2 = t2.v) / 100) > 0 && u2 < 200 ? n2 * e2 / 100 / (u2 <= 100 ? u2 : 200 - u2) * 100 : 0, l: u2 / 2, a: t2.a }; | |
| 1816 | - var t2, n2, e2, u2; | |
| 1817 | - }; | |
| 1818 | - var l = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i; | |
| 1819 | - var p = /^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i; | |
| 1820 | - var v = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i; | |
| 1821 | - var m = /^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i; | |
| 1822 | - var y = { string: [[function(r2) { | |
| 1823 | - var t2 = i.exec(r2); | |
| 1824 | - return t2 ? (r2 = t2[1]).length <= 4 ? { r: parseInt(r2[0] + r2[0], 16), g: parseInt(r2[1] + r2[1], 16), b: parseInt(r2[2] + r2[2], 16), a: 4 === r2.length ? n(parseInt(r2[3] + r2[3], 16) / 255, 2) : 1 } : 6 === r2.length || 8 === r2.length ? { r: parseInt(r2.substr(0, 2), 16), g: parseInt(r2.substr(2, 2), 16), b: parseInt(r2.substr(4, 2), 16), a: 8 === r2.length ? n(parseInt(r2.substr(6, 2), 16) / 255, 2) : 1 } : null : null; | |
| 1825 | - }, "hex"], [function(r2) { | |
| 1826 | - var t2 = v.exec(r2) || m.exec(r2); | |
| 1827 | - return t2 ? t2[2] !== t2[4] || t2[4] !== t2[6] ? null : a({ r: Number(t2[1]) / (t2[2] ? 100 / 255 : 1), g: Number(t2[3]) / (t2[4] ? 100 / 255 : 1), b: Number(t2[5]) / (t2[6] ? 100 / 255 : 1), a: void 0 === t2[7] ? 1 : Number(t2[7]) / (t2[8] ? 100 : 1) }) : null; | |
| 1828 | - }, "rgb"], [function(t2) { | |
| 1829 | - var n2 = l.exec(t2) || p.exec(t2); | |
| 1830 | - if (!n2) return null; | |
| 1831 | - var e2, u2, a2 = g({ h: (e2 = n2[1], u2 = n2[2], void 0 === u2 && (u2 = "deg"), Number(e2) * (r[u2] || 1)), s: Number(n2[3]), l: Number(n2[4]), a: void 0 === n2[5] ? 1 : Number(n2[5]) / (n2[6] ? 100 : 1) }); | |
| 1832 | - return f(a2); | |
| 1833 | - }, "hsl"]], object: [[function(r2) { | |
| 1834 | - var n2 = r2.r, e2 = r2.g, u2 = r2.b, o2 = r2.a, i2 = void 0 === o2 ? 1 : o2; | |
| 1835 | - return t(n2) && t(e2) && t(u2) ? a({ r: Number(n2), g: Number(e2), b: Number(u2), a: Number(i2) }) : null; | |
| 1836 | - }, "rgb"], [function(r2) { | |
| 1837 | - var n2 = r2.h, e2 = r2.s, u2 = r2.l, a2 = r2.a, o2 = void 0 === a2 ? 1 : a2; | |
| 1838 | - if (!t(n2) || !t(e2) || !t(u2)) return null; | |
| 1839 | - var i2 = g({ h: Number(n2), s: Number(e2), l: Number(u2), a: Number(o2) }); | |
| 1840 | - return f(i2); | |
| 1841 | - }, "hsl"], [function(r2) { | |
| 1842 | - var n2 = r2.h, a2 = r2.s, o2 = r2.v, i2 = r2.a, s2 = void 0 === i2 ? 1 : i2; | |
| 1843 | - if (!t(n2) || !t(a2) || !t(o2)) return null; | |
| 1844 | - var h2 = (function(r3) { | |
| 1845 | - return { h: u(r3.h), s: e(r3.s, 0, 100), v: e(r3.v, 0, 100), a: e(r3.a) }; | |
| 1846 | - })({ h: Number(n2), s: Number(a2), v: Number(o2), a: Number(s2) }); | |
| 1847 | - return b(h2); | |
| 1831 | + var N = /^hsla?\(\s*([+-]?(?:\d*\.\d+|\d+))(deg|rad|grad|turn)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))%\s*,\s*([+-]?(?:\d*\.\d+|\d+))%\s*(?:,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i; | |
| 1832 | + var x = /^hsla?\(\s*([+-]?(?:\d*\.\d+|\d+))(deg|rad|grad|turn)?\s+([+-]?(?:\d*\.\d+|\d+))%\s+([+-]?(?:\d*\.\d+|\d+))%\s*(?:\/\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i; | |
| 1833 | + var M = /^rgba?\(\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*(?:,\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i; | |
| 1834 | + var H = /^rgba?\(\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s+([+-]?(?:\d*\.\d+|\d+))(%)?\s+([+-]?(?:\d*\.\d+|\d+))(%)?\s*(?:\/\s*([+-]?(?:\d*\.\d+|\d+))(%)?\s*)?\)$/i; | |
| 1835 | + var $ = { string: [[function(r) { | |
| 1836 | + if (!s.test(r)) return null; | |
| 1837 | + var t = r.length; | |
| 1838 | + return t <= 5 ? { r: 17 * d(r, 1), g: 17 * d(r, 2), b: 17 * d(r, 3), a: 5 === t ? n(17 * d(r, 4) / 255, 2) : 1 } : 7 === t || 9 === t ? { r: h(r, 1), g: h(r, 3), b: h(r, 5), a: 9 === t ? n(h(r, 7) / 255, 2) : 1 } : null; | |
| 1839 | + }, "hex"], [function(r) { | |
| 1840 | + var t = M.exec(r) || H.exec(r); | |
| 1841 | + return t ? t[2] !== t[4] || t[4] !== t[6] ? null : a({ r: Number(t[1]) / (t[2] ? 100 / 255 : 1), g: Number(t[3]) / (t[4] ? 100 / 255 : 1), b: Number(t[5]) / (t[6] ? 100 / 255 : 1), a: void 0 === t[7] ? 1 : Number(t[7]) / (t[8] ? 100 : 1) }) : null; | |
| 1842 | + }, "rgb"], [function(t) { | |
| 1843 | + var n = N.exec(t) || x.exec(t); | |
| 1844 | + if (!n) return null; | |
| 1845 | + var u, e, o = l({ h: (u = n[1], e = n[2], void 0 === e && (e = "deg"), Number(u) * (r[e] || 1)), s: Number(n[3]), l: Number(n[4]), a: void 0 === n[5] ? 1 : Number(n[5]) / (n[6] ? 100 : 1) }); | |
| 1846 | + return m(o); | |
| 1847 | + }, "hsl"]], object: [[function(r) { | |
| 1848 | + var n = r.r, u = r.g, e = r.b, o = r.a, i = void 0 === o ? 1 : o; | |
| 1849 | + return t(n) && t(u) && t(e) ? a({ r: Number(n), g: Number(u), b: Number(e), a: Number(i) }) : null; | |
| 1850 | + }, "rgb"], [function(r) { | |
| 1851 | + var n = r.h, u = r.s, e = r.l, o = r.a, a = void 0 === o ? 1 : o; | |
| 1852 | + if (!t(n) || !t(u) || !t(e)) return null; | |
| 1853 | + var i = l({ h: Number(n), s: Number(u), l: Number(e), a: Number(a) }); | |
| 1854 | + return m(i); | |
| 1855 | + }, "hsl"], [function(r) { | |
| 1856 | + var n = r.h, o = r.s, a = r.v, i = r.a, s = void 0 === i ? 1 : i; | |
| 1857 | + if (!t(n) || !t(o) || !t(a)) return null; | |
| 1858 | + var d = (function(r2) { | |
| 1859 | + return { h: e(r2.h), s: u(r2.s, 0, 100), v: u(r2.v, 0, 100), a: u(r2.a) }; | |
| 1860 | + })({ h: Number(n), s: Number(o), v: Number(a), a: Number(s) }); | |
| 1861 | + return v(d); | |
| 1848 | 1862 | }, "hsv"]] }; |
| 1849 | - var N = function(r2, t2) { | |
| 1850 | - for (var n2 = 0; n2 < t2.length; n2++) { | |
| 1851 | - var e2 = t2[n2][0](r2); | |
| 1852 | - if (e2) return [e2, t2[n2][1]]; | |
| 1863 | + var j = function(r, t) { | |
| 1864 | + for (var n = 0; n < t.length; n++) { | |
| 1865 | + var u = t[n][0](r); | |
| 1866 | + if (u) return [u, t[n][1]]; | |
| 1853 | 1867 | } |
| 1854 | 1868 | return [null, void 0]; |
| 1855 | 1869 | }; |
| 1856 | - var x = function(r2) { | |
| 1857 | - return "string" == typeof r2 ? N(r2.trim(), y.string) : "object" == typeof r2 && null !== r2 ? N(r2, y.object) : [null, void 0]; | |
| 1870 | + var w = function(r) { | |
| 1871 | + return "string" == typeof r ? j(r.trim(), $.string) : "object" == typeof r && null !== r ? j(r, $.object) : [null, void 0]; | |
| 1858 | 1872 | }; |
| 1859 | - var M = function(r2, t2) { | |
| 1860 | - var n2 = c(r2); | |
| 1861 | - return { h: n2.h, s: e(n2.s + 100 * t2, 0, 100), l: n2.l, a: n2.a }; | |
| 1873 | + var k = function(r, t) { | |
| 1874 | + var n = y(r); | |
| 1875 | + return { h: n.h, s: u(n.s + 100 * t, 0, 100), l: n.l, a: n.a }; | |
| 1862 | 1876 | }; |
| 1863 | - var H = function(r2) { | |
| 1864 | - return (299 * r2.r + 587 * r2.g + 114 * r2.b) / 1e3 / 255; | |
| 1877 | + var E = function(r) { | |
| 1878 | + return (299 * r.r + 587 * r.g + 114 * r.b) / 1e3 / 255; | |
| 1865 | 1879 | }; |
| 1866 | - var $ = function(r2, t2) { | |
| 1867 | - var n2 = c(r2); | |
| 1868 | - return { h: n2.h, s: n2.s, l: e(n2.l + 100 * t2, 0, 100), a: n2.a }; | |
| 1880 | + var R = function(r, t) { | |
| 1881 | + var n = y(r); | |
| 1882 | + return { h: n.h, s: n.s, l: u(n.l + 100 * t, 0, 100), a: n.a }; | |
| 1869 | 1883 | }; |
| 1870 | - var j = (function() { | |
| 1871 | - function r2(r3) { | |
| 1872 | - this.parsed = x(r3)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 }; | |
| 1884 | + var q = (function() { | |
| 1885 | + function r(r2) { | |
| 1886 | + this.parsed = w(r2)[0], this.rgba = this.parsed || { r: 0, g: 0, b: 0, a: 1 }; | |
| 1873 | 1887 | } |
| 1874 | - return r2.prototype.isValid = function() { | |
| 1888 | + return r.prototype.isValid = function() { | |
| 1875 | 1889 | return null !== this.parsed; |
| 1876 | - }, r2.prototype.brightness = function() { | |
| 1877 | - return n(H(this.rgba), 2); | |
| 1878 | - }, r2.prototype.isDark = function() { | |
| 1879 | - return H(this.rgba) < 0.5; | |
| 1880 | - }, r2.prototype.isLight = function() { | |
| 1881 | - return H(this.rgba) >= 0.5; | |
| 1882 | - }, r2.prototype.toHex = function() { | |
| 1883 | - return r3 = o(this.rgba), t2 = r3.r, e2 = r3.g, u2 = r3.b, i2 = (a2 = r3.a) < 1 ? s(n(255 * a2)) : "", "#" + s(t2) + s(e2) + s(u2) + i2; | |
| 1884 | - var r3, t2, e2, u2, a2, i2; | |
| 1885 | - }, r2.prototype.toRgb = function() { | |
| 1886 | - return o(this.rgba); | |
| 1887 | - }, r2.prototype.toRgbString = function() { | |
| 1888 | - return r3 = o(this.rgba), t2 = r3.r, n2 = r3.g, e2 = r3.b, (u2 = r3.a) < 1 ? "rgba(" + t2 + ", " + n2 + ", " + e2 + ", " + u2 + ")" : "rgb(" + t2 + ", " + n2 + ", " + e2 + ")"; | |
| 1889 | - var r3, t2, n2, e2, u2; | |
| 1890 | - }, r2.prototype.toHsl = function() { | |
| 1891 | - return d(c(this.rgba)); | |
| 1892 | - }, r2.prototype.toHslString = function() { | |
| 1893 | - return r3 = d(c(this.rgba)), t2 = r3.h, n2 = r3.s, e2 = r3.l, (u2 = r3.a) < 1 ? "hsla(" + t2 + ", " + n2 + "%, " + e2 + "%, " + u2 + ")" : "hsl(" + t2 + ", " + n2 + "%, " + e2 + "%)"; | |
| 1894 | - var r3, t2, n2, e2, u2; | |
| 1895 | - }, r2.prototype.toHsv = function() { | |
| 1896 | - return r3 = h(this.rgba), { h: n(r3.h), s: n(r3.s), v: n(r3.v), a: n(r3.a, 3) }; | |
| 1897 | - var r3; | |
| 1898 | - }, r2.prototype.invert = function() { | |
| 1899 | - return w({ r: 255 - (r3 = this.rgba).r, g: 255 - r3.g, b: 255 - r3.b, a: r3.a }); | |
| 1900 | - var r3; | |
| 1901 | - }, r2.prototype.saturate = function(r3) { | |
| 1902 | - return void 0 === r3 && (r3 = 0.1), w(M(this.rgba, r3)); | |
| 1903 | - }, r2.prototype.desaturate = function(r3) { | |
| 1904 | - return void 0 === r3 && (r3 = 0.1), w(M(this.rgba, -r3)); | |
| 1905 | - }, r2.prototype.grayscale = function() { | |
| 1906 | - return w(M(this.rgba, -1)); | |
| 1907 | - }, r2.prototype.lighten = function(r3) { | |
| 1908 | - return void 0 === r3 && (r3 = 0.1), w($(this.rgba, r3)); | |
| 1909 | - }, r2.prototype.darken = function(r3) { | |
| 1910 | - return void 0 === r3 && (r3 = 0.1), w($(this.rgba, -r3)); | |
| 1911 | - }, r2.prototype.rotate = function(r3) { | |
| 1912 | - return void 0 === r3 && (r3 = 15), this.hue(this.hue() + r3); | |
| 1913 | - }, r2.prototype.alpha = function(r3) { | |
| 1914 | - return "number" == typeof r3 ? w({ r: (t2 = this.rgba).r, g: t2.g, b: t2.b, a: r3 }) : n(this.rgba.a, 3); | |
| 1915 | - var t2; | |
| 1916 | - }, r2.prototype.hue = function(r3) { | |
| 1917 | - var t2 = c(this.rgba); | |
| 1918 | - return "number" == typeof r3 ? w({ h: r3, s: t2.s, l: t2.l, a: t2.a }) : n(t2.h); | |
| 1919 | - }, r2.prototype.isEqual = function(r3) { | |
| 1920 | - return this.toHex() === w(r3).toHex(); | |
| 1921 | - }, r2; | |
| 1890 | + }, r.prototype.brightness = function() { | |
| 1891 | + return n(E(this.rgba), 2); | |
| 1892 | + }, r.prototype.isDark = function() { | |
| 1893 | + return E(this.rgba) < 0.5; | |
| 1894 | + }, r.prototype.isLight = function() { | |
| 1895 | + return E(this.rgba) >= 0.5; | |
| 1896 | + }, r.prototype.toHex = function() { | |
| 1897 | + return r2 = i(this.rgba), t = r2.r, u = r2.g, e = r2.b, a = (o = r2.a) < 1 ? g(n(255 * o)) : "", "#" + g(t) + g(u) + g(e) + a; | |
| 1898 | + var r2, t, u, e, o, a; | |
| 1899 | + }, r.prototype.toRgb = function() { | |
| 1900 | + return i(this.rgba); | |
| 1901 | + }, r.prototype.toRgbString = function() { | |
| 1902 | + return r2 = i(this.rgba), t = r2.r, n = r2.g, u = r2.b, (e = r2.a) < 1 ? "rgba(" + t + ", " + n + ", " + u + ", " + e + ")" : "rgb(" + t + ", " + n + ", " + u + ")"; | |
| 1903 | + var r2, t, n, u, e; | |
| 1904 | + }, r.prototype.toHsl = function() { | |
| 1905 | + return p(y(this.rgba)); | |
| 1906 | + }, r.prototype.toHslString = function() { | |
| 1907 | + return r2 = p(y(this.rgba)), t = r2.h, n = r2.s, u = r2.l, (e = r2.a) < 1 ? "hsla(" + t + ", " + n + "%, " + u + "%, " + e + ")" : "hsl(" + t + ", " + n + "%, " + u + "%)"; | |
| 1908 | + var r2, t, n, u, e; | |
| 1909 | + }, r.prototype.toHsv = function() { | |
| 1910 | + return r2 = c(this.rgba), { h: o(r2.h), s: n(r2.s), v: n(r2.v), a: n(r2.a, 3) }; | |
| 1911 | + var r2; | |
| 1912 | + }, r.prototype.invert = function() { | |
| 1913 | + return A({ r: 255 - (r2 = this.rgba).r, g: 255 - r2.g, b: 255 - r2.b, a: r2.a }); | |
| 1914 | + var r2; | |
| 1915 | + }, r.prototype.saturate = function(r2) { | |
| 1916 | + return void 0 === r2 && (r2 = 0.1), A(k(this.rgba, r2)); | |
| 1917 | + }, r.prototype.desaturate = function(r2) { | |
| 1918 | + return void 0 === r2 && (r2 = 0.1), A(k(this.rgba, -r2)); | |
| 1919 | + }, r.prototype.grayscale = function() { | |
| 1920 | + return A(k(this.rgba, -1)); | |
| 1921 | + }, r.prototype.lighten = function(r2) { | |
| 1922 | + return void 0 === r2 && (r2 = 0.1), A(R(this.rgba, r2)); | |
| 1923 | + }, r.prototype.darken = function(r2) { | |
| 1924 | + return void 0 === r2 && (r2 = 0.1), A(R(this.rgba, -r2)); | |
| 1925 | + }, r.prototype.rotate = function(r2) { | |
| 1926 | + return void 0 === r2 && (r2 = 15), this.hue(y(this.rgba).h + r2); | |
| 1927 | + }, r.prototype.alpha = function(r2) { | |
| 1928 | + return "number" == typeof r2 ? A({ r: (t = this.rgba).r, g: t.g, b: t.b, a: r2 }) : n(this.rgba.a, 3); | |
| 1929 | + var t; | |
| 1930 | + }, r.prototype.hue = function(r2) { | |
| 1931 | + var t = y(this.rgba); | |
| 1932 | + return "number" == typeof r2 ? A({ h: r2, s: t.s, l: t.l, a: t.a }) : o(t.h); | |
| 1933 | + }, r.prototype.isEqual = function(r2) { | |
| 1934 | + return this.toHex() === A(r2).toHex(); | |
| 1935 | + }, r; | |
| 1922 | 1936 | })(); |
| 1923 | - var w = function(r2) { | |
| 1924 | - return r2 instanceof j ? r2 : new j(r2); | |
| 1937 | + var A = function(r) { | |
| 1938 | + return r instanceof q ? r : new q(r); | |
| 1925 | 1939 | }; |
| 1926 | 1940 | |
| 1927 | 1941 | // packages/rich-text/build-module/hook/use-boundary-style.mjs |
| 1928 | 1942 | var import_element2 = __toESM(require_element(), 1); |
| @@ -1941,10 +1955,10 @@ | ||
| 1941 | 1955 | } |
| 1942 | 1956 | const { ownerDocument } = element; |
| 1943 | 1957 | const { defaultView } = ownerDocument; |
| 1944 | 1958 | const computedStyle = defaultView.getComputedStyle(element); |
| 1945 | - const newColor = w(computedStyle.color).alpha(0.2).toRgbString(); | |
| 1946 | - const selector = `.rich-text:focus ${boundarySelector}`; | |
| 1959 | + const newColor = A(computedStyle.color).alpha(0.2).toRgbString(); | |
| 1960 | + const selector = `[contenteditable="true"]:focus ${boundarySelector}`; | |
| 1947 | 1961 | const rule = `background-color: ${newColor}`; |
| 1948 | 1962 | const style = `${selector} {${rule}}`; |
| 1949 | 1963 | const globalStyleId = "rich-text-boundary-style"; |
| 1950 | 1964 | let globalStyle = ownerDocument.getElementById(globalStyleId); |
| @@ -1961,18 +1975,40 @@ | ||
| 1961 | 1975 | } |
| 1962 | 1976 | |
| 1963 | 1977 | // packages/rich-text/build-module/hook/event-listeners/index.mjs |
| 1964 | 1978 | var import_element3 = __toESM(require_element(), 1); |
| 1965 | - var import_compose8 = __toESM(require_compose(), 1); | |
| 1979 | + var import_compose7 = __toESM(require_compose(), 1); | |
| 1966 | 1980 | |
| 1967 | 1981 | // packages/rich-text/build-module/hook/event-listeners/copy-handler.mjs |
| 1968 | 1982 | var import_compose = __toESM(require_compose(), 1); |
| 1983 | + | |
| 1984 | + // packages/rich-text/build-module/owns-selection.mjs | |
| 1985 | + function ownsSelection(element) { | |
| 1986 | + const { ownerDocument } = element; | |
| 1987 | + const { activeElement } = ownerDocument; | |
| 1988 | + if (activeElement === element) { | |
| 1989 | + return true; | |
| 1990 | + } | |
| 1991 | + if (!activeElement || activeElement.contentEditable !== "true" || element.contentEditable !== "true" || !activeElement.contains(element)) { | |
| 1992 | + return false; | |
| 1993 | + } | |
| 1994 | + const selection = ownerDocument.defaultView.getSelection(); | |
| 1995 | + const { anchorNode, focusNode } = selection; | |
| 1996 | + return !!anchorNode && !!focusNode && element.contains(anchorNode) && element.contains(focusNode); | |
| 1997 | + } | |
| 1998 | + | |
| 1999 | + // packages/rich-text/build-module/hook/event-listeners/copy-handler.mjs | |
| 1969 | 2000 | var { subscribeDelegatedListener } = unlock(import_compose.privateApis); |
| 1970 | 2001 | var copy_handler_default = (props) => (element) => { |
| 1971 | 2002 | function onCopy(event) { |
| 1972 | - const { record } = props.current; | |
| 2003 | + const { record, handleChange } = props.current; | |
| 1973 | 2004 | const { ownerDocument } = element; |
| 1974 | - if (isCollapsed(record.current) || !element.contains(ownerDocument.activeElement)) { | |
| 2005 | + if ( | |
| 2006 | + // Another handler may have already claimed the clipboard, e.g. | |
| 2007 | + // the block editor copying the whole block when its entire | |
| 2008 | + // text is selected. | |
| 2009 | + event.defaultPrevented || isCollapsed(record.current) || !element.contains(ownerDocument.activeElement) && !ownsSelection(element) | |
| 2010 | + ) { | |
| 1975 | 2011 | return; |
| 1976 | 2012 | } |
| 1977 | 2013 | const selectedRecord = slice(record.current); |
| 1978 | 2014 | const plainText = getTextContent(selectedRecord); |
| @@ -1981,9 +2017,9 @@ | ||
| 1981 | 2017 | event.clipboardData.setData("text/html", html); |
| 1982 | 2018 | event.clipboardData.setData("rich-text", "true"); |
| 1983 | 2019 | event.preventDefault(); |
| 1984 | 2020 | if (event.type === "cut") { |
| 1985 | - ownerDocument.execCommand("delete"); | |
| 2021 | + handleChange(remove2(record.current)); | |
| 1986 | 2022 | } |
| 1987 | 2023 | } |
| 1988 | 2024 | const { defaultView } = element.ownerDocument; |
| 1989 | 2025 | const unsubscribeCopy = subscribeDelegatedListener( |
| @@ -2024,9 +2060,9 @@ | ||
| 2024 | 2060 | selection.addRange(range); |
| 2025 | 2061 | event.preventDefault(); |
| 2026 | 2062 | } |
| 2027 | 2063 | function onFocusIn(event) { |
| 2028 | - if (event.relatedTarget && !element.contains(event.relatedTarget) && event.relatedTarget.tagName === "A") { | |
| 2064 | + if (event.relatedTarget && !element.contains(event.relatedTarget)) { | |
| 2029 | 2065 | onClick(event); |
| 2030 | 2066 | } |
| 2031 | 2067 | } |
| 2032 | 2068 | const unsubscribeClick = subscribeDelegatedListener2( |
| @@ -2046,10 +2082,55 @@ | ||
| 2046 | 2082 | }; |
| 2047 | 2083 | |
| 2048 | 2084 | // packages/rich-text/build-module/hook/event-listeners/format-boundaries.mjs |
| 2049 | 2085 | var import_keycodes = __toESM(require_keycodes(), 1); |
| 2086 | + | |
| 2087 | + // packages/rich-text/build-module/subscribe-owned-listener.mjs | |
| 2050 | 2088 | var import_compose3 = __toESM(require_compose(), 1); |
| 2051 | 2089 | var { subscribeDelegatedListener: subscribeDelegatedListener3 } = unlock(import_compose3.privateApis); |
| 2090 | + var registries = /* @__PURE__ */ new WeakMap(); | |
| 2091 | + function subscribeOwnedListener(element, eventType, callback, capture = false) { | |
| 2092 | + const { ownerDocument } = element; | |
| 2093 | + let byEvent = registries.get(ownerDocument); | |
| 2094 | + if (!byEvent) { | |
| 2095 | + byEvent = /* @__PURE__ */ new Map(); | |
| 2096 | + registries.set(ownerDocument, byEvent); | |
| 2097 | + } | |
| 2098 | + const key = capture ? `${eventType}:capture` : eventType; | |
| 2099 | + let elements = byEvent.get(key); | |
| 2100 | + if (!elements) { | |
| 2101 | + elements = /* @__PURE__ */ new WeakMap(); | |
| 2102 | + byEvent.set(key, elements); | |
| 2103 | + subscribeDelegatedListener3( | |
| 2104 | + ownerDocument, | |
| 2105 | + eventType, | |
| 2106 | + (event) => { | |
| 2107 | + const { defaultView, activeElement } = ownerDocument; | |
| 2108 | + const anchorNode = defaultView?.getSelection()?.anchorNode; | |
| 2109 | + for (let node = anchorNode ?? activeElement; node; node = node.parentNode) { | |
| 2110 | + const callbacks = elements.get(node); | |
| 2111 | + if (callbacks && ownsSelection(node)) { | |
| 2112 | + for (const cb of callbacks) { | |
| 2113 | + cb(event); | |
| 2114 | + } | |
| 2115 | + } | |
| 2116 | + } | |
| 2117 | + }, | |
| 2118 | + capture | |
| 2119 | + ); | |
| 2120 | + } | |
| 2121 | + let set = elements.get(element); | |
| 2122 | + if (!set) { | |
| 2123 | + set = /* @__PURE__ */ new Set(); | |
| 2124 | + elements.set(element, set); | |
| 2125 | + } | |
| 2126 | + set.add(callback); | |
| 2127 | + return () => { | |
| 2128 | + set.delete(callback); | |
| 2129 | + }; | |
| 2130 | + } | |
| 2131 | + | |
| 2132 | + // packages/rich-text/build-module/hook/event-listeners/format-boundaries.mjs | |
| 2052 | 2133 | var EMPTY_ACTIVE_FORMATS = []; |
| 2053 | 2134 | var format_boundaries_default = (props) => (element) => { |
| 2054 | 2135 | function onKeyDown(event) { |
| 2055 | 2136 | const { keyCode, shiftKey, altKey, metaKey, ctrlKey } = event; |
| @@ -2110,15 +2191,13 @@ | ||
| 2110 | 2191 | record.current = newValue; |
| 2111 | 2192 | applyRecord(newValue); |
| 2112 | 2193 | forceRender(); |
| 2113 | 2194 | } |
| 2114 | - return subscribeDelegatedListener3(element, "keydown", onKeyDown, true); | |
| 2195 | + return subscribeOwnedListener(element, "keydown", onKeyDown, true); | |
| 2115 | 2196 | }; |
| 2116 | 2197 | |
| 2117 | 2198 | // packages/rich-text/build-module/hook/event-listeners/delete.mjs |
| 2118 | 2199 | var import_keycodes2 = __toESM(require_keycodes(), 1); |
| 2119 | - var import_compose4 = __toESM(require_compose(), 1); | |
| 2120 | - var { subscribeDelegatedListener: subscribeDelegatedListener4 } = unlock(import_compose4.privateApis); | |
| 2121 | 2200 | var delete_default = (props) => (element) => { |
| 2122 | 2201 | function onKeyDown(event) { |
| 2123 | 2202 | const { keyCode } = event; |
| 2124 | 2203 | if (event.defaultPrevented) { |
| @@ -2134,13 +2213,13 @@ | ||
| 2134 | 2213 | handleChange(remove2(currentValue)); |
| 2135 | 2214 | event.preventDefault(); |
| 2136 | 2215 | } |
| 2137 | 2216 | } |
| 2138 | - return subscribeDelegatedListener4(element, "keydown", onKeyDown); | |
| 2217 | + return subscribeOwnedListener(element, "keydown", onKeyDown); | |
| 2139 | 2218 | }; |
| 2140 | 2219 | |
| 2141 | 2220 | // packages/rich-text/build-module/hook/event-listeners/input-and-selection.mjs |
| 2142 | - var import_compose5 = __toESM(require_compose(), 1); | |
| 2221 | + var import_compose4 = __toESM(require_compose(), 1); | |
| 2143 | 2222 | |
| 2144 | 2223 | // packages/rich-text/build-module/update-formats.mjs |
| 2145 | 2224 | function updateFormats({ value, start, end, formats }) { |
| 2146 | 2225 | const min = Math.min(start, end); |
| @@ -2169,9 +2248,9 @@ | ||
| 2169 | 2248 | return value; |
| 2170 | 2249 | } |
| 2171 | 2250 | |
| 2172 | 2251 | // packages/rich-text/build-module/hook/event-listeners/input-and-selection.mjs |
| 2173 | - var { subscribeDelegatedListener: subscribeDelegatedListener5 } = unlock(import_compose5.privateApis); | |
| 2252 | + var { subscribeDelegatedListener: subscribeDelegatedListener4 } = unlock(import_compose4.privateApis); | |
| 2174 | 2253 | var INSERTION_INPUT_TYPES_TO_IGNORE = /* @__PURE__ */ new Set([ |
| 2175 | 2254 | "insertParagraph", |
| 2176 | 2255 | "insertOrderedList", |
| 2177 | 2256 | "insertUnorderedList", |
| @@ -2179,24 +2258,19 @@ | ||
| 2179 | 2258 | "insertLink" |
| 2180 | 2259 | ]); |
| 2181 | 2260 | var EMPTY_ACTIVE_FORMATS2 = []; |
| 2182 | 2261 | var PLACEHOLDER_ATTR_NAME = "data-rich-text-placeholder"; |
| 2183 | - function fixPlaceholderSelection(defaultView) { | |
| 2184 | - const selection = defaultView.getSelection(); | |
| 2185 | - const { anchorNode, anchorOffset } = selection; | |
| 2186 | - if (anchorNode.nodeType !== anchorNode.ELEMENT_NODE) { | |
| 2187 | - return; | |
| 2188 | - } | |
| 2189 | - const targetNode = anchorNode.childNodes[anchorOffset]; | |
| 2190 | - if (!targetNode || targetNode.nodeType !== targetNode.ELEMENT_NODE || !targetNode.hasAttribute(PLACEHOLDER_ATTR_NAME)) { | |
| 2191 | - return; | |
| 2192 | - } | |
| 2193 | - selection.collapseToStart(); | |
| 2194 | - } | |
| 2195 | 2262 | var input_and_selection_default = (props) => (element) => { |
| 2196 | 2263 | const { ownerDocument } = element; |
| 2197 | 2264 | const { defaultView } = ownerDocument; |
| 2198 | 2265 | let isComposing = false; |
| 2266 | + let isPointerDown = false; | |
| 2267 | + function onPointerDown() { | |
| 2268 | + isPointerDown = true; | |
| 2269 | + } | |
| 2270 | + function onPointerUp() { | |
| 2271 | + isPointerDown = false; | |
| 2272 | + } | |
| 2199 | 2273 | function onInput(event) { |
| 2200 | 2274 | if (isComposing) { |
| 2201 | 2275 | return; |
| 2202 | 2276 | } |
| @@ -2219,33 +2293,42 @@ | ||
| 2219 | 2293 | formats: clearFormats ? [] : oldActiveFormats |
| 2220 | 2294 | }); |
| 2221 | 2295 | handleChange(change); |
| 2222 | 2296 | } |
| 2297 | + let selectionSnapshot; | |
| 2223 | 2298 | function handleSelectionChange() { |
| 2224 | 2299 | const { record, applyRecord, createRecord, onSelectionChange } = props.current; |
| 2225 | 2300 | if (element.contentEditable !== "true") { |
| 2226 | 2301 | return; |
| 2227 | 2302 | } |
| 2228 | - if (ownerDocument.activeElement !== element) { | |
| 2229 | - ownerDocument.removeEventListener( | |
| 2230 | - "selectionchange", | |
| 2231 | - handleSelectionChange | |
| 2232 | - ); | |
| 2303 | + if (ownerDocument.activeElement !== element && !ownsSelection(element)) { | |
| 2233 | 2304 | return; |
| 2234 | 2305 | } |
| 2235 | 2306 | if (isComposing) { |
| 2236 | 2307 | return; |
| 2237 | 2308 | } |
| 2309 | + const selection = defaultView.getSelection(); | |
| 2310 | + if (selectionSnapshot && selectionSnapshot.anchorNode === selection.anchorNode && selectionSnapshot.anchorOffset === selection.anchorOffset && selectionSnapshot.focusNode === selection.focusNode && selectionSnapshot.focusOffset === selection.focusOffset && selectionSnapshot.processedStart === record.current.start && selectionSnapshot.processedEnd === record.current.end) { | |
| 2311 | + return; | |
| 2312 | + } | |
| 2238 | 2313 | const { start, end, text } = createRecord(); |
| 2239 | 2314 | const oldRecord = record.current; |
| 2315 | + if (text.length === 0) { | |
| 2316 | + applyRecord({ ...oldRecord, start, end }); | |
| 2317 | + } | |
| 2318 | + selectionSnapshot = { | |
| 2319 | + anchorNode: selection.anchorNode, | |
| 2320 | + anchorOffset: selection.anchorOffset, | |
| 2321 | + focusNode: selection.focusNode, | |
| 2322 | + focusOffset: selection.focusOffset, | |
| 2323 | + processedStart: start, | |
| 2324 | + processedEnd: end | |
| 2325 | + }; | |
| 2240 | 2326 | if (text !== oldRecord.text) { |
| 2241 | 2327 | onInput(); |
| 2242 | 2328 | return; |
| 2243 | 2329 | } |
| 2244 | 2330 | if (start === oldRecord.start && end === oldRecord.end) { |
| 2245 | - if (oldRecord.text.length === 0 && start === 0) { | |
| 2246 | - fixPlaceholderSelection(defaultView); | |
| 2247 | - } | |
| 2248 | 2331 | return; |
| 2249 | 2332 | } |
| 2250 | 2333 | const newValue = { |
| 2251 | 2334 | ...oldRecord, |
| @@ -2267,21 +2350,13 @@ | ||
| 2267 | 2350 | onSelectionChange(start, end); |
| 2268 | 2351 | } |
| 2269 | 2352 | function onCompositionStart() { |
| 2270 | 2353 | isComposing = true; |
| 2271 | - ownerDocument.removeEventListener( | |
| 2272 | - "selectionchange", | |
| 2273 | - handleSelectionChange | |
| 2274 | - ); | |
| 2275 | 2354 | element.querySelector(`[${PLACEHOLDER_ATTR_NAME}]`)?.remove(); |
| 2276 | 2355 | } |
| 2277 | 2356 | function onCompositionEnd() { |
| 2278 | 2357 | isComposing = false; |
| 2279 | 2358 | onInput({ inputType: "insertText" }); |
| 2280 | - ownerDocument.addEventListener( | |
| 2281 | - "selectionchange", | |
| 2282 | - handleSelectionChange | |
| 2283 | - ); | |
| 2284 | 2359 | } |
| 2285 | 2360 | function onFocus(event) { |
| 2286 | 2361 | if (event.target !== element) { |
| 2287 | 2362 | return; |
| @@ -2290,8 +2365,16 @@ | ||
| 2290 | 2365 | return; |
| 2291 | 2366 | } |
| 2292 | 2367 | const { record, isSelected, onSelectionChange, applyRecord } = props.current; |
| 2293 | 2368 | if (element.parentElement.closest('[contenteditable="true"]')) { |
| 2369 | + const selection = defaultView.getSelection(); | |
| 2370 | + if (!selection.anchorNode || !element.contains(selection.anchorNode)) { | |
| 2371 | + if (isSelected && record.current.start !== void 0) { | |
| 2372 | + applyRecord(record.current); | |
| 2373 | + } else { | |
| 2374 | + selection.collapse(element, 0); | |
| 2375 | + } | |
| 2376 | + } | |
| 2294 | 2377 | return; |
| 2295 | 2378 | } |
| 2296 | 2379 | if (!isSelected) { |
| 2297 | 2380 | const index = void 0; |
| @@ -2300,51 +2383,89 @@ | ||
| 2300 | 2383 | start: index, |
| 2301 | 2384 | end: index, |
| 2302 | 2385 | activeFormats: EMPTY_ACTIVE_FORMATS2 |
| 2303 | 2386 | }; |
| 2304 | - } else { | |
| 2305 | - applyRecord(record.current, { domOnly: true }); | |
| 2387 | + selectionSnapshot = void 0; | |
| 2388 | + } else if (!isPointerDown) { | |
| 2389 | + applyRecord(record.current); | |
| 2306 | 2390 | } |
| 2307 | 2391 | onSelectionChange(record.current.start, record.current.end); |
| 2308 | 2392 | window.queueMicrotask(handleSelectionChange); |
| 2309 | - ownerDocument.addEventListener( | |
| 2310 | - "selectionchange", | |
| 2311 | - handleSelectionChange | |
| 2312 | - ); | |
| 2313 | 2393 | } |
| 2314 | - const unsubscribeInput = subscribeDelegatedListener5( | |
| 2394 | + const unsubscribeInput = subscribeOwnedListener( | |
| 2315 | 2395 | element, |
| 2316 | 2396 | "input", |
| 2317 | 2397 | onInput, |
| 2318 | 2398 | true |
| 2319 | 2399 | ); |
| 2320 | - const unsubscribeCompositionStart = subscribeDelegatedListener5( | |
| 2400 | + const unsubscribeCompositionStart = subscribeOwnedListener( | |
| 2321 | 2401 | element, |
| 2322 | 2402 | "compositionstart", |
| 2323 | 2403 | onCompositionStart |
| 2324 | 2404 | ); |
| 2325 | - const unsubscribeCompositionEnd = subscribeDelegatedListener5( | |
| 2405 | + const unsubscribeCompositionEnd = subscribeOwnedListener( | |
| 2326 | 2406 | element, |
| 2327 | 2407 | "compositionend", |
| 2328 | 2408 | onCompositionEnd, |
| 2329 | 2409 | true |
| 2330 | 2410 | ); |
| 2331 | - const unsubscribeFocus = subscribeDelegatedListener5( | |
| 2411 | + const unsubscribeFocus = subscribeDelegatedListener4( | |
| 2332 | 2412 | element, |
| 2333 | 2413 | "focusin", |
| 2334 | 2414 | onFocus |
| 2335 | 2415 | ); |
| 2416 | + const unsubscribePointerDown = subscribeDelegatedListener4( | |
| 2417 | + element, | |
| 2418 | + "pointerdown", | |
| 2419 | + onPointerDown | |
| 2420 | + ); | |
| 2421 | + const unsubscribePointerUp = subscribeDelegatedListener4( | |
| 2422 | + defaultView, | |
| 2423 | + "pointerup", | |
| 2424 | + onPointerUp | |
| 2425 | + ); | |
| 2426 | + const unsubscribePointerCancel = subscribeDelegatedListener4( | |
| 2427 | + defaultView, | |
| 2428 | + "pointercancel", | |
| 2429 | + onPointerUp | |
| 2430 | + ); | |
| 2431 | + const unsubscribeSelectionChange = subscribeOwnedListener( | |
| 2432 | + element, | |
| 2433 | + "selectionchange", | |
| 2434 | + handleSelectionChange | |
| 2435 | + ); | |
| 2436 | + const unsubscribeEnsureSelectionSync = [ | |
| 2437 | + "keydown", | |
| 2438 | + "beforeinput", | |
| 2439 | + "copy", | |
| 2440 | + "cut", | |
| 2441 | + "paste" | |
| 2442 | + ].map( | |
| 2443 | + (eventType) => subscribeOwnedListener( | |
| 2444 | + element, | |
| 2445 | + eventType, | |
| 2446 | + handleSelectionChange, | |
| 2447 | + true | |
| 2448 | + ) | |
| 2449 | + ); | |
| 2336 | 2450 | return () => { |
| 2337 | 2451 | unsubscribeInput(); |
| 2338 | 2452 | unsubscribeCompositionStart(); |
| 2339 | 2453 | unsubscribeCompositionEnd(); |
| 2340 | 2454 | unsubscribeFocus(); |
| 2455 | + unsubscribePointerDown(); | |
| 2456 | + unsubscribePointerUp(); | |
| 2457 | + unsubscribePointerCancel(); | |
| 2458 | + unsubscribeSelectionChange(); | |
| 2459 | + unsubscribeEnsureSelectionSync.forEach( | |
| 2460 | + (unsubscribe) => unsubscribe() | |
| 2461 | + ); | |
| 2341 | 2462 | }; |
| 2342 | 2463 | }; |
| 2343 | 2464 | |
| 2344 | 2465 | // packages/rich-text/build-module/hook/event-listeners/selection-change-compat.mjs |
| 2345 | - var import_compose6 = __toESM(require_compose(), 1); | |
| 2346 | - var { subscribeDelegatedListener: subscribeDelegatedListener6 } = unlock(import_compose6.privateApis); | |
| 2466 | + var import_compose5 = __toESM(require_compose(), 1); | |
| 2467 | + var { subscribeDelegatedListener: subscribeDelegatedListener5 } = unlock(import_compose5.privateApis); | |
| 2347 | 2468 | var selection_change_compat_default = () => (element) => { |
| 2348 | 2469 | const { ownerDocument } = element; |
| 2349 | 2470 | const { defaultView } = ownerDocument; |
| 2350 | 2471 | const selection = defaultView?.getSelection(); |
| @@ -2370,14 +2491,14 @@ | ||
| 2370 | 2491 | ownerDocument.addEventListener("selectionchange", onCancel); |
| 2371 | 2492 | ownerDocument.addEventListener("input", onCancel); |
| 2372 | 2493 | range = getRange(); |
| 2373 | 2494 | } |
| 2374 | - const unsubscribePointerDown = subscribeDelegatedListener6( | |
| 2495 | + const unsubscribePointerDown = subscribeDelegatedListener5( | |
| 2375 | 2496 | element, |
| 2376 | 2497 | "pointerdown", |
| 2377 | 2498 | onDown |
| 2378 | 2499 | ); |
| 2379 | - const unsubscribeKeyDown = subscribeDelegatedListener6( | |
| 2500 | + const unsubscribeKeyDown = subscribeDelegatedListener5( | |
| 2380 | 2501 | element, |
| 2381 | 2502 | "keydown", |
| 2382 | 2503 | onDown |
| 2383 | 2504 | ); |
| @@ -2387,10 +2508,10 @@ | ||
| 2387 | 2508 | }; |
| 2388 | 2509 | }; |
| 2389 | 2510 | |
| 2390 | 2511 | // packages/rich-text/build-module/hook/event-listeners/prevent-focus-capture.mjs |
| 2391 | - var import_compose7 = __toESM(require_compose(), 1); | |
| 2392 | - var { subscribeDelegatedListener: subscribeDelegatedListener7 } = unlock(import_compose7.privateApis); | |
| 2512 | + var import_compose6 = __toESM(require_compose(), 1); | |
| 2513 | + var { subscribeDelegatedListener: subscribeDelegatedListener6 } = unlock(import_compose6.privateApis); | |
| 2393 | 2514 | function preventFocusCapture() { |
| 2394 | 2515 | return (element) => { |
| 2395 | 2516 | const { ownerDocument } = element; |
| 2396 | 2517 | const { defaultView } = ownerDocument; |
| @@ -2404,31 +2525,44 @@ | ||
| 2404 | 2525 | } |
| 2405 | 2526 | if (!event.target.contains(element)) { |
| 2406 | 2527 | return; |
| 2407 | 2528 | } |
| 2529 | + if (!event.target.closest("[data-block]")) { | |
| 2530 | + return; | |
| 2531 | + } | |
| 2408 | 2532 | value = element.getAttribute("contenteditable"); |
| 2533 | + defaultView.getSelection().removeAllRanges(); | |
| 2409 | 2534 | element.setAttribute("contenteditable", "false"); |
| 2410 | - defaultView.getSelection().removeAllRanges(); | |
| 2411 | 2535 | } |
| 2412 | 2536 | function onPointerUp() { |
| 2413 | 2537 | if (value !== null) { |
| 2414 | 2538 | element.setAttribute("contenteditable", value); |
| 2415 | 2539 | value = null; |
| 2540 | + const selection = defaultView.getSelection(); | |
| 2541 | + if (selection.isCollapsed && element.contains(selection.anchorNode)) { | |
| 2542 | + selection.removeAllRanges(); | |
| 2543 | + } | |
| 2416 | 2544 | } |
| 2417 | 2545 | } |
| 2418 | - const unsubscribePointerDown = subscribeDelegatedListener7( | |
| 2546 | + const unsubscribePointerDown = subscribeDelegatedListener6( | |
| 2419 | 2547 | defaultView, |
| 2420 | 2548 | "pointerdown", |
| 2421 | 2549 | onPointerDown |
| 2422 | 2550 | ); |
| 2423 | - const unsubscribePointerUp = subscribeDelegatedListener7( | |
| 2551 | + const unsubscribePointerUp = subscribeDelegatedListener6( | |
| 2424 | 2552 | defaultView, |
| 2425 | 2553 | "pointerup", |
| 2426 | 2554 | onPointerUp |
| 2427 | 2555 | ); |
| 2556 | + const unsubscribePointerCancel = subscribeDelegatedListener6( | |
| 2557 | + defaultView, | |
| 2558 | + "pointercancel", | |
| 2559 | + onPointerUp | |
| 2560 | + ); | |
| 2428 | 2561 | return () => { |
| 2429 | 2562 | unsubscribePointerDown(); |
| 2430 | 2563 | unsubscribePointerUp(); |
| 2564 | + unsubscribePointerCancel(); | |
| 2431 | 2565 | }; |
| 2432 | 2566 | }; |
| 2433 | 2567 | } |
| 2434 | 2568 | |
| @@ -2433,13 +2567,13 @@ | ||
| 2433 | 2567 | } |
| 2434 | 2568 | |
| 2435 | 2569 | // packages/rich-text/build-module/hook/event-listeners/index.mjs |
| 2436 | 2570 | var allEventListeners = [ |
| 2571 | + input_and_selection_default, | |
| 2437 | 2572 | copy_handler_default, |
| 2438 | 2573 | select_object_default, |
| 2439 | 2574 | format_boundaries_default, |
| 2440 | 2575 | delete_default, |
| 2441 | - input_and_selection_default, | |
| 2442 | 2576 | selection_change_compat_default, |
| 2443 | 2577 | preventFocusCapture |
| 2444 | 2578 | ]; |
| 2445 | 2579 | function useEventListeners(props) { |
| @@ -2450,9 +2584,9 @@ | ||
| 2450 | 2584 | const refEffects = (0, import_element3.useMemo)( |
| 2451 | 2585 | () => allEventListeners.map((refEffect) => refEffect(propsRef)), |
| 2452 | 2586 | [propsRef] |
| 2453 | 2587 | ); |
| 2454 | - return (0, import_compose8.useRefEffect)( | |
| 2588 | + return (0, import_compose7.useRefEffect)( | |
| 2455 | 2589 | (element) => { |
| 2456 | 2590 | const cleanups = refEffects.map((effect) => effect(element)); |
| 2457 | 2591 | return () => { |
| 2458 | 2592 | cleanups.forEach((cleanup) => cleanup()); |
| @@ -2585,8 +2719,12 @@ | ||
| 2585 | 2719 | }; |
| 2586 | 2720 | } |
| 2587 | 2721 | |
| 2588 | 2722 | // packages/rich-text/build-module/hook/index.mjs |
| 2723 | + function hasFocus(element) { | |
| 2724 | + const { activeElement } = element.ownerDocument; | |
| 2725 | + return activeElement === element || activeElement?.contentEditable === "true" && activeElement.contains(element); | |
| 2726 | + } | |
| 2589 | 2727 | function useRichTextBase({ |
| 2590 | 2728 | value = "", |
| 2591 | 2729 | selectionStart, |
| 2592 | 2730 | selectionEnd, |
| @@ -2651,14 +2789,11 @@ | ||
| 2651 | 2789 | } |
| 2652 | 2790 | recordRef.current.start = selectionStart; |
| 2653 | 2791 | recordRef.current.end = selectionEnd; |
| 2654 | 2792 | } |
| 2655 | - const hadSelectionUpdateRef = (0, import_element5.useRef)(false); | |
| 2656 | 2793 | if (!recordRef.current) { |
| 2657 | - hadSelectionUpdateRef.current = isSelected; | |
| 2658 | 2794 | setRecordFromProps(); |
| 2659 | 2795 | } else if (selectionStart !== recordRef.current.start || selectionEnd !== recordRef.current.end) { |
| 2660 | - hadSelectionUpdateRef.current = isSelected; | |
| 2661 | 2796 | recordRef.current = { |
| 2662 | 2797 | ...recordRef.current, |
| 2663 | 2798 | start: selectionStart, |
| 2664 | 2799 | end: selectionEnd, |
| @@ -2664,8 +2799,13 @@ | ||
| 2664 | 2799 | end: selectionEnd, |
| 2665 | 2800 | activeFormats: void 0 |
| 2666 | 2801 | }; |
| 2667 | 2802 | } |
| 2803 | + const sentSelectionRef = (0, import_element5.useRef)([]); | |
| 2804 | + function sendSelection(start, end) { | |
| 2805 | + sentSelectionRef.current = [start, end]; | |
| 2806 | + onSelectionChange(start, end); | |
| 2807 | + } | |
| 2668 | 2808 | function handleChange(newRecord) { |
| 2669 | 2809 | recordRef.current = newRecord; |
| 2670 | 2810 | applyRecord(newRecord); |
| 2671 | 2811 | if (disableFormats) { |
| @@ -2683,9 +2823,9 @@ | ||
| 2683 | 2823 | } |
| 2684 | 2824 | } |
| 2685 | 2825 | const { start, end, formats, text } = recordRef.current; |
| 2686 | 2826 | registry.batch(() => { |
| 2687 | - onSelectionChange(start, end); | |
| 2827 | + sendSelection(start, end); | |
| 2688 | 2828 | onChange(_valueRef.current, { |
| 2689 | 2829 | __unstableFormats: formats, |
| 2690 | 2830 | __unstableText: text |
| 2691 | 2831 | }); |
| @@ -2691,36 +2831,26 @@ | ||
| 2691 | 2831 | }); |
| 2692 | 2832 | }); |
| 2693 | 2833 | forceRender(); |
| 2694 | 2834 | } |
| 2695 | - function applyFromProps() { | |
| 2696 | - const previousValue = _valueRef.current; | |
| 2697 | - setRecordFromProps(); | |
| 2698 | - const contentLengthChanged = previousValue && typeof previousValue === "string" && typeof value === "string" && previousValue.length !== value.length; | |
| 2699 | - const hasFocus = ref.current?.contains( | |
| 2700 | - ref.current.ownerDocument.activeElement | |
| 2701 | - ); | |
| 2702 | - const skipSelection = contentLengthChanged && !hasFocus; | |
| 2703 | - applyRecord(recordRef.current, { domOnly: skipSelection }); | |
| 2704 | - } | |
| 2705 | - const didMountRef = (0, import_element5.useRef)(false); | |
| 2706 | 2835 | (0, import_element5.useLayoutEffect)(() => { |
| 2707 | - if (didMountRef.current && value !== _valueRef.current) { | |
| 2708 | - applyFromProps(); | |
| 2709 | - forceRender(); | |
| 2836 | + if (value === _valueRef.current) { | |
| 2837 | + return; | |
| 2710 | 2838 | } |
| 2839 | + setRecordFromProps(); | |
| 2840 | + applyRecord(recordRef.current, { | |
| 2841 | + domOnly: !hasFocus(ref.current) | |
| 2842 | + }); | |
| 2843 | + forceRender(); | |
| 2711 | 2844 | }, [value]); |
| 2712 | 2845 | (0, import_element5.useLayoutEffect)(() => { |
| 2713 | - if (!hadSelectionUpdateRef.current) { | |
| 2714 | - return; | |
| 2846 | + const [sentStart, sentEnd] = sentSelectionRef.current; | |
| 2847 | + sentSelectionRef.current = []; | |
| 2848 | + if (isSelected && (selectionStart !== sentStart || selectionEnd !== sentEnd) && hasFocus(ref.current)) { | |
| 2849 | + applyRecord(recordRef.current); | |
| 2715 | 2850 | } |
| 2716 | - if (ref.current.ownerDocument.activeElement !== ref.current) { | |
| 2717 | - ref.current.focus(); | |
| 2718 | - } | |
| 2719 | - applyRecord(recordRef.current); | |
| 2720 | - hadSelectionUpdateRef.current = false; | |
| 2721 | - }, [hadSelectionUpdateRef.current]); | |
| 2722 | - const mergedRefs = (0, import_compose9.useMergeRefs)([ | |
| 2851 | + }, [selectionStart, selectionEnd, isSelected]); | |
| 2852 | + const mergedRefs = (0, import_compose8.useMergeRefs)([ | |
| 2723 | 2853 | ref, |
| 2724 | 2854 | useDefaultStyle(), |
| 2725 | 2855 | useBoundaryStyle({ record: recordRef }), |
| 2726 | 2856 | useEventListeners({ |
| @@ -2728,15 +2858,20 @@ | ||
| 2728 | 2858 | handleChange, |
| 2729 | 2859 | applyRecord, |
| 2730 | 2860 | createRecord, |
| 2731 | 2861 | isSelected, |
| 2732 | - onSelectionChange, | |
| 2862 | + onSelectionChange: sendSelection, | |
| 2733 | 2863 | forceRender |
| 2734 | 2864 | }), |
| 2735 | - (0, import_compose9.useRefEffect)(() => { | |
| 2736 | - applyFromProps(); | |
| 2737 | - didMountRef.current = true; | |
| 2738 | - }, [placeholder, ...__unstableDependencies]) | |
| 2865 | + (0, import_compose8.useRefEffect)( | |
| 2866 | + (element) => { | |
| 2867 | + setRecordFromProps(); | |
| 2868 | + applyRecord(recordRef.current, { | |
| 2869 | + domOnly: !hasFocus(element) | |
| 2870 | + }); | |
| 2871 | + }, | |
| 2872 | + [placeholder, ...__unstableDependencies] | |
| 2873 | + ) | |
| 2739 | 2874 | ]); |
| 2740 | 2875 | return { |
| 2741 | 2876 | value: recordRef.current, |
| 2742 | 2877 | // A function to get the most recent value so event handlers in |
| @@ -2814,16 +2949,102 @@ | ||
| 2814 | 2949 | }); |
| 2815 | 2950 | return useRichTextBase(props); |
| 2816 | 2951 | } |
| 2817 | 2952 | |
| 2953 | + // packages/rich-text/build-module/contexts.mjs | |
| 2954 | + var import_element6 = __toESM(require_element(), 1); | |
| 2955 | + var KeyboardShortcutContext = (0, import_element6.createContext)(); | |
| 2956 | + KeyboardShortcutContext.displayName = "KeyboardShortcutContext"; | |
| 2957 | + var InputEventContext = (0, import_element6.createContext)(); | |
| 2958 | + InputEventContext.displayName = "InputEventContext"; | |
| 2959 | + | |
| 2960 | + // packages/rich-text/build-module/keyboard-shortcut.mjs | |
| 2961 | + var import_keycodes3 = __toESM(require_keycodes(), 1); | |
| 2962 | + var import_element7 = __toESM(require_element(), 1); | |
| 2963 | + var import_compose9 = __toESM(require_compose(), 1); | |
| 2964 | + function RichTextShortcut({ character, type, onUse }) { | |
| 2965 | + const keyboardShortcuts = (0, import_element7.useContext)(KeyboardShortcutContext); | |
| 2966 | + const stableOnUse = (0, import_compose9.useEvent)(onUse); | |
| 2967 | + (0, import_element7.useEffect)(() => { | |
| 2968 | + const shortcuts = keyboardShortcuts.current; | |
| 2969 | + function callback(event) { | |
| 2970 | + if (import_keycodes3.isKeyboardEvent[type](event, character)) { | |
| 2971 | + stableOnUse(); | |
| 2972 | + event.preventDefault(); | |
| 2973 | + } | |
| 2974 | + } | |
| 2975 | + shortcuts.add(callback); | |
| 2976 | + return () => { | |
| 2977 | + shortcuts.delete(callback); | |
| 2978 | + }; | |
| 2979 | + }, [character, type, keyboardShortcuts, stableOnUse]); | |
| 2980 | + return null; | |
| 2981 | + } | |
| 2982 | + | |
| 2983 | + // packages/rich-text/build-module/input-event.mjs | |
| 2984 | + var import_element8 = __toESM(require_element(), 1); | |
| 2985 | + var import_compose10 = __toESM(require_compose(), 1); | |
| 2986 | + function RichTextInputEvent({ inputType, onInput }) { | |
| 2987 | + const callbacks = (0, import_element8.useContext)(InputEventContext); | |
| 2988 | + const stableOnInput = (0, import_compose10.useEvent)(onInput); | |
| 2989 | + (0, import_element8.useEffect)(() => { | |
| 2990 | + const inputCallbacks = callbacks.current; | |
| 2991 | + function callback(event) { | |
| 2992 | + if (event.inputType === inputType) { | |
| 2993 | + stableOnInput(); | |
| 2994 | + event.preventDefault(); | |
| 2995 | + } | |
| 2996 | + } | |
| 2997 | + inputCallbacks.add(callback); | |
| 2998 | + return () => { | |
| 2999 | + inputCallbacks.delete(callback); | |
| 3000 | + }; | |
| 3001 | + }, [inputType, callbacks, stableOnInput]); | |
| 3002 | + return null; | |
| 3003 | + } | |
| 3004 | + | |
| 3005 | + // packages/rich-text/build-module/event-listeners.mjs | |
| 3006 | + var shortcutsListener = (props) => (element) => { | |
| 3007 | + const { keyboardShortcuts } = props.current; | |
| 3008 | + function onKeyDown(event) { | |
| 3009 | + for (const keyboardShortcut of keyboardShortcuts.current) { | |
| 3010 | + keyboardShortcut(event); | |
| 3011 | + } | |
| 3012 | + } | |
| 3013 | + element.addEventListener("keydown", onKeyDown); | |
| 3014 | + return () => { | |
| 3015 | + element.removeEventListener("keydown", onKeyDown); | |
| 3016 | + }; | |
| 3017 | + }; | |
| 3018 | + var inputEventsListener = (props) => (element) => { | |
| 3019 | + const { inputEvents } = props.current; | |
| 3020 | + function onInput(event) { | |
| 3021 | + for (const inputEventHandler of inputEvents.current) { | |
| 3022 | + inputEventHandler(event); | |
| 3023 | + } | |
| 3024 | + } | |
| 3025 | + element.addEventListener("input", onInput); | |
| 3026 | + return () => { | |
| 3027 | + element.removeEventListener("input", onInput); | |
| 3028 | + }; | |
| 3029 | + }; | |
| 3030 | + | |
| 2818 | 3031 | // packages/rich-text/build-module/private-apis.mjs |
| 2819 | 3032 | var privateApis = {}; |
| 2820 | 3033 | lock(privateApis, { |
| 2821 | - useRichText | |
| 3034 | + useRichText, | |
| 3035 | + KeyboardShortcutContext, | |
| 3036 | + InputEventContext, | |
| 3037 | + RichTextShortcut, | |
| 3038 | + RichTextInputEvent, | |
| 3039 | + shortcutsListener, | |
| 3040 | + inputEventsListener, | |
| 3041 | + ownsSelection, | |
| 3042 | + subscribeOwnedListener | |
| 2822 | 3043 | }); |
| 2823 | 3044 | |
| 2824 | 3045 | // packages/rich-text/build-module/hook/use-anchor-ref.mjs |
| 2825 | - var import_element6 = __toESM(require_element(), 1); | |
| 3046 | + var import_element9 = __toESM(require_element(), 1); | |
| 2826 | 3047 | var import_deprecated2 = __toESM(require_deprecated(), 1); |
| 2827 | 3048 | function useAnchorRef({ ref, value, settings = {} }) { |
| 2828 | 3049 | (0, import_deprecated2.default)("`useAnchorRef` hook", { |
| 2829 | 3050 | since: "6.1", |
| @@ -2830,9 +3051,9 @@ | ||
| 2830 | 3051 | alternative: "`useAnchor` hook" |
| 2831 | 3052 | }); |
| 2832 | 3053 | const { tagName, className, name } = settings; |
| 2833 | 3054 | const activeFormat = name ? getActiveFormat(value, name) : void 0; |
| 2834 | - return (0, import_element6.useMemo)(() => { | |
| 3055 | + return (0, import_element9.useMemo)(() => { | |
| 2835 | 3056 | if (!ref.current) { |
| 2836 | 3057 | return; |
| 2837 | 3058 | } |
| 2838 | 3059 | const { |
| @@ -2857,10 +3078,10 @@ | ||
| 2857 | 3078 | }, [activeFormat, value.start, value.end, tagName, className]); |
| 2858 | 3079 | } |
| 2859 | 3080 | |
| 2860 | 3081 | // packages/rich-text/build-module/hook/use-anchor.mjs |
| 2861 | - var import_compose10 = __toESM(require_compose(), 1); | |
| 2862 | - var import_element7 = __toESM(require_element(), 1); | |
| 3082 | + var import_compose11 = __toESM(require_compose(), 1); | |
| 3083 | + var import_element10 = __toESM(require_element(), 1); | |
| 2863 | 3084 | var import_dom = __toESM(require_dom(), 1); |
| 2864 | 3085 | function getFormatElement(range, editableContentElement, tagName, className) { |
| 2865 | 3086 | let element = range.startContainer; |
| 2866 | 3087 | if (element.nodeType === element.TEXT_NODE && element instanceof window.Text && range.startOffset === element.length && element.nextSibling) { |
| @@ -2939,13 +3160,13 @@ | ||
| 2939 | 3160 | settings |
| 2940 | 3161 | }) { |
| 2941 | 3162 | const { tagName, className } = settings ?? DEFAULT_SETTINGS; |
| 2942 | 3163 | const isActive = !!(settings && "isActive" in settings && settings.isActive); |
| 2943 | - const [anchor, setAnchor] = (0, import_element7.useState)( | |
| 3164 | + const [anchor, setAnchor] = (0, import_element10.useState)( | |
| 2944 | 3165 | () => getAnchor(editableContentElement, tagName, className ?? "") |
| 2945 | 3166 | ); |
| 2946 | - const wasActive = (0, import_compose10.usePrevious)(isActive); | |
| 2947 | - (0, import_element7.useLayoutEffect)(() => { | |
| 3167 | + const wasActive = (0, import_compose11.usePrevious)(isActive); | |
| 3168 | + (0, import_element10.useLayoutEffect)(() => { | |
| 2948 | 3169 | if (!editableContentElement) { |
| 2949 | 3170 | return; |
| 2950 | 3171 | } |
| 2951 | 3172 | function callback() { |
| @@ -2959,9 +3180,9 @@ | ||
| 2959 | 3180 | function detach() { |
| 2960 | 3181 | ownerDocument.removeEventListener("selectionchange", callback); |
| 2961 | 3182 | } |
| 2962 | 3183 | const { ownerDocument } = editableContentElement; |
| 2963 | - if (editableContentElement === ownerDocument.activeElement || // When a link is created, we need to attach the popover to the newly created anchor. | |
| 3184 | + if (ownsSelection(editableContentElement) || // When a link is created, we need to attach the popover to the newly created anchor. | |
| 2964 | 3185 | !wasActive && isActive || // Sometimes we're _removing_ an active anchor, such as the inline color popover. |
| 2965 | 3186 | // When we add the color, it switches from a virtual anchor to a `<mark>` element. |
| 2966 | 3187 | // When we _remove_ the color, it switches from a `<mark>` element to a virtual anchor. |
| 2967 | 3188 | wasActive && !isActive) { |
| @@ -2984,6 +3205,8 @@ | ||
| 2984 | 3205 | // packages/rich-text/build-module/index.mjs |
| 2985 | 3206 | function __experimentalRichText() { |
| 2986 | 3207 | } |
| 2987 | 3208 | return __toCommonJS(index_exports); |
| 3209 | +})(); | |
| 3210 | +(window.wp ||= {}).richText = wp.richText; | |
| 2988 | 3211 | })(); |
| 2989 | 3212 | //# sourceMappingURL=index.js.map |