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.js CHANGED
@@ -5,6 +5,24 @@ var ReactDOM = require('react-dom');
5
5
 
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
8
+ function _interopNamespace(e) {
9
+ if (e && e.__esModule) return e;
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n["default"] = e;
23
+ return Object.freeze(n);
24
+ }
25
+
8
26
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
9
27
  var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
10
28
 
@@ -689,35 +707,100 @@ function totalCharacters(_ref2) {
689
707
  var emojisCount = (html.match(/<img/g) || []).length;
690
708
  return textCount + emojisCount;
691
709
  }
710
+ /**
711
+ *
712
+ * @param {HTMLDivElement} inputDiv
713
+ * @return {string}
714
+ */
715
+ function removeHtmlExceptBr(inputDiv) {
716
+ var temp = inputDiv.innerHTML.replace(/<br\s*\/?>/gi, "[BR]"); // temporarily replace <br> with placeholder
717
+ var stripped = temp.replace(/<[^>]+>/g, ""); // strip all html tags
718
+ var _final = stripped.replace(/\[BR\]/gi, "</br>"); // replace placeholders with <br>
719
+ return _final;
720
+ }
692
721
 
693
722
  /**
694
- * Set caret to the end of text value
695
- * @param {React.MutableRefObject<HTMLDivElement| null>} input
723
+ *
724
+ * @param {*} range
725
+ * @returns
696
726
  */
697
- function moveCaretToEnd(input) {
698
- var range;
699
- var selection;
700
- if (document.createRange && input.current) {
701
- range = document.createRange();
702
- range.selectNodeContents(input.current);
703
- range.collapse(false);
704
- selection = window.getSelection();
705
- if (selection) {
706
- selection.removeAllRanges();
707
- selection.addRange(range);
727
+ function getSelectionStart$1(range) {
728
+ var node = range.startContainer;
729
+ var offset = range.startOffset;
730
+
731
+ // Handle cases where the selection start node is not a text node
732
+ if (node.nodeType !== Node.TEXT_NODE) {
733
+ while (node.nodeType !== Node.TEXT_NODE) {
734
+ node = node.nextSibling;
735
+ if (!node) break;
708
736
  }
737
+ if (!node) {
738
+ node = range.commonAncestorContainer;
739
+ while (node.nodeType !== Node.TEXT_NODE) {
740
+ node = node.firstChild;
741
+ }
742
+ }
743
+ offset = 0;
709
744
  }
745
+ return {
746
+ node: node,
747
+ offset: offset
748
+ };
710
749
  }
750
+
711
751
  /**
712
752
  *
713
- * @param {HTMLDivElement} inputDiv
714
- * @return {string}
753
+ * @returns {Object} cursor
715
754
  */
716
- function removeHtmlExceptBr(inputDiv) {
717
- var temp = inputDiv.innerHTML.replace(/<br\s*\/?>/gi, '[BR]'); // temporarily replace <br> with placeholder
718
- var stripped = temp.replace(/<[^>]+>/g, ''); // strip all html tags
719
- var _final = stripped.replace(/\[BR\]/gi, '</br>'); // replace placeholders with <br>
720
- return _final;
755
+ function getCursor() {
756
+ var selection = window.getSelection();
757
+ var range = selection.getRangeAt(0);
758
+ var selectionStart = getSelectionStart$1(range);
759
+ return {
760
+ selection: selection,
761
+ range: range,
762
+ selectionStart: selectionStart
763
+ };
764
+ }
765
+
766
+ /**
767
+ *
768
+ */
769
+ function addLineBreak() {
770
+ var _getCursor = getCursor(),
771
+ selection = _getCursor.selection,
772
+ range = _getCursor.range,
773
+ selectionStart = _getCursor.selectionStart;
774
+
775
+ // If cursor is at the end of the text content, add one more line break
776
+ if (selection.isCollapsed && selectionStart.offset === selectionStart.node.textContent.length) {
777
+ var br = document.createElement("br");
778
+ range.insertNode(br);
779
+ range.setStartAfter(br);
780
+ range.setEndAfter(br);
781
+ selection.removeAllRanges();
782
+ selection.addRange(range);
783
+ var br2 = document.createElement("br");
784
+ range.insertNode(br2);
785
+ range.setStartAfter(br2);
786
+ range.setEndAfter(br2);
787
+ selection.removeAllRanges();
788
+ selection.addRange(range);
789
+ } else {
790
+ var _br = document.createElement("br");
791
+ range.insertNode(_br);
792
+ range.setStartAfter(_br);
793
+ range.setEndAfter(_br);
794
+ selection.removeAllRanges();
795
+ selection.addRange(range);
796
+ // Set cursor position right before the first letter after the line break
797
+ if (selectionStart.node.nextSibling && selectionStart.node.nextSibling.nodeType === Node.TEXT_NODE) {
798
+ range.setStart(selectionStart.node.nextSibling, 1);
799
+ range.setEnd(selectionStart.node.nextSibling, 1);
800
+ }
801
+ selection.removeAllRanges();
802
+ selection.addRange(range);
803
+ }
721
804
  }
722
805
 
723
806
  // @ts-check
@@ -976,8 +1059,7 @@ var TextInput = function TextInput(_ref, ref) {
976
1059
  if (event.key === "Enter" && (event.shiftKey === true || event.ctrlKey === true) && props.shouldReturn) {
977
1060
  event.preventDefault();
978
1061
  if (textInputRef.current) {
979
- textInputRef.current.innerHTML = "".concat(textInputRef.current.innerHTML, "</br></br>");
980
- moveCaretToEnd(textInputRef);
1062
+ addLineBreak();
981
1063
  return;
982
1064
  }
983
1065
  }
@@ -3556,12 +3638,31 @@ function EmojiPicker(props) {
3556
3638
  categoryies = [].concat(_toConsumableArray(categoryies), ["people", "nature", "foods", "activity", "places", "objects", "symbols", "flags"]);
3557
3639
  return categoryies;
3558
3640
  }, [disableRecent]);
3559
- var i18n = React.useMemo(function () {
3641
+ var _useState = React.useState(undefined),
3642
+ _useState2 = _slicedToArray(_useState, 2),
3643
+ i18n = _useState2[0],
3644
+ setI18n = _useState2[1];
3645
+ React.useEffect(function () {
3560
3646
  if (!language) {
3561
- return undefined;
3647
+ // @ts-ignore
3648
+ Promise.resolve().then(function () { return en$1; }).then(function (translations) {
3649
+ setI18n(translations);
3650
+ })["catch"](function (error) {
3651
+ console.error("Failed to load translations:", error);
3652
+ });
3653
+ return;
3562
3654
  }
3563
- return require("@emoji-mart/data/i18n/".concat(language !== null && language !== void 0 ? language : 'en', ".json"));
3655
+
3656
+ // @ts-ignore
3657
+ (function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })("@emoji-mart/data/i18n/".concat(language, ".json")).then(function (translations) {
3658
+ setI18n(translations);
3659
+ })["catch"](function (error) {
3660
+ console.error("Failed to load translations:", error);
3661
+ });
3564
3662
  }, [language]);
3663
+ if (!i18n) {
3664
+ return null;
3665
+ }
3565
3666
  return /*#__PURE__*/React__default["default"].createElement($e5534fc185f7111e$export$2e2bcd8739ae039, {
3566
3667
  data: undefined,
3567
3668
  theme: theme,
@@ -4623,5 +4724,54 @@ InputEmojiWithRef.defaultProps = {
4623
4724
  language: undefined
4624
4725
  };
4625
4726
 
4727
+ var search = "Search";
4728
+ var search_no_results_1 = "Oh no!";
4729
+ var search_no_results_2 = "That emoji couldn’t be found";
4730
+ var pick = "Pick an emoji…";
4731
+ var add_custom = "Add custom emoji";
4732
+ var categories = {
4733
+ activity: "Activity",
4734
+ custom: "Custom",
4735
+ flags: "Flags",
4736
+ foods: "Food & Drink",
4737
+ frequent: "Frequently used",
4738
+ nature: "Animals & Nature",
4739
+ objects: "Objects",
4740
+ people: "Smileys & People",
4741
+ places: "Travel & Places",
4742
+ search: "Search Results",
4743
+ symbols: "Symbols"
4744
+ };
4745
+ var skins = {
4746
+ "1": "Default",
4747
+ "2": "Light",
4748
+ "3": "Medium-Light",
4749
+ "4": "Medium",
4750
+ "5": "Medium-Dark",
4751
+ "6": "Dark",
4752
+ choose: "Choose default skin tone"
4753
+ };
4754
+ var en = {
4755
+ search: search,
4756
+ search_no_results_1: search_no_results_1,
4757
+ search_no_results_2: search_no_results_2,
4758
+ pick: pick,
4759
+ add_custom: add_custom,
4760
+ categories: categories,
4761
+ skins: skins
4762
+ };
4763
+
4764
+ var en$1 = /*#__PURE__*/Object.freeze({
4765
+ __proto__: null,
4766
+ search: search,
4767
+ search_no_results_1: search_no_results_1,
4768
+ search_no_results_2: search_no_results_2,
4769
+ pick: pick,
4770
+ add_custom: add_custom,
4771
+ categories: categories,
4772
+ skins: skins,
4773
+ 'default': en
4774
+ });
4775
+
4626
4776
  module.exports = InputEmojiWithRef;
4627
4777
  //# sourceMappingURL=index.js.map