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.
- package/CHANGELOG.md +19 -0
- package/README.md +7 -19
- package/dist/react-mentions.cjs.dev.js +275 -372
- package/dist/react-mentions.cjs.prod.js +143 -296
- package/dist/react-mentions.esm.js +276 -373
- package/package.json +1 -1
|
@@ -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
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
|
|
746
|
-
|
|
747
|
-
offsetTop = _this$caretElement.offsetTop;
|
|
734
|
+
var offsetLeft = caretElement.offsetLeft,
|
|
735
|
+
offsetTop = caretElement.offsetTop;
|
|
748
736
|
|
|
749
|
-
|
|
750
|
-
|
|
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
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
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
|
-
|
|
784
|
-
|
|
749
|
+
var config = readConfigFromChildren(children);
|
|
750
|
+
var caretPositionInMarkup;
|
|
785
751
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
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
|
-
|
|
800
|
-
|
|
773
|
+
substringComponentKey++;
|
|
774
|
+
};
|
|
801
775
|
|
|
802
|
-
|
|
803
|
-
|
|
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
|
-
|
|
807
|
-
|
|
779
|
+
components.push(getMentionComponentForMatch(id, display, mentionChildIndex, key));
|
|
780
|
+
};
|
|
808
781
|
|
|
809
|
-
|
|
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
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
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
|
-
|
|
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
|
-
|
|
845
|
-
|
|
846
|
-
|
|
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
|
|
854
|
-
|
|
815
|
+
return /*#__PURE__*/React__default.createElement("div", _extends({}, style, {
|
|
816
|
+
ref: containerRef
|
|
817
|
+
}), resultComponents);
|
|
818
|
+
}
|
|
855
819
|
|
|
856
|
-
|
|
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
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
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
|
|
872
|
+
var renderContent = function renderContent() {
|
|
873
|
+
var display = getDisplay();
|
|
874
|
+
var highlightedDisplay = renderHighlightedDisplay(display);
|
|
903
875
|
|
|
904
|
-
|
|
905
|
-
|
|
876
|
+
if (renderSuggestion) {
|
|
877
|
+
return renderSuggestion(suggestion, query, highlightedDisplay, index, focused);
|
|
878
|
+
}
|
|
906
879
|
|
|
907
|
-
return
|
|
908
|
-
}
|
|
880
|
+
return highlightedDisplay;
|
|
881
|
+
};
|
|
909
882
|
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
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
|
-
|
|
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
|
-
|
|
945
|
-
|
|
946
|
-
|
|
891
|
+
if (id === undefined || !display) {
|
|
892
|
+
return id;
|
|
893
|
+
}
|
|
947
894
|
|
|
948
|
-
|
|
949
|
-
|
|
895
|
+
return display;
|
|
896
|
+
};
|
|
950
897
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
}
|
|
898
|
+
var renderHighlightedDisplay = function renderHighlightedDisplay(display) {
|
|
899
|
+
var i = getSubstringIndex(display, query, ignoreAccents);
|
|
954
900
|
|
|
955
|
-
|
|
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
|
-
|
|
967
|
-
|
|
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
|
|
975
|
-
|
|
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
|
-
|
|
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
|
|
1015
|
-
|
|
1016
|
-
|
|
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
|
|
1019
|
-
_inherits(SuggestionsOverlay, _Component);
|
|
986
|
+
var scrollTop = ulElement.scrollTop;
|
|
1020
987
|
|
|
1021
|
-
|
|
988
|
+
var _ulElement$children$f = ulElement.children[focusIndex].getBoundingClientRect(),
|
|
989
|
+
top = _ulElement$children$f.top,
|
|
990
|
+
bottom = _ulElement$children$f.bottom;
|
|
1022
991
|
|
|
1023
|
-
|
|
1024
|
-
|
|
992
|
+
var _ulElement$getBoundin = ulElement.getBoundingClientRect(),
|
|
993
|
+
topContainer = _ulElement$getBoundin.top;
|
|
1025
994
|
|
|
1026
|
-
|
|
995
|
+
top = top - topContainer + scrollTop;
|
|
996
|
+
bottom = bottom - topContainer + scrollTop;
|
|
1027
997
|
|
|
1028
|
-
|
|
1029
|
-
|
|
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
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
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
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1040
|
+
var renderLoadingIndicator = function renderLoadingIndicator() {
|
|
1041
|
+
if (!isLoading) {
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1043
1044
|
|
|
1044
|
-
|
|
1045
|
-
|
|
1045
|
+
return /*#__PURE__*/React__default.createElement(LoadingIndicator, {
|
|
1046
|
+
style: style('loadingIndicator')
|
|
1046
1047
|
});
|
|
1048
|
+
};
|
|
1047
1049
|
|
|
1048
|
-
|
|
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
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
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
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
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
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1065
|
+
return suggestion.id;
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
if (!isOpened) {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1165
1071
|
|
|
1166
|
-
return
|
|
1167
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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;
|