react-input-emoji 5.8.0 → 5.9.0

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
@@ -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();
@@ -1738,6 +1753,9 @@ var $f72b75cf796873c7$export$2e2bcd8739ae039 = {
1738
1753
  };
1739
1754
  const $c84d045dcc34faf5$var$CACHE = new Map();
1740
1755
  const $c84d045dcc34faf5$var$VERSIONS = [{
1756
+ v: 15,
1757
+ emoji: "\uD83E\uDEE8"
1758
+ }, {
1741
1759
  v: 14,
1742
1760
  emoji: "\uD83E\uDEE0"
1743
1761
  }, {
@@ -1917,8 +1935,8 @@ var $b247ea80b67298d5$export$2e2bcd8739ae039 = {
1917
1935
  value: 24
1918
1936
  },
1919
1937
  emojiVersion: {
1920
- value: 14,
1921
- choices: [1, 2, 3, 4, 5, 11, 12, 12.1, 13, 13.1, 14]
1938
+ value: 15,
1939
+ choices: [1, 2, 3, 4, 5, 11, 12, 12.1, 13, 13.1, 14, 15]
1922
1940
  },
1923
1941
  exceptEmojis: {
1924
1942
  value: []
@@ -1929,7 +1947,7 @@ var $b247ea80b67298d5$export$2e2bcd8739ae039 = {
1929
1947
  },
1930
1948
  locale: {
1931
1949
  value: "en",
1932
- choices: ["en", "ar", "be", "cs", "de", "es", "fa", "fi", "fr", "hi", "it", "ja", "kr", "nl", "pl", "pt", "ru", "sa", "tr", "uk", "vi", "zh"]
1950
+ choices: ["en", "ar", "be", "cs", "de", "es", "fa", "fi", "fr", "hi", "it", "ja", "ko", "nl", "pl", "pt", "ru", "sa", "tr", "uk", "vi", "zh"]
1933
1951
  },
1934
1952
  maxFrequentRows: {
1935
1953
  value: 4
@@ -2448,8 +2466,8 @@ function $254755d3f438722f$export$2e2bcd8739ae039(props) {
2448
2466
  emoji || (emoji = ($c4d155af13ad4d4b$export$2e2bcd8739ae039).get(id || props.native));
2449
2467
  if (!emoji) return props.fallback;
2450
2468
  const emojiSkin = emoji.skins[skin - 1] || emoji.skins[0];
2451
- const imageSrc = emojiSkin.src || (props.set != "native" && !props.spritesheet ? typeof props.getImageURL === "function" ? props.getImageURL(props.set, emojiSkin.unified) : `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@14.0.0/img/${props.set}/64/${emojiSkin.unified}.png` : undefined);
2452
- const spritesheetSrc = typeof props.getSpritesheetURL === "function" ? props.getSpritesheetURL(props.set) : `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@14.0.0/img/${props.set}/sheets-256/64.png`;
2469
+ const imageSrc = emojiSkin.src || (props.set != "native" && !props.spritesheet ? typeof props.getImageURL === "function" ? props.getImageURL(props.set, emojiSkin.unified) : `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@15.0.1/img/${props.set}/64/${emojiSkin.unified}.png` : undefined);
2470
+ const spritesheetSrc = typeof props.getSpritesheetURL === "function" ? props.getSpritesheetURL(props.set) : `https://cdn.jsdelivr.net/npm/emoji-datasource-${props.set}@15.0.1/img/${props.set}/sheets-256/64.png`;
2453
2471
  return /*#__PURE__*/($bd9dd35321b03dd4$export$34b9dba7ce09269b)("span", {
2454
2472
  class: "emoji-mart-emoji",
2455
2473
  "data-emoji-set": props.set,
@@ -2972,6 +2990,7 @@ class $89bd6bb200cc8fef$export$2e2bcd8739ae039 extends ($fb96b826c0c5f37a$export
2972
2990
  }
2973
2991
  unregister() {
2974
2992
  document.removeEventListener("click", this.handleClickOutside);
2993
+ this.darkMedia?.removeEventListener("change", this.darkMediaCallback);
2975
2994
  this.unobserve();
2976
2995
  }
2977
2996
  observe() {
@@ -3029,12 +3048,7 @@ class $89bd6bb200cc8fef$export$2e2bcd8739ae039 extends ($fb96b826c0c5f37a$export
3029
3048
  if (!this.darkMedia) {
3030
3049
  this.darkMedia = matchMedia("(prefers-color-scheme: dark)");
3031
3050
  if (this.darkMedia.media.match(/^not/)) return "light";
3032
- this.darkMedia.addListener(() => {
3033
- if (this.props.theme != "auto") return;
3034
- this.setState({
3035
- theme: this.darkMedia.matches ? "dark" : "light"
3036
- });
3037
- });
3051
+ this.darkMedia.addEventListener("change", this.darkMediaCallback);
3038
3052
  }
3039
3053
  return this.darkMedia.matches ? "dark" : "light";
3040
3054
  }
@@ -3639,6 +3653,12 @@ class $89bd6bb200cc8fef$export$2e2bcd8739ae039 extends ($fb96b826c0c5f37a$export
3639
3653
  }
3640
3654
  constructor(props) {
3641
3655
  super();
3656
+ ($c770c458706daa72$export$2e2bcd8739ae039)(this, "darkMediaCallback", () => {
3657
+ if (this.props.theme != "auto") return;
3658
+ this.setState({
3659
+ theme: this.darkMedia.matches ? "dark" : "light"
3660
+ });
3661
+ });
3642
3662
  ($c770c458706daa72$export$2e2bcd8739ae039)(this, "handleClickOutside", e => {
3643
3663
  const {
3644
3664
  element: element
@@ -4057,6 +4077,11 @@ var EmojiPickerWrapper = function EmojiPickerWrapper(props) {
4057
4077
  _useState6 = _slicedToArray(_useState5, 2),
4058
4078
  emojiPickerPosition = _useState6[0],
4059
4079
  setEmojiPickerPosition = _useState6[1];
4080
+ React.useEffect(function () {
4081
+ if (showPicker) {
4082
+ cacheCurrentRange();
4083
+ }
4084
+ }, [showPicker]);
4060
4085
  React.useEffect(function () {
4061
4086
  addSanitizeFn(replaceAllTextEmojiToString);
4062
4087
  }, [addSanitizeFn]);