react-mentions 4.4.6 → 4.4.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -661,6 +661,10 @@ var omit = function omit(obj) {
661
661
 
662
662
  var _excluded = ["style", "className", "classNames"];
663
663
 
664
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
665
+
666
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
667
+
664
668
  function createDefaultStyle(defaultStyle, getModifiers) {
665
669
  var enhance = function enhance(ComponentToWrap) {
666
670
  var DefaultStyleEnhancer = function DefaultStyleEnhancer(_ref) {
@@ -681,17 +685,18 @@ function createDefaultStyle(defaultStyle, getModifiers) {
681
685
  };
682
686
 
683
687
  var displayName = ComponentToWrap.displayName || ComponentToWrap.name || 'Component';
684
- DefaultStyleEnhancer.displayName = "defaultStyle(".concat(displayName, ")");
685
- return DefaultStyleEnhancer;
688
+ DefaultStyleEnhancer.displayName = "defaultStyle(".concat(displayName, ")"); // return DefaultStyleEnhancer
689
+
690
+ return /*#__PURE__*/React__default.forwardRef(function (props, ref) {
691
+ return DefaultStyleEnhancer(_objectSpread(_objectSpread({}, props), {}, {
692
+ ref: ref
693
+ }));
694
+ });
686
695
  };
687
696
 
688
697
  return enhance;
689
698
  }
690
699
 
691
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
692
-
693
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
694
-
695
700
  var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
696
701
  if (!usedKeys.hasOwnProperty(id)) {
697
702
  usedKeys[id] = 0;
@@ -702,158 +707,126 @@ var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
702
707
  return id + '_' + usedKeys[id];
703
708
  };
704
709
 
705
- var Highlighter = /*#__PURE__*/function (_Component) {
706
- _inherits(Highlighter, _Component);
707
-
708
- var _super = _createSuper(Highlighter);
709
-
710
- function Highlighter() {
711
- var _this;
712
-
713
- _classCallCheck(this, Highlighter);
714
-
715
- _this = _super.apply(this, arguments);
716
-
717
- _defineProperty(_assertThisInitialized(_this), "setCaretElement", function (el) {
718
- _this.caretElement = el;
719
- });
720
-
721
- _this.state = {
722
- left: undefined,
723
- top: undefined
724
- };
725
- return _this;
726
- }
710
+ function Highlighter(_ref) {
711
+ var selectionStart = _ref.selectionStart,
712
+ selectionEnd = _ref.selectionEnd,
713
+ _ref$value = _ref.value,
714
+ value = _ref$value === void 0 ? '' : _ref$value,
715
+ onCaretPositionChange = _ref.onCaretPositionChange,
716
+ containerRef = _ref.containerRef,
717
+ children = _ref.children,
718
+ singleLine = _ref.singleLine,
719
+ style = _ref.style;
720
+
721
+ var _useState = React.useState({
722
+ left: undefined,
723
+ top: undefined
724
+ }),
725
+ _useState2 = _slicedToArray(_useState, 2),
726
+ position = _useState2[0],
727
+ setPosition = _useState2[1];
728
+
729
+ var _useState3 = React.useState(),
730
+ _useState4 = _slicedToArray(_useState3, 2),
731
+ caretElement = _useState4[0],
732
+ setCaretElement = _useState4[1];
733
+
734
+ React.useEffect(function () {
735
+ notifyCaretPosition();
736
+ });
727
737
 
728
- _createClass(Highlighter, [{
729
- key: "componentDidMount",
730
- value: function componentDidMount() {
731
- this.notifyCaretPosition();
738
+ var notifyCaretPosition = function notifyCaretPosition() {
739
+ if (!caretElement) {
740
+ return;
732
741
  }
733
- }, {
734
- key: "componentDidUpdate",
735
- value: function componentDidUpdate() {
736
- this.notifyCaretPosition();
737
- }
738
- }, {
739
- key: "notifyCaretPosition",
740
- value: function notifyCaretPosition() {
741
- if (!this.caretElement) {
742
- return;
743
- }
744
-
745
- var _this$caretElement = this.caretElement,
746
- offsetLeft = _this$caretElement.offsetLeft,
747
- offsetTop = _this$caretElement.offsetTop;
748
742
 
749
- if (this.state.left === offsetLeft && this.state.top === offsetTop) {
750
- return;
751
- }
743
+ var offsetLeft = caretElement.offsetLeft,
744
+ offsetTop = caretElement.offsetTop;
752
745
 
753
- var newPosition = {
754
- left: offsetLeft,
755
- top: offsetTop
756
- };
757
- this.setState(newPosition);
758
- this.props.onCaretPositionChange(newPosition);
746
+ if (position.left === offsetLeft && position.top === offsetTop) {
747
+ return;
759
748
  }
760
- }, {
761
- key: "render",
762
- value: function render() {
763
- var _this2 = this;
764
-
765
- var _this$props = this.props,
766
- selectionStart = _this$props.selectionStart,
767
- selectionEnd = _this$props.selectionEnd,
768
- value = _this$props.value,
769
- style = _this$props.style,
770
- children = _this$props.children,
771
- containerRef = _this$props.containerRef;
772
- var config = readConfigFromChildren(children); // If there's a caret (i.e. no range selection), map the caret position into the marked up value
773
749
 
774
- var caretPositionInMarkup;
750
+ var newPosition = {
751
+ left: offsetLeft,
752
+ top: offsetTop
753
+ };
754
+ setPosition(newPosition);
755
+ onCaretPositionChange(newPosition);
756
+ };
775
757
 
776
- if (selectionStart === selectionEnd) {
777
- caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
778
- }
758
+ var config = readConfigFromChildren(children);
759
+ var caretPositionInMarkup;
779
760
 
780
- var resultComponents = [];
781
- var componentKeys = {}; // start by appending directly to the resultComponents
761
+ if (selectionEnd === selectionStart) {
762
+ caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
763
+ }
782
764
 
783
- var components = resultComponents;
784
- var substringComponentKey = 0;
765
+ var resultComponents = [];
766
+ var componentKeys = {};
767
+ var components = resultComponents;
768
+ var substringComponentKey = 0;
769
+
770
+ var textIteratee = function textIteratee(substr, index, indexInPlainText) {
771
+ // check whether the caret element has to be inserted inside the current plain substring
772
+ if (isNumber(caretPositionInMarkup) && caretPositionInMarkup >= index && caretPositionInMarkup <= index + substr.length) {
773
+ // if yes, split substr at the caret position and insert the caret component
774
+ var splitIndex = caretPositionInMarkup - index;
775
+ components.push(renderSubstring(substr.substring(0, splitIndex), substringComponentKey)); // add all following substrings and mention components as children of the caret component
776
+
777
+ components = [renderSubstring(substr.substring(splitIndex), substringComponentKey)];
778
+ } else {
779
+ components.push(renderSubstring(substr, substringComponentKey));
780
+ }
785
781
 
786
- var textIteratee = function textIteratee(substr, index, indexInPlainText) {
787
- // check whether the caret element has to be inserted inside the current plain substring
788
- if (isNumber(caretPositionInMarkup) && caretPositionInMarkup >= index && caretPositionInMarkup <= index + substr.length) {
789
- // if yes, split substr at the caret position and insert the caret component
790
- var splitIndex = caretPositionInMarkup - index;
791
- components.push(_this2.renderSubstring(substr.substring(0, splitIndex), substringComponentKey)); // add all following substrings and mention components as children of the caret component
782
+ substringComponentKey++;
783
+ };
792
784
 
793
- components = [_this2.renderSubstring(substr.substring(splitIndex), substringComponentKey)];
794
- } else {
795
- // otherwise just push the plain text substring
796
- components.push(_this2.renderSubstring(substr, substringComponentKey));
797
- }
785
+ var mentionIteratee = function mentionIteratee(markup, index, indexInPlainText, id, display, mentionChildIndex, lastMentionEndIndex) {
786
+ var key = _generateComponentKey(componentKeys, id);
798
787
 
799
- substringComponentKey++;
800
- };
788
+ components.push(getMentionComponentForMatch(id, display, mentionChildIndex, key));
789
+ };
801
790
 
802
- var mentionIteratee = function mentionIteratee(markup, index, indexInPlainText, id, display, mentionChildIndex, lastMentionEndIndex) {
803
- // generate a component key based on the id
804
- var key = _generateComponentKey(componentKeys, id);
791
+ var renderSubstring = function renderSubstring(string, key) {
792
+ // set substring span to hidden, so that Emojis are not shown double in Mobile Safari
793
+ return /*#__PURE__*/React__default.createElement("span", _extends({}, style('substring'), {
794
+ key: key
795
+ }), string);
796
+ };
805
797
 
806
- components.push(_this2.getMentionComponentForMatch(id, display, mentionChildIndex, key));
807
- };
798
+ var getMentionComponentForMatch = function getMentionComponentForMatch(id, display, mentionChildIndex, key) {
799
+ var props = {
800
+ id: id,
801
+ display: display,
802
+ key: key
803
+ };
804
+ var child = React.Children.toArray(children)[mentionChildIndex];
805
+ return /*#__PURE__*/React__default.cloneElement(child, props);
806
+ };
808
807
 
809
- iterateMentionsMarkup(value, config, mentionIteratee, textIteratee); // append a span containing a space, to ensure the last text line has the correct height
808
+ var renderHighlighterCaret = function renderHighlighterCaret(children) {
809
+ return /*#__PURE__*/React__default.createElement("span", _extends({}, style('caret'), {
810
+ ref: setCaretElement,
811
+ key: "caret"
812
+ }), children);
813
+ };
810
814
 
811
- components.push(' ');
815
+ iterateMentionsMarkup(value, config, mentionIteratee, textIteratee); // append a span containing a space, to ensure the last text line has the correct height
812
816
 
813
- if (components !== resultComponents) {
814
- // if a caret component is to be rendered, add all components that followed as its children
815
- resultComponents.push(this.renderHighlighterCaret(components));
816
- }
817
+ components.push(' ');
817
818
 
818
- return /*#__PURE__*/React__default.createElement("div", _extends({}, style, {
819
- ref: containerRef
820
- }), resultComponents);
821
- }
822
- }, {
823
- key: "renderSubstring",
824
- value: function renderSubstring(string, key) {
825
- // set substring span to hidden, so that Emojis are not shown double in Mobile Safari
826
- return /*#__PURE__*/React__default.createElement("span", _extends({}, this.props.style('substring'), {
827
- key: key
828
- }), string);
829
- } // Returns a clone of the Mention child applicable for the specified type to be rendered inside the highlighter
830
-
831
- }, {
832
- key: "getMentionComponentForMatch",
833
- value: function getMentionComponentForMatch(id, display, mentionChildIndex, key) {
834
- var props = {
835
- id: id,
836
- display: display,
837
- key: key
838
- };
839
- var child = React.Children.toArray(this.props.children)[mentionChildIndex];
840
- return /*#__PURE__*/React__default.cloneElement(child, props);
841
- } // Renders an component to be inserted in the highlighter at the current caret position
842
-
843
- }, {
844
- key: "renderHighlighterCaret",
845
- value: function renderHighlighterCaret(children) {
846
- return /*#__PURE__*/React__default.createElement("span", _extends({}, this.props.style('caret'), {
847
- ref: this.setCaretElement,
848
- key: "caret"
849
- }), children);
850
- }
851
- }]);
819
+ if (components !== resultComponents) {
820
+ // if a caret component is to be rendered, add all components that followed as its children
821
+ resultComponents.push(renderHighlighterCaret(components));
822
+ }
852
823
 
853
- return Highlighter;
854
- }(React.Component);
824
+ return /*#__PURE__*/React__default.createElement("div", _extends({}, style, {
825
+ ref: containerRef
826
+ }), resultComponents);
827
+ }
855
828
 
856
- _defineProperty(Highlighter, "propTypes", {
829
+ Highlighter.propTypes = {
857
830
  selectionStart: PropTypes.number,
858
831
  selectionEnd: PropTypes.number,
859
832
  value: PropTypes.string.isRequired,
@@ -862,12 +835,7 @@ _defineProperty(Highlighter, "propTypes", {
862
835
  current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
863
836
  })]),
864
837
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
865
- });
866
-
867
- _defineProperty(Highlighter, "defaultProps", {
868
- value: ''
869
- });
870
-
838
+ };
871
839
  var styled = createDefaultStyle({
872
840
  position: 'relative',
873
841
  boxSizing: 'border-box',
@@ -989,162 +957,145 @@ function LoadingIndicator(_ref) {
989
957
 
990
958
  var defaultstyle = {};
991
959
 
992
- function _createSuper$1(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$1(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
993
-
994
- function _isNativeReflectConstruct$1() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
960
+ function SuggestionsOverlay(_ref) {
961
+ var id = _ref.id,
962
+ _ref$suggestions = _ref.suggestions,
963
+ suggestions = _ref$suggestions === void 0 ? {} : _ref$suggestions,
964
+ a11ySuggestionsListLabel = _ref.a11ySuggestionsListLabel,
965
+ focusIndex = _ref.focusIndex,
966
+ position = _ref.position,
967
+ left = _ref.left,
968
+ right = _ref.right,
969
+ top = _ref.top,
970
+ scrollFocusedIntoView = _ref.scrollFocusedIntoView,
971
+ isLoading = _ref.isLoading,
972
+ isOpened = _ref.isOpened,
973
+ _ref$onSelect = _ref.onSelect,
974
+ onSelect = _ref$onSelect === void 0 ? function () {
975
+ return null;
976
+ } : _ref$onSelect,
977
+ ignoreAccents = _ref.ignoreAccents,
978
+ containerRef = _ref.containerRef,
979
+ children = _ref.children,
980
+ style = _ref.style,
981
+ customSuggestionsContainer = _ref.customSuggestionsContainer,
982
+ onMouseDown = _ref.onMouseDown,
983
+ onMouseEnter = _ref.onMouseEnter;
984
+
985
+ var _useState = React.useState(undefined),
986
+ _useState2 = _slicedToArray(_useState, 2),
987
+ ulElement = _useState2[0],
988
+ setUlElement = _useState2[1];
989
+
990
+ React.useEffect(function () {
991
+ if (!ulElement || ulElement.offsetHeight >= ulElement.scrollHeight || !scrollFocusedIntoView) {
992
+ return;
993
+ }
995
994
 
996
- var SuggestionsOverlay = /*#__PURE__*/function (_Component) {
997
- _inherits(SuggestionsOverlay, _Component);
995
+ var scrollTop = ulElement.scrollTop;
998
996
 
999
- var _super = _createSuper$1(SuggestionsOverlay);
997
+ var _ulElement$children$f = ulElement.children[focusIndex].getBoundingClientRect(),
998
+ top = _ulElement$children$f.top,
999
+ bottom = _ulElement$children$f.bottom;
1000
1000
 
1001
- function SuggestionsOverlay() {
1002
- var _this;
1001
+ var _ulElement$getBoundin = ulElement.getBoundingClientRect(),
1002
+ topContainer = _ulElement$getBoundin.top;
1003
1003
 
1004
- _classCallCheck(this, SuggestionsOverlay);
1004
+ top = top - topContainer + scrollTop;
1005
+ bottom = bottom - topContainer + scrollTop;
1005
1006
 
1006
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1007
- args[_key] = arguments[_key];
1007
+ if (top < scrollTop) {
1008
+ ulElement.scrollTop = top;
1009
+ } else if (bottom > ulElement.offsetHeight) {
1010
+ ulElement.scrollTop = bottom - ulElement.offsetHeight;
1008
1011
  }
1012
+ }, [focusIndex, scrollFocusedIntoView, ulElement]);
1009
1013
 
1010
- _this = _super.call.apply(_super, [this].concat(args));
1014
+ var renderSuggestions = function renderSuggestions() {
1015
+ var suggestionsToRender = /*#__PURE__*/React__default.createElement("ul", _extends({
1016
+ ref: setUlElement,
1017
+ id: id,
1018
+ role: "listbox",
1019
+ "aria-label": a11ySuggestionsListLabel
1020
+ }, style('list')), Object.values(suggestions).reduce(function (accResults, _ref2) {
1021
+ var results = _ref2.results,
1022
+ queryInfo = _ref2.queryInfo;
1023
+ return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
1024
+ return renderSuggestion(result, queryInfo, accResults.length + index);
1025
+ })));
1026
+ }, []));
1027
+ if (customSuggestionsContainer) return customSuggestionsContainer(suggestionsToRender);
1028
+ return suggestionsToRender;
1029
+ };
1011
1030
 
1012
- _defineProperty(_assertThisInitialized(_this), "handleMouseEnter", function (index, ev) {
1013
- if (_this.props.onMouseEnter) {
1014
- _this.props.onMouseEnter(index);
1031
+ var renderSuggestion = function renderSuggestion(result, queryInfo, index) {
1032
+ var isFocused = index === focusIndex;
1033
+ var childIndex = queryInfo.childIndex,
1034
+ query = queryInfo.query;
1035
+ var renderSuggestion = React.Children.toArray(children)[childIndex].props.renderSuggestion;
1036
+ return /*#__PURE__*/React__default.createElement(Suggestion$1, {
1037
+ style: style('item'),
1038
+ key: "".concat(childIndex, "-").concat(getID(result)),
1039
+ id: getSuggestionHtmlId(id, index),
1040
+ query: query,
1041
+ index: index,
1042
+ ignoreAccents: ignoreAccents,
1043
+ renderSuggestion: renderSuggestion,
1044
+ suggestion: result,
1045
+ focused: isFocused,
1046
+ onClick: function onClick() {
1047
+ return select(result, queryInfo);
1048
+ },
1049
+ onMouseEnter: function onMouseEnter() {
1050
+ return handleMouseEnter(index);
1015
1051
  }
1016
1052
  });
1053
+ };
1017
1054
 
1018
- _defineProperty(_assertThisInitialized(_this), "select", function (suggestion, queryInfo) {
1019
- _this.props.onSelect(suggestion, queryInfo);
1020
- });
1055
+ var renderLoadingIndicator = function renderLoadingIndicator() {
1056
+ if (!isLoading) {
1057
+ return;
1058
+ }
1021
1059
 
1022
- _defineProperty(_assertThisInitialized(_this), "setUlElement", function (el) {
1023
- _this.ulElement = el;
1060
+ return /*#__PURE__*/React__default.createElement(LoadingIndicator, {
1061
+ style: style('loadingIndicator')
1024
1062
  });
1063
+ };
1025
1064
 
1026
- return _this;
1027
- }
1028
-
1029
- _createClass(SuggestionsOverlay, [{
1030
- key: "componentDidUpdate",
1031
- value: function componentDidUpdate() {
1032
- if (!this.ulElement || this.ulElement.offsetHeight >= this.ulElement.scrollHeight || !this.props.scrollFocusedIntoView) {
1033
- return;
1034
- }
1035
-
1036
- var scrollTop = this.ulElement.scrollTop;
1037
-
1038
- var _this$ulElement$child = this.ulElement.children[this.props.focusIndex].getBoundingClientRect(),
1039
- top = _this$ulElement$child.top,
1040
- bottom = _this$ulElement$child.bottom;
1041
-
1042
- var _this$ulElement$getBo = this.ulElement.getBoundingClientRect(),
1043
- topContainer = _this$ulElement$getBo.top;
1044
-
1045
- top = top - topContainer + scrollTop;
1046
- bottom = bottom - topContainer + scrollTop;
1047
-
1048
- if (top < scrollTop) {
1049
- this.ulElement.scrollTop = top;
1050
- } else if (bottom > this.ulElement.offsetHeight) {
1051
- this.ulElement.scrollTop = bottom - this.ulElement.offsetHeight;
1052
- }
1065
+ var handleMouseEnter = function handleMouseEnter(index, ev) {
1066
+ if (onMouseEnter) {
1067
+ onMouseEnter(index);
1053
1068
  }
1054
- }, {
1055
- key: "render",
1056
- value: function render() {
1057
- var _this$props = this.props,
1058
- id = _this$props.id,
1059
- a11ySuggestionsListLabel = _this$props.a11ySuggestionsListLabel,
1060
- isOpened = _this$props.isOpened,
1061
- style = _this$props.style,
1062
- onMouseDown = _this$props.onMouseDown,
1063
- containerRef = _this$props.containerRef,
1064
- position = _this$props.position,
1065
- left = _this$props.left,
1066
- right = _this$props.right,
1067
- top = _this$props.top; // do not show suggestions until there is some data
1068
-
1069
- if (!isOpened) {
1070
- return null;
1071
- }
1069
+ };
1072
1070
 
1073
- return /*#__PURE__*/React__default.createElement("div", _extends({}, useStyles.inline({
1074
- position: position || 'absolute',
1075
- left: left,
1076
- right: right,
1077
- top: top
1078
- }, style), {
1079
- onMouseDown: onMouseDown,
1080
- ref: containerRef
1081
- }), /*#__PURE__*/React__default.createElement("ul", _extends({
1082
- ref: this.setUlElement,
1083
- id: id,
1084
- role: "listbox",
1085
- "aria-label": a11ySuggestionsListLabel
1086
- }, style('list')), this.renderSuggestions()), this.renderLoadingIndicator());
1087
- }
1088
- }, {
1089
- key: "renderSuggestions",
1090
- value: function renderSuggestions() {
1091
- var _this2 = this;
1071
+ var select = function select(suggestion, queryInfo) {
1072
+ onSelect(suggestion, queryInfo);
1073
+ };
1092
1074
 
1093
- var customSuggestionsContainer = this.props.customSuggestionsContainer;
1094
- var suggestions = Object.values(this.props.suggestions).reduce(function (accResults, _ref) {
1095
- var results = _ref.results,
1096
- queryInfo = _ref.queryInfo;
1097
- return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
1098
- return _this2.renderSuggestion(result, queryInfo, accResults.length + index);
1099
- })));
1100
- }, []);
1101
- if (customSuggestionsContainer) return customSuggestionsContainer(suggestions);else return suggestions;
1102
- }
1103
- }, {
1104
- key: "renderSuggestion",
1105
- value: function renderSuggestion(result, queryInfo, index) {
1106
- var _this3 = this;
1107
-
1108
- var isFocused = index === this.props.focusIndex;
1109
- var childIndex = queryInfo.childIndex,
1110
- query = queryInfo.query;
1111
- var renderSuggestion = React.Children.toArray(this.props.children)[childIndex].props.renderSuggestion;
1112
- var ignoreAccents = this.props.ignoreAccents;
1113
- return /*#__PURE__*/React__default.createElement(Suggestion$1, {
1114
- style: this.props.style('item'),
1115
- key: "".concat(childIndex, "-").concat(getID(result)),
1116
- id: getSuggestionHtmlId(this.props.id, index),
1117
- query: query,
1118
- index: index,
1119
- ignoreAccents: ignoreAccents,
1120
- renderSuggestion: renderSuggestion,
1121
- suggestion: result,
1122
- focused: isFocused,
1123
- onClick: function onClick() {
1124
- return _this3.select(result, queryInfo);
1125
- },
1126
- onMouseEnter: function onMouseEnter() {
1127
- return _this3.handleMouseEnter(index);
1128
- }
1129
- });
1075
+ var getID = function getID(suggestion) {
1076
+ if (typeof suggestion === 'string') {
1077
+ return suggestion;
1130
1078
  }
1131
- }, {
1132
- key: "renderLoadingIndicator",
1133
- value: function renderLoadingIndicator() {
1134
- if (!this.props.isLoading) {
1135
- return;
1136
- }
1137
1079
 
1138
- return /*#__PURE__*/React__default.createElement(LoadingIndicator, {
1139
- style: this.props.style('loadingIndicator')
1140
- });
1141
- }
1142
- }]);
1080
+ return suggestion.id;
1081
+ };
1082
+
1083
+ if (!isOpened) {
1084
+ return null;
1085
+ }
1143
1086
 
1144
- return SuggestionsOverlay;
1145
- }(React.Component);
1087
+ return /*#__PURE__*/React__default.createElement("div", _extends({}, useStyles.inline({
1088
+ position: position || 'absolute',
1089
+ left: left,
1090
+ right: right,
1091
+ top: top
1092
+ }, style), {
1093
+ onMouseDown: onMouseDown,
1094
+ ref: containerRef
1095
+ }), renderSuggestions(), renderLoadingIndicator());
1096
+ }
1146
1097
 
1147
- _defineProperty(SuggestionsOverlay, "propTypes", {
1098
+ SuggestionsOverlay.propTypes = {
1148
1099
  id: PropTypes.string.isRequired,
1149
1100
  suggestions: PropTypes.object.isRequired,
1150
1101
  a11ySuggestionsListLabel: PropTypes.string,
@@ -1158,27 +1109,11 @@ _defineProperty(SuggestionsOverlay, "propTypes", {
1158
1109
  isOpened: PropTypes.bool.isRequired,
1159
1110
  onSelect: PropTypes.func,
1160
1111
  ignoreAccents: PropTypes.bool,
1112
+ customSuggestionsContainer: PropTypes.func,
1161
1113
  containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
1162
1114
  current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
1163
- })]),
1164
- children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
1165
- });
1166
-
1167
- _defineProperty(SuggestionsOverlay, "defaultProps", {
1168
- suggestions: {},
1169
- onSelect: function onSelect() {
1170
- return null;
1171
- }
1172
- });
1173
-
1174
- var getID = function getID(suggestion) {
1175
- if (typeof suggestion === 'string') {
1176
- return suggestion;
1177
- }
1178
-
1179
- return suggestion.id;
1115
+ })])
1180
1116
  };
1181
-
1182
1117
  var styled$2 = createDefaultStyle({
1183
1118
  zIndex: 1,
1184
1119
  backgroundColor: 'white',
@@ -1192,13 +1127,13 @@ var styled$2 = createDefaultStyle({
1192
1127
  });
1193
1128
  var SuggestionsOverlay$1 = styled$2(SuggestionsOverlay);
1194
1129
 
1195
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1130
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
1196
1131
 
1197
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1132
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
1198
1133
 
1199
- function _createSuper$2(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$2(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1134
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
1200
1135
 
1201
- function _isNativeReflectConstruct$2() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1136
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
1202
1137
  var makeTriggerRegex = function makeTriggerRegex(trigger) {
1203
1138
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1204
1139
 
@@ -1270,7 +1205,7 @@ var propTypes = {
1270
1205
  var MentionsInput = /*#__PURE__*/function (_React$Component) {
1271
1206
  _inherits(MentionsInput, _React$Component);
1272
1207
 
1273
- var _super = _createSuper$2(MentionsInput);
1208
+ var _super = _createSuper(MentionsInput);
1274
1209
 
1275
1210
  function MentionsInput(_props) {
1276
1211
  var _this;
@@ -1291,7 +1226,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1291
1226
 
1292
1227
  var props = omit(_this.props, ['style', 'classNames', 'className'], // substyle props
1293
1228
  keys(propTypes));
1294
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props), style('input')), {}, {
1229
+ return _objectSpread$1(_objectSpread$1(_objectSpread$1(_objectSpread$1({}, props), style('input')), {}, {
1295
1230
  value: _this.getPlainText(),
1296
1231
  onScroll: _this.updateHighlighterScroll
1297
1232
  }, !readOnly && !disabled && {
@@ -1330,6 +1265,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1330
1265
 
1331
1266
  _defineProperty(_assertThisInitialized(_this), "renderTextarea", function (props) {
1332
1267
  return /*#__PURE__*/React__default.createElement("textarea", _extends({
1268
+ autoFocus: true,
1333
1269
  ref: _this.setInputRef
1334
1270
  }, props));
1335
1271
  });
@@ -1834,7 +1770,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1834
1770
  if (queryId !== _this._queryId) return; // save in property so that multiple sync state updates from different mentions sources
1835
1771
  // won't overwrite each other
1836
1772
 
1837
- _this.suggestions = _objectSpread(_objectSpread({}, _this.suggestions), {}, _defineProperty({}, childIndex, {
1773
+ _this.suggestions = _objectSpread$1(_objectSpread$1({}, _this.suggestions), {}, _defineProperty({}, childIndex, {
1838
1774
  queryInfo: {
1839
1775
  childIndex: childIndex,
1840
1776
  query: query,
@@ -1939,7 +1875,8 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1939
1875
  selectionEnd: null,
1940
1876
  suggestions: {},
1941
1877
  caretPosition: null,
1942
- suggestionsPosition: {}
1878
+ suggestionsPosition: {},
1879
+ setSelectionAfterHandlePaste: false
1943
1880
  };
1944
1881
  return _this;
1945
1882
  }
@@ -1969,6 +1906,13 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1969
1906
  });
1970
1907
  this.setSelection(this.state.selectionStart, this.state.selectionEnd);
1971
1908
  }
1909
+
1910
+ if (this.state.setSelectionAfterHandlePaste) {
1911
+ this.setState({
1912
+ setSelectionAfterHandlePaste: false
1913
+ });
1914
+ this.setSelection(this.state.selectionStart, this.state.selectionEnd);
1915
+ }
1972
1916
  }
1973
1917
  }, {
1974
1918
  key: "componentWillUnmount",
@@ -1993,9 +1937,9 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1993
1937
 
1994
1938
  if (!this.supportsClipboardActions(event)) {
1995
1939
  return;
1996
- }
1940
+ } // event.preventDefault()
1941
+
1997
1942
 
1998
- event.preventDefault();
1999
1943
  var _this$state3 = this.state,
2000
1944
  selectionStart = _this$state3.selectionStart,
2001
1945
  selectionEnd = _this$state3.selectionEnd;
@@ -2010,7 +1954,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
2010
1954
  var newValue = spliceString(value, markupStartIndex, markupEndIndex, pastedMentions || pastedData).replace(/\r/g, '');
2011
1955
  var newPlainTextValue = getPlainText(newValue, config);
2012
1956
  var eventMock = {
2013
- target: _objectSpread(_objectSpread({}, event.target), {}, {
1957
+ target: _objectSpread$1(_objectSpread$1({}, event.target), {}, {
2014
1958
  value: newValue
2015
1959
  })
2016
1960
  };
@@ -2018,7 +1962,11 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
2018
1962
 
2019
1963
  var startOfMention = findStartOfMentionInPlainText(value, config, selectionStart);
2020
1964
  var nextPos = (startOfMention || selectionStart) + getPlainText(pastedMentions || pastedData, config).length;
2021
- this.setSelection(nextPos, nextPos);
1965
+ this.setState({
1966
+ selectionStart: nextPos,
1967
+ selectionEnd: nextPos,
1968
+ setSelectionAfterHandlePaste: true
1969
+ });
2022
1970
  }
2023
1971
  }, {
2024
1972
  key: "saveSelectionToClipboard",
@@ -2080,7 +2028,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
2080
2028
  var newValue = [value.slice(0, markupStartIndex), value.slice(markupEndIndex)].join('');
2081
2029
  var newPlainTextValue = getPlainText(newValue, config);
2082
2030
  var eventMock = {
2083
- target: _objectSpread(_objectSpread({}, event.target), {}, {
2031
+ target: _objectSpread$1(_objectSpread$1({}, event.target), {}, {
2084
2032
  value: newPlainTextValue
2085
2033
  })
2086
2034
  };
@@ -2137,7 +2085,7 @@ var styled$3 = createDefaultStyle({
2137
2085
  letterSpacing: 'inherit'
2138
2086
  },
2139
2087
  '&multiLine': {
2140
- input: _objectSpread({
2088
+ input: _objectSpread$1({
2141
2089
  height: '100%',
2142
2090
  bottom: 0,
2143
2091
  overflow: 'hidden',