react-mentions 4.4.4 → 4.4.7

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.
@@ -688,10 +688,6 @@ function createDefaultStyle(defaultStyle, getModifiers) {
688
688
  return enhance;
689
689
  }
690
690
 
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
691
  var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
696
692
  if (!usedKeys.hasOwnProperty(id)) {
697
693
  usedKeys[id] = 0;
@@ -702,158 +698,126 @@ var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
702
698
  return id + '_' + usedKeys[id];
703
699
  };
704
700
 
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
- }
727
-
728
- _createClass(Highlighter, [{
729
- key: "componentDidMount",
730
- value: function componentDidMount() {
731
- this.notifyCaretPosition();
732
- }
733
- }, {
734
- key: "componentDidUpdate",
735
- value: function componentDidUpdate() {
736
- this.notifyCaretPosition();
701
+ function Highlighter(_ref) {
702
+ var selectionStart = _ref.selectionStart,
703
+ selectionEnd = _ref.selectionEnd,
704
+ _ref$value = _ref.value,
705
+ value = _ref$value === void 0 ? '' : _ref$value,
706
+ onCaretPositionChange = _ref.onCaretPositionChange,
707
+ containerRef = _ref.containerRef,
708
+ children = _ref.children,
709
+ singleLine = _ref.singleLine,
710
+ style = _ref.style;
711
+
712
+ var _useState = React.useState({
713
+ left: undefined,
714
+ top: undefined
715
+ }),
716
+ _useState2 = _slicedToArray(_useState, 2),
717
+ position = _useState2[0],
718
+ setPosition = _useState2[1];
719
+
720
+ var _useState3 = React.useState(),
721
+ _useState4 = _slicedToArray(_useState3, 2),
722
+ caretElement = _useState4[0],
723
+ setCaretElement = _useState4[1];
724
+
725
+ React.useEffect(function () {
726
+ notifyCaretPosition();
727
+ }, [caretElement]);
728
+
729
+ var notifyCaretPosition = function notifyCaretPosition() {
730
+ if (!caretElement) {
731
+ return;
737
732
  }
738
- }, {
739
- key: "notifyCaretPosition",
740
- value: function notifyCaretPosition() {
741
- if (!this.caretElement) {
742
- return;
743
- }
744
733
 
745
- var _this$caretElement = this.caretElement,
746
- offsetLeft = _this$caretElement.offsetLeft,
747
- offsetTop = _this$caretElement.offsetTop;
734
+ var offsetLeft = caretElement.offsetLeft,
735
+ offsetTop = caretElement.offsetTop;
748
736
 
749
- if (this.state.left === offsetLeft && this.state.top === offsetTop) {
750
- return;
751
- }
752
-
753
- var newPosition = {
754
- left: offsetLeft,
755
- top: offsetTop
756
- };
757
- this.setState(newPosition);
758
- this.props.onCaretPositionChange(newPosition);
737
+ if (position.left === offsetLeft && position.top === offsetTop) {
738
+ return;
759
739
  }
760
- }, {
761
- key: "render",
762
- value: function render() {
763
- var _this2 = this;
764
740
 
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
-
774
- var caretPositionInMarkup;
775
-
776
- if (selectionStart === selectionEnd) {
777
- caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
778
- }
779
-
780
- var resultComponents = [];
781
- var componentKeys = {}; // start by appending directly to the resultComponents
741
+ var newPosition = {
742
+ left: offsetLeft,
743
+ top: offsetTop
744
+ };
745
+ setPosition(newPosition);
746
+ onCaretPositionChange(newPosition);
747
+ };
782
748
 
783
- var components = resultComponents;
784
- var substringComponentKey = 0;
749
+ var config = readConfigFromChildren(children);
750
+ var caretPositionInMarkup;
785
751
 
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
752
+ if (selectionEnd === selectionStart) {
753
+ caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
754
+ }
792
755
 
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
- }
756
+ var resultComponents = [];
757
+ var componentKeys = {};
758
+ var components = resultComponents;
759
+ var substringComponentKey = 0;
760
+
761
+ var textIteratee = function textIteratee(substr, index, indexInPlainText) {
762
+ // check whether the caret element has to be inserted inside the current plain substring
763
+ if (isNumber(caretPositionInMarkup) && caretPositionInMarkup >= index && caretPositionInMarkup <= index + substr.length) {
764
+ // if yes, split substr at the caret position and insert the caret component
765
+ var splitIndex = caretPositionInMarkup - index;
766
+ components.push(renderSubstring(substr.substring(0, splitIndex), substringComponentKey)); // add all following substrings and mention components as children of the caret component
767
+
768
+ components = [renderSubstring(substr.substring(splitIndex), substringComponentKey)];
769
+ } else {
770
+ components.push(renderSubstring(substr, substringComponentKey));
771
+ }
798
772
 
799
- substringComponentKey++;
800
- };
773
+ substringComponentKey++;
774
+ };
801
775
 
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);
776
+ var mentionIteratee = function mentionIteratee(markup, index, indexInPlainText, id, display, mentionChildIndex, lastMentionEndIndex) {
777
+ var key = _generateComponentKey(componentKeys, id);
805
778
 
806
- components.push(_this2.getMentionComponentForMatch(id, display, mentionChildIndex, key));
807
- };
779
+ components.push(getMentionComponentForMatch(id, display, mentionChildIndex, key));
780
+ };
808
781
 
809
- iterateMentionsMarkup(value, config, mentionIteratee, textIteratee); // append a span containing a space, to ensure the last text line has the correct height
782
+ var renderSubstring = function renderSubstring(string, key) {
783
+ // set substring span to hidden, so that Emojis are not shown double in Mobile Safari
784
+ return /*#__PURE__*/React__default.createElement("span", _extends({}, style('substring'), {
785
+ key: key
786
+ }), string);
787
+ };
810
788
 
811
- components.push(' ');
789
+ var getMentionComponentForMatch = function getMentionComponentForMatch(id, display, mentionChildIndex, key) {
790
+ var props = {
791
+ id: id,
792
+ display: display,
793
+ key: key
794
+ };
795
+ var child = React.Children.toArray(children)[mentionChildIndex];
796
+ return /*#__PURE__*/React__default.cloneElement(child, props);
797
+ };
812
798
 
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
- }
799
+ var renderHighlighterCaret = function renderHighlighterCaret(children) {
800
+ return /*#__PURE__*/React__default.createElement("span", _extends({}, style('caret'), {
801
+ ref: setCaretElement,
802
+ key: "caret"
803
+ }), children);
804
+ };
817
805
 
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
806
+ iterateMentionsMarkup(value, config, mentionIteratee, textIteratee); // append a span containing a space, to ensure the last text line has the correct height
830
807
 
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
808
+ components.push(' ');
842
809
 
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
- }]);
810
+ if (components !== resultComponents) {
811
+ // if a caret component is to be rendered, add all components that followed as its children
812
+ resultComponents.push(renderHighlighterCaret(components));
813
+ }
852
814
 
853
- return Highlighter;
854
- }(React.Component);
815
+ return /*#__PURE__*/React__default.createElement("div", _extends({}, style, {
816
+ ref: containerRef
817
+ }), resultComponents);
818
+ }
855
819
 
856
- _defineProperty(Highlighter, "propTypes", {
820
+ Highlighter.propTypes = {
857
821
  selectionStart: PropTypes.number,
858
822
  selectionEnd: PropTypes.number,
859
823
  value: PropTypes.string.isRequired,
@@ -862,12 +826,7 @@ _defineProperty(Highlighter, "propTypes", {
862
826
  current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
863
827
  })]),
864
828
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
865
- });
866
-
867
- _defineProperty(Highlighter, "defaultProps", {
868
- value: ''
869
- });
870
-
829
+ };
871
830
  var styled = createDefaultStyle({
872
831
  position: 'relative',
873
832
  boxSizing: 'border-box',
@@ -892,89 +851,68 @@ var styled = createDefaultStyle({
892
851
  });
893
852
  var Highlighter$1 = styled(Highlighter);
894
853
 
895
- 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); }; }
896
-
897
- 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; } }
898
-
899
- var Suggestion = /*#__PURE__*/function (_Component) {
900
- _inherits(Suggestion, _Component);
854
+ function Suggestion(_ref) {
855
+ var id = _ref.id,
856
+ focused = _ref.focused,
857
+ ignoreAccents = _ref.ignoreAccents,
858
+ index = _ref.index,
859
+ onClick = _ref.onClick,
860
+ onMouseEnter = _ref.onMouseEnter,
861
+ query = _ref.query,
862
+ renderSuggestion = _ref.renderSuggestion,
863
+ suggestion = _ref.suggestion,
864
+ style = _ref.style,
865
+ className = _ref.className,
866
+ classNames = _ref.classNames;
867
+ var rest = {
868
+ onClick: onClick,
869
+ onMouseEnter: onMouseEnter
870
+ };
901
871
 
902
- var _super = _createSuper$1(Suggestion);
872
+ var renderContent = function renderContent() {
873
+ var display = getDisplay();
874
+ var highlightedDisplay = renderHighlightedDisplay(display);
903
875
 
904
- function Suggestion() {
905
- _classCallCheck(this, Suggestion);
876
+ if (renderSuggestion) {
877
+ return renderSuggestion(suggestion, query, highlightedDisplay, index, focused);
878
+ }
906
879
 
907
- return _super.apply(this, arguments);
908
- }
880
+ return highlightedDisplay;
881
+ };
909
882
 
910
- _createClass(Suggestion, [{
911
- key: "render",
912
- value: function render() {
913
- var rest = omit(this.props, ['style', 'classNames', 'className'], // substyle props
914
- keys(Suggestion.propTypes));
915
- return /*#__PURE__*/React__default.createElement("li", _extends({
916
- id: this.props.id,
917
- role: "option",
918
- "aria-selected": this.props.focused
919
- }, rest, this.props.style), this.renderContent());
883
+ var getDisplay = function getDisplay() {
884
+ if (typeof suggestion === 'string') {
885
+ return suggestion;
920
886
  }
921
- }, {
922
- key: "renderContent",
923
- value: function renderContent() {
924
- var _this$props = this.props,
925
- query = _this$props.query,
926
- renderSuggestion = _this$props.renderSuggestion,
927
- suggestion = _this$props.suggestion,
928
- index = _this$props.index,
929
- focused = _this$props.focused;
930
- var display = this.getDisplay();
931
- var highlightedDisplay = this.renderHighlightedDisplay(display, query);
932
-
933
- if (renderSuggestion) {
934
- return renderSuggestion(suggestion, query, highlightedDisplay, index, focused);
935
- }
936
887
 
937
- return highlightedDisplay;
938
- }
939
- }, {
940
- key: "getDisplay",
941
- value: function getDisplay() {
942
- var suggestion = this.props.suggestion;
888
+ var id = suggestion.id,
889
+ display = suggestion.display;
943
890
 
944
- if (typeof suggestion === 'string') {
945
- return suggestion;
946
- }
891
+ if (id === undefined || !display) {
892
+ return id;
893
+ }
947
894
 
948
- var id = suggestion.id,
949
- display = suggestion.display;
895
+ return display;
896
+ };
950
897
 
951
- if (id === undefined || !display) {
952
- return id;
953
- }
898
+ var renderHighlightedDisplay = function renderHighlightedDisplay(display) {
899
+ var i = getSubstringIndex(display, query, ignoreAccents);
954
900
 
955
- return display;
901
+ if (i === -1) {
902
+ return /*#__PURE__*/React__default.createElement("span", style('display'), display);
956
903
  }
957
- }, {
958
- key: "renderHighlightedDisplay",
959
- value: function renderHighlightedDisplay(display) {
960
- var _this$props2 = this.props,
961
- ignoreAccents = _this$props2.ignoreAccents,
962
- query = _this$props2.query,
963
- style = _this$props2.style;
964
- var i = getSubstringIndex(display, query, ignoreAccents);
965
904
 
966
- if (i === -1) {
967
- return /*#__PURE__*/React__default.createElement("span", style('display'), display);
968
- }
969
-
970
- return /*#__PURE__*/React__default.createElement("span", style('display'), display.substring(0, i), /*#__PURE__*/React__default.createElement("b", style('highlight'), display.substring(i, i + query.length)), display.substring(i + query.length));
971
- }
972
- }]);
905
+ return /*#__PURE__*/React__default.createElement("span", style('display'), display.substring(0, i), /*#__PURE__*/React__default.createElement("b", style('highlight'), display.substring(i, i + query.length)), display.substring(i + query.length));
906
+ };
973
907
 
974
- return Suggestion;
975
- }(React.Component);
908
+ return /*#__PURE__*/React__default.createElement("li", _extends({
909
+ id: id,
910
+ role: "option",
911
+ "aria-selected": focused
912
+ }, rest, style), renderContent());
913
+ }
976
914
 
977
- _defineProperty(Suggestion, "propTypes", {
915
+ Suggestion.propTypes = {
978
916
  id: PropTypes.string.isRequired,
979
917
  query: PropTypes.string.isRequired,
980
918
  index: PropTypes.number.isRequired,
@@ -985,8 +923,7 @@ _defineProperty(Suggestion, "propTypes", {
985
923
  })]).isRequired,
986
924
  renderSuggestion: PropTypes.func,
987
925
  focused: PropTypes.bool
988
- });
989
-
926
+ };
990
927
  var styled$1 = createDefaultStyle({
991
928
  cursor: 'pointer'
992
929
  }, function (props) {
@@ -1011,162 +948,144 @@ function LoadingIndicator(_ref) {
1011
948
 
1012
949
  var defaultstyle = {};
1013
950
 
1014
- 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); }; }
1015
-
1016
- 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; } }
951
+ function SuggestionsOverlay(_ref) {
952
+ var id = _ref.id,
953
+ _ref$suggestions = _ref.suggestions,
954
+ suggestions = _ref$suggestions === void 0 ? {} : _ref$suggestions,
955
+ a11ySuggestionsListLabel = _ref.a11ySuggestionsListLabel,
956
+ focusIndex = _ref.focusIndex,
957
+ position = _ref.position,
958
+ left = _ref.left,
959
+ right = _ref.right,
960
+ top = _ref.top,
961
+ scrollFocusedIntoView = _ref.scrollFocusedIntoView,
962
+ isLoading = _ref.isLoading,
963
+ isOpened = _ref.isOpened,
964
+ _ref$onSelect = _ref.onSelect,
965
+ onSelect = _ref$onSelect === void 0 ? function () {
966
+ return null;
967
+ } : _ref$onSelect,
968
+ ignoreAccents = _ref.ignoreAccents,
969
+ containerRef = _ref.containerRef,
970
+ children = _ref.children,
971
+ style = _ref.style,
972
+ customSuggestionsContainer = _ref.customSuggestionsContainer,
973
+ onMouseDown = _ref.onMouseDown,
974
+ onMouseEnter = _ref.onMouseEnter;
975
+
976
+ var _useState = React.useState(),
977
+ _useState2 = _slicedToArray(_useState, 2),
978
+ ulElement = _useState2[0],
979
+ setUlElement = _useState2[1];
980
+
981
+ React.useEffect(function () {
982
+ if (!ulElement || ulElement.offsetHeight >= ulElement.scrollHeight || !scrollFocusedIntoView) {
983
+ return;
984
+ }
1017
985
 
1018
- var SuggestionsOverlay = /*#__PURE__*/function (_Component) {
1019
- _inherits(SuggestionsOverlay, _Component);
986
+ var scrollTop = ulElement.scrollTop;
1020
987
 
1021
- var _super = _createSuper$2(SuggestionsOverlay);
988
+ var _ulElement$children$f = ulElement.children[focusIndex].getBoundingClientRect(),
989
+ top = _ulElement$children$f.top,
990
+ bottom = _ulElement$children$f.bottom;
1022
991
 
1023
- function SuggestionsOverlay() {
1024
- var _this;
992
+ var _ulElement$getBoundin = ulElement.getBoundingClientRect(),
993
+ topContainer = _ulElement$getBoundin.top;
1025
994
 
1026
- _classCallCheck(this, SuggestionsOverlay);
995
+ top = top - topContainer + scrollTop;
996
+ bottom = bottom - topContainer + scrollTop;
1027
997
 
1028
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1029
- args[_key] = arguments[_key];
998
+ if (top < scrollTop) {
999
+ ulElement.scrollTop = top;
1000
+ } else if (bottom > ulElement.offsetHeight) {
1001
+ ulElement.scrollTop = bottom - ulElement.offsetHeight;
1030
1002
  }
1003
+ }, []);
1004
+
1005
+ var renderSuggestions = function renderSuggestions() {
1006
+ var suggestionsToRender = Object.values(suggestions).reduce(function (accResults, _ref2) {
1007
+ var results = _ref2.results,
1008
+ queryInfo = _ref2.queryInfo;
1009
+ return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
1010
+ return renderSuggestion(result, queryInfo, accResults.length + index);
1011
+ })));
1012
+ }, []);
1013
+ if (customSuggestionsContainer) return customSuggestionsContainer(suggestionsToRender);else return suggestionsToRender;
1014
+ };
1031
1015
 
1032
- _this = _super.call.apply(_super, [this].concat(args));
1033
-
1034
- _defineProperty(_assertThisInitialized(_this), "handleMouseEnter", function (index, ev) {
1035
- if (_this.props.onMouseEnter) {
1036
- _this.props.onMouseEnter(index);
1016
+ var renderSuggestion = function renderSuggestion(result, queryInfo, index) {
1017
+ var isFocused = index === focusIndex;
1018
+ var childIndex = queryInfo.childIndex,
1019
+ query = queryInfo.query;
1020
+ var renderSuggestion = React.Children.toArray(children)[childIndex].props.renderSuggestion;
1021
+ return /*#__PURE__*/React__default.createElement(Suggestion$1, {
1022
+ style: style('item'),
1023
+ key: "".concat(childIndex, "-").concat(getID(result)),
1024
+ id: getSuggestionHtmlId(id, index),
1025
+ query: query,
1026
+ index: index,
1027
+ ignoreAccents: ignoreAccents,
1028
+ renderSuggestion: renderSuggestion,
1029
+ suggestion: result,
1030
+ focused: isFocused,
1031
+ onClick: function onClick() {
1032
+ return select(result, queryInfo);
1033
+ },
1034
+ onMouseEnter: function onMouseEnter() {
1035
+ return handleMouseEnter(index);
1037
1036
  }
1038
1037
  });
1038
+ };
1039
1039
 
1040
- _defineProperty(_assertThisInitialized(_this), "select", function (suggestion, queryInfo) {
1041
- _this.props.onSelect(suggestion, queryInfo);
1042
- });
1040
+ var renderLoadingIndicator = function renderLoadingIndicator() {
1041
+ if (!isLoading) {
1042
+ return;
1043
+ }
1043
1044
 
1044
- _defineProperty(_assertThisInitialized(_this), "setUlElement", function (el) {
1045
- _this.ulElement = el;
1045
+ return /*#__PURE__*/React__default.createElement(LoadingIndicator, {
1046
+ style: style('loadingIndicator')
1046
1047
  });
1048
+ };
1047
1049
 
1048
- return _this;
1049
- }
1050
-
1051
- _createClass(SuggestionsOverlay, [{
1052
- key: "componentDidUpdate",
1053
- value: function componentDidUpdate() {
1054
- if (!this.ulElement || this.ulElement.offsetHeight >= this.ulElement.scrollHeight || !this.props.scrollFocusedIntoView) {
1055
- return;
1056
- }
1057
-
1058
- var scrollTop = this.ulElement.scrollTop;
1059
-
1060
- var _this$ulElement$child = this.ulElement.children[this.props.focusIndex].getBoundingClientRect(),
1061
- top = _this$ulElement$child.top,
1062
- bottom = _this$ulElement$child.bottom;
1063
-
1064
- var _this$ulElement$getBo = this.ulElement.getBoundingClientRect(),
1065
- topContainer = _this$ulElement$getBo.top;
1066
-
1067
- top = top - topContainer + scrollTop;
1068
- bottom = bottom - topContainer + scrollTop;
1069
-
1070
- if (top < scrollTop) {
1071
- this.ulElement.scrollTop = top;
1072
- } else if (bottom > this.ulElement.offsetHeight) {
1073
- this.ulElement.scrollTop = bottom - this.ulElement.offsetHeight;
1074
- }
1050
+ var handleMouseEnter = function handleMouseEnter(index, ev) {
1051
+ if (onMouseEnter) {
1052
+ onMouseEnter(index);
1075
1053
  }
1076
- }, {
1077
- key: "render",
1078
- value: function render() {
1079
- var _this$props = this.props,
1080
- id = _this$props.id,
1081
- a11ySuggestionsListLabel = _this$props.a11ySuggestionsListLabel,
1082
- isOpened = _this$props.isOpened,
1083
- style = _this$props.style,
1084
- onMouseDown = _this$props.onMouseDown,
1085
- containerRef = _this$props.containerRef,
1086
- position = _this$props.position,
1087
- left = _this$props.left,
1088
- right = _this$props.right,
1089
- top = _this$props.top; // do not show suggestions until there is some data
1090
-
1091
- if (!isOpened) {
1092
- return null;
1093
- }
1054
+ };
1094
1055
 
1095
- return /*#__PURE__*/React__default.createElement("div", _extends({}, useStyles.inline({
1096
- position: position || 'absolute',
1097
- left: left,
1098
- right: right,
1099
- top: top
1100
- }, style), {
1101
- onMouseDown: onMouseDown,
1102
- ref: containerRef
1103
- }), /*#__PURE__*/React__default.createElement("ul", _extends({
1104
- ref: this.setUlElement,
1105
- id: id,
1106
- role: "listbox",
1107
- "aria-label": a11ySuggestionsListLabel
1108
- }, style('list')), this.renderSuggestions()), this.renderLoadingIndicator());
1109
- }
1110
- }, {
1111
- key: "renderSuggestions",
1112
- value: function renderSuggestions() {
1113
- var _this2 = this;
1056
+ var select = function select(suggestion, queryInfo) {
1057
+ onSelect(suggestion, queryInfo);
1058
+ };
1114
1059
 
1115
- var customSuggestionsContainer = this.props.customSuggestionsContainer;
1116
- var suggestions = Object.values(this.props.suggestions).reduce(function (accResults, _ref) {
1117
- var results = _ref.results,
1118
- queryInfo = _ref.queryInfo;
1119
- return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
1120
- return _this2.renderSuggestion(result, queryInfo, accResults.length + index);
1121
- })));
1122
- }, []);
1123
- if (customSuggestionsContainer) return customSuggestionsContainer(suggestions);else return suggestions;
1060
+ var getID = function getID(suggestion) {
1061
+ if (typeof suggestion === 'string') {
1062
+ return suggestion;
1124
1063
  }
1125
- }, {
1126
- key: "renderSuggestion",
1127
- value: function renderSuggestion(result, queryInfo, index) {
1128
- var _this3 = this;
1129
-
1130
- var isFocused = index === this.props.focusIndex;
1131
- var childIndex = queryInfo.childIndex,
1132
- query = queryInfo.query;
1133
- var renderSuggestion = React.Children.toArray(this.props.children)[childIndex].props.renderSuggestion;
1134
- var ignoreAccents = this.props.ignoreAccents;
1135
- return /*#__PURE__*/React__default.createElement(Suggestion$1, {
1136
- style: this.props.style('item'),
1137
- key: "".concat(childIndex, "-").concat(getID(result)),
1138
- id: getSuggestionHtmlId(this.props.id, index),
1139
- query: query,
1140
- index: index,
1141
- ignoreAccents: ignoreAccents,
1142
- renderSuggestion: renderSuggestion,
1143
- suggestion: result,
1144
- focused: isFocused,
1145
- onClick: function onClick() {
1146
- return _this3.select(result, queryInfo);
1147
- },
1148
- onMouseEnter: function onMouseEnter() {
1149
- return _this3.handleMouseEnter(index);
1150
- }
1151
- });
1152
- }
1153
- }, {
1154
- key: "renderLoadingIndicator",
1155
- value: function renderLoadingIndicator() {
1156
- if (!this.props.isLoading) {
1157
- return;
1158
- }
1159
1064
 
1160
- return /*#__PURE__*/React__default.createElement(LoadingIndicator, {
1161
- style: this.props.style('loadingIndicator')
1162
- });
1163
- }
1164
- }]);
1065
+ return suggestion.id;
1066
+ };
1067
+
1068
+ if (!isOpened) {
1069
+ return null;
1070
+ }
1165
1071
 
1166
- return SuggestionsOverlay;
1167
- }(React.Component);
1072
+ return /*#__PURE__*/React__default.createElement("div", _extends({}, useStyles.inline({
1073
+ position: position || 'absolute',
1074
+ left: left,
1075
+ right: right,
1076
+ top: top
1077
+ }, style), {
1078
+ onMouseDown: onMouseDown,
1079
+ ref: containerRef
1080
+ }), /*#__PURE__*/React__default.createElement("ul", _extends({
1081
+ ref: setUlElement,
1082
+ id: id,
1083
+ role: "listbox",
1084
+ "aria-label": a11ySuggestionsListLabel
1085
+ }, style('list')), renderSuggestions()), renderLoadingIndicator());
1086
+ }
1168
1087
 
1169
- _defineProperty(SuggestionsOverlay, "propTypes", {
1088
+ SuggestionsOverlay.propTypes = {
1170
1089
  id: PropTypes.string.isRequired,
1171
1090
  suggestions: PropTypes.object.isRequired,
1172
1091
  a11ySuggestionsListLabel: PropTypes.string,
@@ -1180,27 +1099,11 @@ _defineProperty(SuggestionsOverlay, "propTypes", {
1180
1099
  isOpened: PropTypes.bool.isRequired,
1181
1100
  onSelect: PropTypes.func,
1182
1101
  ignoreAccents: PropTypes.bool,
1102
+ customSuggestionsContainer: PropTypes.any,
1183
1103
  containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
1184
1104
  current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
1185
- })]),
1186
- children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
1187
- });
1188
-
1189
- _defineProperty(SuggestionsOverlay, "defaultProps", {
1190
- suggestions: {},
1191
- onSelect: function onSelect() {
1192
- return null;
1193
- }
1194
- });
1195
-
1196
- var getID = function getID(suggestion) {
1197
- if (typeof suggestion === 'string') {
1198
- return suggestion;
1199
- }
1200
-
1201
- return suggestion.id;
1105
+ })])
1202
1106
  };
1203
-
1204
1107
  var styled$2 = createDefaultStyle({
1205
1108
  zIndex: 1,
1206
1109
  backgroundColor: 'white',
@@ -1218,9 +1121,9 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
1218
1121
 
1219
1122
  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; }
1220
1123
 
1221
- function _createSuper$3(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$3(); 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); }; }
1124
+ 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); }; }
1222
1125
 
1223
- function _isNativeReflectConstruct$3() { 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; } }
1126
+ 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; } }
1224
1127
  var makeTriggerRegex = function makeTriggerRegex(trigger) {
1225
1128
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1226
1129
 
@@ -1292,7 +1195,7 @@ var propTypes = {
1292
1195
  var MentionsInput = /*#__PURE__*/function (_React$Component) {
1293
1196
  _inherits(MentionsInput, _React$Component);
1294
1197
 
1295
- var _super = _createSuper$3(MentionsInput);
1198
+ var _super = _createSuper(MentionsInput);
1296
1199
 
1297
1200
  function MentionsInput(_props) {
1298
1201
  var _this;
@@ -1734,7 +1637,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
1734
1637
  // is small enough to NOT cover up the caret
1735
1638
 
1736
1639
 
1737
- if (allowSuggestionsAboveCursor && viewportRelative.top - highlighter.scrollTop + suggestions.offsetHeight > viewportHeight && suggestions.offsetHeight < caretOffsetParentRect.top - caretHeight - highlighter.scrollTop) {
1640
+ if (allowSuggestionsAboveCursor && viewportRelative.top - highlighter.scrollTop + suggestions.offsetHeight > viewportHeight && suggestions.offsetHeight < caretOffsetParentRect.top - caretHeight - highlighter.scrollTop || forceSuggestionsAboveCursor) {
1738
1641
  position.top = _top - suggestions.offsetHeight - caretHeight;
1739
1642
  } else {
1740
1643
  position.top = _top;