react-input-emoji 5.8.1 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -626,9 +626,22 @@ function handleCopy(event) {
626
626
  event.preventDefault();
627
627
  }
628
628
 
629
+ /** @type {Range|undefined} */
630
+ /** @type {Range|undefined} */
631
+ var currentRangeCached;
632
+
629
633
  /**
630
- *
631
- * @param {string} html
634
+ * Caches the current text selection range
635
+ */
636
+ function cacheCurrentRange() {
637
+ var selection = window.getSelection();
638
+ if (!selection.rangeCount || (selection === null || selection === void 0 ? void 0 : selection.anchorNode['className']) !== 'react-input-emoji--input' && selection.anchorNode.parentNode['className'] !== 'react-input-emoji--input') return;
639
+ var range = selection.getRangeAt(0);
640
+ currentRangeCached = range.cloneRange();
641
+ }
642
+
643
+ /**
644
+ * @param {string} html - HTML string to be pasted at the caret position
632
645
  */
633
646
  function handlePasteHtmlAtCaret(html) {
634
647
  var sel;
@@ -638,7 +651,8 @@ function handlePasteHtmlAtCaret(html) {
638
651
  sel = window.getSelection();
639
652
  if (sel === null) return;
640
653
  if (sel.getRangeAt && sel.rangeCount) {
641
- range = sel.getRangeAt(0);
654
+ var _currentRangeCached;
655
+ range = (_currentRangeCached = currentRangeCached) !== null && _currentRangeCached !== void 0 ? _currentRangeCached : sel.getRangeAt(0);
642
656
  range.deleteContents();
643
657
 
644
658
  // Range.createContextualFragment() would be useful here but is
@@ -656,6 +670,7 @@ function handlePasteHtmlAtCaret(html) {
656
670
  // Preserve the selection
657
671
  if (lastNode) {
658
672
  range = range.cloneRange();
673
+ currentRangeCached = range;
659
674
  range.setStartAfter(lastNode);
660
675
  range.collapse(true);
661
676
  sel.removeAllRanges();
@@ -4062,6 +4077,11 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
4062
4077
  _useState6 = _slicedToArray(_useState5, 2),
4063
4078
  emojiPickerPosition = _useState6[0],
4064
4079
  setEmojiPickerPosition = _useState6[1];
4080
+ React.useEffect(function () {
4081
+ if (showPicker) {
4082
+ cacheCurrentRange();
4083
+ }
4084
+ }, [showPicker]);
4065
4085
  React.useEffect(function () {
4066
4086
  addSanitizeFn(replaceAllTextEmojiToString);
4067
4087
  }, [addSanitizeFn]);