react-input-emoji 5.6.4 → 5.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -607,6 +607,24 @@ function replaceAllTextEmojiToString(html) {
607
607
 
608
608
  // @ts-check
609
609
 
610
+ /**
611
+ * Handle copy of current selected text
612
+ * @param {React.ClipboardEvent} event
613
+ */
614
+ function handleCopy(event) {
615
+ var selectedText = window.getSelection();
616
+ if (selectedText === null) {
617
+ return;
618
+ }
619
+ var container = document.createElement("div");
620
+ for (var i = 0, len = selectedText.rangeCount; i < len; ++i) {
621
+ container.appendChild(selectedText.getRangeAt(i).cloneContents());
622
+ }
623
+ container = replaceEmojiToString(container);
624
+ event.clipboardData.setData("text", container.innerText);
625
+ event.preventDefault();
626
+ }
627
+
610
628
  /**
611
629
  *
612
630
  * @param {string} html
@@ -646,6 +664,19 @@ function handlePasteHtmlAtCaret(html) {
646
664
  }
647
665
  }
648
666
 
667
+ /**
668
+ * Replace emoji img to its string value
669
+ * @param {HTMLDivElement} container
670
+ * @return {HTMLDivElement}
671
+ */
672
+ function replaceEmojiToString(container) {
673
+ var images = Array.prototype.slice.call(container.querySelectorAll("img"));
674
+ images.forEach(function (image) {
675
+ image.outerHTML = image.dataset.emoji;
676
+ });
677
+ return container;
678
+ }
679
+
649
680
  /**
650
681
  *
651
682
  * @param {{text: string, html: string}} props
@@ -4522,27 +4553,6 @@ function InputEmoji(props, ref) {
4522
4553
  }
4523
4554
  }
4524
4555
 
4525
- /**
4526
- * Handle copy of current selected text
4527
- * @param {React.ClipboardEvent} event
4528
- */
4529
- function handleCopy(event) {
4530
- var selection = window.getSelection();
4531
- if (selection !== null) {
4532
- var selectedText = '';
4533
- if (selection.anchorNode && selection.anchorNode.nodeType === Node.ELEMENT_NODE) {
4534
- // @ts-ignore
4535
- selectedText = selection.anchorNode.innerHTML;
4536
- } else if (selection.anchorNode && selection.anchorNode.nodeType === Node.TEXT_NODE) {
4537
- var _selection$anchorNode;
4538
- selectedText = (_selection$anchorNode = selection.anchorNode.textContent) !== null && _selection$anchorNode !== void 0 ? _selection$anchorNode : '';
4539
- }
4540
- var text = replaceAllTextEmojiToString(selectedText);
4541
- event.clipboardData.setData("text", text);
4542
- event.preventDefault();
4543
- }
4544
- }
4545
-
4546
4556
  /**
4547
4557
  * Handle past on input
4548
4558
  * @param {React.ClipboardEvent} event