react-input-emoji 5.6.5 → 5.6.7

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.es.js CHANGED
@@ -682,35 +682,100 @@ function totalCharacters(_ref2) {
682
682
  var emojisCount = (html.match(/<img/g) || []).length;
683
683
  return textCount + emojisCount;
684
684
  }
685
+ /**
686
+ *
687
+ * @param {HTMLDivElement} inputDiv
688
+ * @return {string}
689
+ */
690
+ function removeHtmlExceptBr(inputDiv) {
691
+ var temp = inputDiv.innerHTML.replace(/<br\s*\/?>/gi, "[BR]"); // temporarily replace <br> with placeholder
692
+ var stripped = temp.replace(/<[^>]+>/g, ""); // strip all html tags
693
+ var _final = stripped.replace(/\[BR\]/gi, "</br>"); // replace placeholders with <br>
694
+ return _final;
695
+ }
685
696
 
686
697
  /**
687
- * Set caret to the end of text value
688
- * @param {React.MutableRefObject<HTMLDivElement| null>} input
698
+ *
699
+ * @param {*} range
700
+ * @returns
689
701
  */
690
- function moveCaretToEnd(input) {
691
- var range;
692
- var selection;
693
- if (document.createRange && input.current) {
694
- range = document.createRange();
695
- range.selectNodeContents(input.current);
696
- range.collapse(false);
697
- selection = window.getSelection();
698
- if (selection) {
699
- selection.removeAllRanges();
700
- selection.addRange(range);
702
+ function getSelectionStart$1(range) {
703
+ var node = range.startContainer;
704
+ var offset = range.startOffset;
705
+
706
+ // Handle cases where the selection start node is not a text node
707
+ if (node.nodeType !== Node.TEXT_NODE) {
708
+ while (node.nodeType !== Node.TEXT_NODE) {
709
+ node = node.nextSibling;
710
+ if (!node) break;
701
711
  }
712
+ if (!node) {
713
+ node = range.commonAncestorContainer;
714
+ while (node.nodeType !== Node.TEXT_NODE) {
715
+ node = node.firstChild;
716
+ }
717
+ }
718
+ offset = 0;
702
719
  }
720
+ return {
721
+ node: node,
722
+ offset: offset
723
+ };
703
724
  }
725
+
704
726
  /**
705
727
  *
706
- * @param {HTMLDivElement} inputDiv
707
- * @return {string}
728
+ * @returns {Object} cursor
708
729
  */
709
- function removeHtmlExceptBr(inputDiv) {
710
- var temp = inputDiv.innerHTML.replace(/<br\s*\/?>/gi, '[BR]'); // temporarily replace <br> with placeholder
711
- var stripped = temp.replace(/<[^>]+>/g, ''); // strip all html tags
712
- var _final = stripped.replace(/\[BR\]/gi, '</br>'); // replace placeholders with <br>
713
- return _final;
730
+ function getCursor() {
731
+ var selection = window.getSelection();
732
+ var range = selection.getRangeAt(0);
733
+ var selectionStart = getSelectionStart$1(range);
734
+ return {
735
+ selection: selection,
736
+ range: range,
737
+ selectionStart: selectionStart
738
+ };
739
+ }
740
+
741
+ /**
742
+ *
743
+ */
744
+ function addLineBreak() {
745
+ var _getCursor = getCursor(),
746
+ selection = _getCursor.selection,
747
+ range = _getCursor.range,
748
+ selectionStart = _getCursor.selectionStart;
749
+
750
+ // If cursor is at the end of the text content, add one more line break
751
+ if (selection.isCollapsed && selectionStart.offset === selectionStart.node.textContent.length) {
752
+ var br = document.createElement("br");
753
+ range.insertNode(br);
754
+ range.setStartAfter(br);
755
+ range.setEndAfter(br);
756
+ selection.removeAllRanges();
757
+ selection.addRange(range);
758
+ var br2 = document.createElement("br");
759
+ range.insertNode(br2);
760
+ range.setStartAfter(br2);
761
+ range.setEndAfter(br2);
762
+ selection.removeAllRanges();
763
+ selection.addRange(range);
764
+ } else {
765
+ var _br = document.createElement("br");
766
+ range.insertNode(_br);
767
+ range.setStartAfter(_br);
768
+ range.setEndAfter(_br);
769
+ selection.removeAllRanges();
770
+ selection.addRange(range);
771
+ // Set cursor position right before the first letter after the line break
772
+ if (selectionStart.node.nextSibling && selectionStart.node.nextSibling.nodeType === Node.TEXT_NODE) {
773
+ range.setStart(selectionStart.node.nextSibling, 1);
774
+ range.setEnd(selectionStart.node.nextSibling, 1);
775
+ }
776
+ selection.removeAllRanges();
777
+ selection.addRange(range);
778
+ }
714
779
  }
715
780
 
716
781
  // @ts-check
@@ -969,8 +1034,7 @@ var TextInput = function TextInput(_ref, ref) {
969
1034
  if (event.key === "Enter" && (event.shiftKey === true || event.ctrlKey === true) && props.shouldReturn) {
970
1035
  event.preventDefault();
971
1036
  if (textInputRef.current) {
972
- textInputRef.current.innerHTML = "".concat(textInputRef.current.innerHTML, "</br></br>");
973
- moveCaretToEnd(textInputRef);
1037
+ addLineBreak();
974
1038
  return;
975
1039
  }
976
1040
  }
@@ -3549,12 +3613,31 @@ function EmojiPicker(props) {
3549
3613
  categoryies = [].concat(_toConsumableArray(categoryies), ["people", "nature", "foods", "activity", "places", "objects", "symbols", "flags"]);
3550
3614
  return categoryies;
3551
3615
  }, [disableRecent]);
3552
- var i18n = useMemo(function () {
3616
+ var _useState = useState(undefined),
3617
+ _useState2 = _slicedToArray(_useState, 2),
3618
+ i18n = _useState2[0],
3619
+ setI18n = _useState2[1];
3620
+ useEffect(function () {
3553
3621
  if (!language) {
3554
- return undefined;
3622
+ // @ts-ignore
3623
+ Promise.resolve().then(function () { return en$1; }).then(function (translations) {
3624
+ setI18n(translations);
3625
+ })["catch"](function (error) {
3626
+ console.error("Failed to load translations:", error);
3627
+ });
3628
+ return;
3555
3629
  }
3556
- return require("@emoji-mart/data/i18n/".concat(language !== null && language !== void 0 ? language : 'en', ".json"));
3630
+
3631
+ // @ts-ignore
3632
+ import("@emoji-mart/data/i18n/".concat(language, ".json")).then(function (translations) {
3633
+ setI18n(translations);
3634
+ })["catch"](function (error) {
3635
+ console.error("Failed to load translations:", error);
3636
+ });
3557
3637
  }, [language]);
3638
+ if (!i18n) {
3639
+ return null;
3640
+ }
3558
3641
  return /*#__PURE__*/React.createElement($e5534fc185f7111e$export$2e2bcd8739ae039, {
3559
3642
  data: undefined,
3560
3643
  theme: theme,
@@ -4616,5 +4699,54 @@ InputEmojiWithRef.defaultProps = {
4616
4699
  language: undefined
4617
4700
  };
4618
4701
 
4702
+ var search = "Search";
4703
+ var search_no_results_1 = "Oh no!";
4704
+ var search_no_results_2 = "That emoji couldn’t be found";
4705
+ var pick = "Pick an emoji…";
4706
+ var add_custom = "Add custom emoji";
4707
+ var categories = {
4708
+ activity: "Activity",
4709
+ custom: "Custom",
4710
+ flags: "Flags",
4711
+ foods: "Food & Drink",
4712
+ frequent: "Frequently used",
4713
+ nature: "Animals & Nature",
4714
+ objects: "Objects",
4715
+ people: "Smileys & People",
4716
+ places: "Travel & Places",
4717
+ search: "Search Results",
4718
+ symbols: "Symbols"
4719
+ };
4720
+ var skins = {
4721
+ "1": "Default",
4722
+ "2": "Light",
4723
+ "3": "Medium-Light",
4724
+ "4": "Medium",
4725
+ "5": "Medium-Dark",
4726
+ "6": "Dark",
4727
+ choose: "Choose default skin tone"
4728
+ };
4729
+ var en = {
4730
+ search: search,
4731
+ search_no_results_1: search_no_results_1,
4732
+ search_no_results_2: search_no_results_2,
4733
+ pick: pick,
4734
+ add_custom: add_custom,
4735
+ categories: categories,
4736
+ skins: skins
4737
+ };
4738
+
4739
+ var en$1 = /*#__PURE__*/Object.freeze({
4740
+ __proto__: null,
4741
+ search: search,
4742
+ search_no_results_1: search_no_results_1,
4743
+ search_no_results_2: search_no_results_2,
4744
+ pick: pick,
4745
+ add_custom: add_custom,
4746
+ categories: categories,
4747
+ skins: skins,
4748
+ 'default': en
4749
+ });
4750
+
4619
4751
  export { InputEmojiWithRef as default };
4620
4752
  //# sourceMappingURL=index.es.js.map