react-input-emoji 5.6.4 → 5.6.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.es.js +31 -21
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +31 -21
- package/dist/index.js.map +1 -1
- package/dist/src/types/types.d.ts +32 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
@@ -600,6 +600,24 @@ function replaceAllTextEmojiToString(html) {
|
|
600
600
|
|
601
601
|
// @ts-check
|
602
602
|
|
603
|
+
/**
|
604
|
+
* Handle copy of current selected text
|
605
|
+
* @param {React.ClipboardEvent} event
|
606
|
+
*/
|
607
|
+
function handleCopy(event) {
|
608
|
+
var selectedText = window.getSelection();
|
609
|
+
if (selectedText === null) {
|
610
|
+
return;
|
611
|
+
}
|
612
|
+
var container = document.createElement("div");
|
613
|
+
for (var i = 0, len = selectedText.rangeCount; i < len; ++i) {
|
614
|
+
container.appendChild(selectedText.getRangeAt(i).cloneContents());
|
615
|
+
}
|
616
|
+
container = replaceEmojiToString(container);
|
617
|
+
event.clipboardData.setData("text", container.innerText);
|
618
|
+
event.preventDefault();
|
619
|
+
}
|
620
|
+
|
603
621
|
/**
|
604
622
|
*
|
605
623
|
* @param {string} html
|
@@ -639,6 +657,19 @@ function handlePasteHtmlAtCaret(html) {
|
|
639
657
|
}
|
640
658
|
}
|
641
659
|
|
660
|
+
/**
|
661
|
+
* Replace emoji img to its string value
|
662
|
+
* @param {HTMLDivElement} container
|
663
|
+
* @return {HTMLDivElement}
|
664
|
+
*/
|
665
|
+
function replaceEmojiToString(container) {
|
666
|
+
var images = Array.prototype.slice.call(container.querySelectorAll("img"));
|
667
|
+
images.forEach(function (image) {
|
668
|
+
image.outerHTML = image.dataset.emoji;
|
669
|
+
});
|
670
|
+
return container;
|
671
|
+
}
|
672
|
+
|
642
673
|
/**
|
643
674
|
*
|
644
675
|
* @param {{text: string, html: string}} props
|
@@ -4515,27 +4546,6 @@ function InputEmoji(props, ref) {
|
|
4515
4546
|
}
|
4516
4547
|
}
|
4517
4548
|
|
4518
|
-
/**
|
4519
|
-
* Handle copy of current selected text
|
4520
|
-
* @param {React.ClipboardEvent} event
|
4521
|
-
*/
|
4522
|
-
function handleCopy(event) {
|
4523
|
-
var selection = window.getSelection();
|
4524
|
-
if (selection !== null) {
|
4525
|
-
var selectedText = '';
|
4526
|
-
if (selection.anchorNode && selection.anchorNode.nodeType === Node.ELEMENT_NODE) {
|
4527
|
-
// @ts-ignore
|
4528
|
-
selectedText = selection.anchorNode.innerHTML;
|
4529
|
-
} else if (selection.anchorNode && selection.anchorNode.nodeType === Node.TEXT_NODE) {
|
4530
|
-
var _selection$anchorNode;
|
4531
|
-
selectedText = (_selection$anchorNode = selection.anchorNode.textContent) !== null && _selection$anchorNode !== void 0 ? _selection$anchorNode : '';
|
4532
|
-
}
|
4533
|
-
var text = replaceAllTextEmojiToString(selectedText);
|
4534
|
-
event.clipboardData.setData("text", text);
|
4535
|
-
event.preventDefault();
|
4536
|
-
}
|
4537
|
-
}
|
4538
|
-
|
4539
4549
|
/**
|
4540
4550
|
* Handle past on input
|
4541
4551
|
* @param {React.ClipboardEvent} event
|