react-input-emoji 5.3.1 → 5.5.1

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
@@ -4907,7 +4907,12 @@ function InputEmoji(props, ref) {
4907
4907
  textInputRef.current.html = replaceAllTextEmojis(nextValue);
4908
4908
  sanitizedTextRef.current = nextValue;
4909
4909
  }, [sanitizedTextRef]);
4910
- var setValue = React.useCallback(function (value) {
4910
+ var setValue = React.useCallback(
4911
+ /**
4912
+ *
4913
+ * @param {string} value
4914
+ */
4915
+ function (value) {
4911
4916
  updateHTML(value);
4912
4917
  }, [updateHTML]);
4913
4918
  var emitChange = useEmit(textInputRef, onResize, onChange);
@@ -4921,10 +4926,10 @@ function InputEmoji(props, ref) {
4921
4926
  if (sanitizedTextRef.current !== value) {
4922
4927
  setValue(value);
4923
4928
  }
4924
- }, [sanitizedTextRef, setValue, value]);
4925
- React.useEffect(function () {
4926
- updateHTML();
4927
- }, [updateHTML]);
4929
+ }, [sanitizedTextRef, setValue, value]); // useEffect(() => {
4930
+ // updateHTML();
4931
+ // }, [updateHTML]);
4932
+
4928
4933
  React.useEffect(function () {
4929
4934
  /**
4930
4935
  * Handle keydown event
@@ -5005,7 +5010,10 @@ function InputEmoji(props, ref) {
5005
5010
 
5006
5011
  function handleTextInputChange(html) {
5007
5012
  sanitize(html);
5008
- emitChange(sanitizedTextRef.current);
5013
+
5014
+ if (value !== sanitizedTextRef.current) {
5015
+ emitChange(sanitizedTextRef.current);
5016
+ }
5009
5017
  }
5010
5018
  /**
5011
5019
  *
@@ -5029,8 +5037,24 @@ function InputEmoji(props, ref) {
5029
5037
 
5030
5038
 
5031
5039
  function handleCopy(event) {
5032
- event.clipboardData.setData("text", sanitizedTextRef.current);
5033
- event.preventDefault();
5040
+ var selection = window.getSelection();
5041
+
5042
+ if (selection !== null) {
5043
+ var selectedText = '';
5044
+
5045
+ if (selection.anchorNode && selection.anchorNode.nodeType === Node.ELEMENT_NODE) {
5046
+ // @ts-ignore
5047
+ selectedText = selection.anchorNode.innerHTML;
5048
+ } else if (selection.anchorNode && selection.anchorNode.nodeType === Node.TEXT_NODE) {
5049
+ var _selection$anchorNode;
5050
+
5051
+ selectedText = (_selection$anchorNode = selection.anchorNode.textContent) !== null && _selection$anchorNode !== void 0 ? _selection$anchorNode : '';
5052
+ }
5053
+
5054
+ var text = replaceAllTextEmojiToString(selectedText);
5055
+ event.clipboardData.setData("text", text);
5056
+ event.preventDefault();
5057
+ }
5034
5058
  }
5035
5059
  /**
5036
5060
  * Handle past on input