react-mentions 4.4.6 → 4.4.8
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 +18 -0
- package/README.md +1 -3
- package/dist/react-mentions.cjs.dev.js +259 -311
- package/dist/react-mentions.cjs.prod.js +169 -246
- package/dist/react-mentions.esm.js +260 -312
- package/package.json +1 -1
@@ -7,7 +7,7 @@ import _inherits from '@babel/runtime/helpers/esm/inherits';
|
|
7
7
|
import _possibleConstructorReturn from '@babel/runtime/helpers/esm/possibleConstructorReturn';
|
8
8
|
import _getPrototypeOf from '@babel/runtime/helpers/esm/getPrototypeOf';
|
9
9
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
10
|
-
import React, { Children,
|
10
|
+
import React, { Children, useState, useEffect } from 'react';
|
11
11
|
import invariant from 'invariant';
|
12
12
|
import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
|
13
13
|
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
@@ -653,6 +653,10 @@ var omit = function omit(obj) {
|
|
653
653
|
|
654
654
|
var _excluded = ["style", "className", "classNames"];
|
655
655
|
|
656
|
+
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; }
|
657
|
+
|
658
|
+
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; }
|
659
|
+
|
656
660
|
function createDefaultStyle(defaultStyle, getModifiers) {
|
657
661
|
var enhance = function enhance(ComponentToWrap) {
|
658
662
|
var DefaultStyleEnhancer = function DefaultStyleEnhancer(_ref) {
|
@@ -673,17 +677,18 @@ function createDefaultStyle(defaultStyle, getModifiers) {
|
|
673
677
|
};
|
674
678
|
|
675
679
|
var displayName = ComponentToWrap.displayName || ComponentToWrap.name || 'Component';
|
676
|
-
DefaultStyleEnhancer.displayName = "defaultStyle(".concat(displayName, ")");
|
677
|
-
|
680
|
+
DefaultStyleEnhancer.displayName = "defaultStyle(".concat(displayName, ")"); // return DefaultStyleEnhancer
|
681
|
+
|
682
|
+
return /*#__PURE__*/React.forwardRef(function (props, ref) {
|
683
|
+
return DefaultStyleEnhancer(_objectSpread(_objectSpread({}, props), {}, {
|
684
|
+
ref: ref
|
685
|
+
}));
|
686
|
+
});
|
678
687
|
};
|
679
688
|
|
680
689
|
return enhance;
|
681
690
|
}
|
682
691
|
|
683
|
-
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); }; }
|
684
|
-
|
685
|
-
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; } }
|
686
|
-
|
687
692
|
var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
|
688
693
|
if (!usedKeys.hasOwnProperty(id)) {
|
689
694
|
usedKeys[id] = 0;
|
@@ -694,158 +699,126 @@ var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
|
|
694
699
|
return id + '_' + usedKeys[id];
|
695
700
|
};
|
696
701
|
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
702
|
+
function Highlighter(_ref) {
|
703
|
+
var selectionStart = _ref.selectionStart,
|
704
|
+
selectionEnd = _ref.selectionEnd,
|
705
|
+
_ref$value = _ref.value,
|
706
|
+
value = _ref$value === void 0 ? '' : _ref$value,
|
707
|
+
onCaretPositionChange = _ref.onCaretPositionChange,
|
708
|
+
containerRef = _ref.containerRef,
|
709
|
+
children = _ref.children,
|
710
|
+
singleLine = _ref.singleLine,
|
711
|
+
style = _ref.style;
|
712
|
+
|
713
|
+
var _useState = useState({
|
714
|
+
left: undefined,
|
715
|
+
top: undefined
|
716
|
+
}),
|
717
|
+
_useState2 = _slicedToArray(_useState, 2),
|
718
|
+
position = _useState2[0],
|
719
|
+
setPosition = _useState2[1];
|
720
|
+
|
721
|
+
var _useState3 = useState(),
|
722
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
723
|
+
caretElement = _useState4[0],
|
724
|
+
setCaretElement = _useState4[1];
|
725
|
+
|
726
|
+
useEffect(function () {
|
727
|
+
notifyCaretPosition();
|
728
|
+
});
|
719
729
|
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
this.notifyCaretPosition();
|
730
|
+
var notifyCaretPosition = function notifyCaretPosition() {
|
731
|
+
if (!caretElement) {
|
732
|
+
return;
|
724
733
|
}
|
725
|
-
}, {
|
726
|
-
key: "componentDidUpdate",
|
727
|
-
value: function componentDidUpdate() {
|
728
|
-
this.notifyCaretPosition();
|
729
|
-
}
|
730
|
-
}, {
|
731
|
-
key: "notifyCaretPosition",
|
732
|
-
value: function notifyCaretPosition() {
|
733
|
-
if (!this.caretElement) {
|
734
|
-
return;
|
735
|
-
}
|
736
|
-
|
737
|
-
var _this$caretElement = this.caretElement,
|
738
|
-
offsetLeft = _this$caretElement.offsetLeft,
|
739
|
-
offsetTop = _this$caretElement.offsetTop;
|
740
734
|
|
741
|
-
|
742
|
-
|
743
|
-
}
|
735
|
+
var offsetLeft = caretElement.offsetLeft,
|
736
|
+
offsetTop = caretElement.offsetTop;
|
744
737
|
|
745
|
-
|
746
|
-
|
747
|
-
top: offsetTop
|
748
|
-
};
|
749
|
-
this.setState(newPosition);
|
750
|
-
this.props.onCaretPositionChange(newPosition);
|
738
|
+
if (position.left === offsetLeft && position.top === offsetTop) {
|
739
|
+
return;
|
751
740
|
}
|
752
|
-
}, {
|
753
|
-
key: "render",
|
754
|
-
value: function render() {
|
755
|
-
var _this2 = this;
|
756
|
-
|
757
|
-
var _this$props = this.props,
|
758
|
-
selectionStart = _this$props.selectionStart,
|
759
|
-
selectionEnd = _this$props.selectionEnd,
|
760
|
-
value = _this$props.value,
|
761
|
-
style = _this$props.style,
|
762
|
-
children = _this$props.children,
|
763
|
-
containerRef = _this$props.containerRef;
|
764
|
-
var config = readConfigFromChildren(children); // If there's a caret (i.e. no range selection), map the caret position into the marked up value
|
765
741
|
|
766
|
-
|
742
|
+
var newPosition = {
|
743
|
+
left: offsetLeft,
|
744
|
+
top: offsetTop
|
745
|
+
};
|
746
|
+
setPosition(newPosition);
|
747
|
+
onCaretPositionChange(newPosition);
|
748
|
+
};
|
767
749
|
|
768
|
-
|
769
|
-
|
770
|
-
}
|
750
|
+
var config = readConfigFromChildren(children);
|
751
|
+
var caretPositionInMarkup;
|
771
752
|
|
772
|
-
|
773
|
-
|
753
|
+
if (selectionEnd === selectionStart) {
|
754
|
+
caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
|
755
|
+
}
|
774
756
|
|
775
|
-
|
776
|
-
|
757
|
+
var resultComponents = [];
|
758
|
+
var componentKeys = {};
|
759
|
+
var components = resultComponents;
|
760
|
+
var substringComponentKey = 0;
|
761
|
+
|
762
|
+
var textIteratee = function textIteratee(substr, index, indexInPlainText) {
|
763
|
+
// check whether the caret element has to be inserted inside the current plain substring
|
764
|
+
if (isNumber(caretPositionInMarkup) && caretPositionInMarkup >= index && caretPositionInMarkup <= index + substr.length) {
|
765
|
+
// if yes, split substr at the caret position and insert the caret component
|
766
|
+
var splitIndex = caretPositionInMarkup - index;
|
767
|
+
components.push(renderSubstring(substr.substring(0, splitIndex), substringComponentKey)); // add all following substrings and mention components as children of the caret component
|
768
|
+
|
769
|
+
components = [renderSubstring(substr.substring(splitIndex), substringComponentKey)];
|
770
|
+
} else {
|
771
|
+
components.push(renderSubstring(substr, substringComponentKey));
|
772
|
+
}
|
777
773
|
|
778
|
-
|
779
|
-
|
780
|
-
if (isNumber(caretPositionInMarkup) && caretPositionInMarkup >= index && caretPositionInMarkup <= index + substr.length) {
|
781
|
-
// if yes, split substr at the caret position and insert the caret component
|
782
|
-
var splitIndex = caretPositionInMarkup - index;
|
783
|
-
components.push(_this2.renderSubstring(substr.substring(0, splitIndex), substringComponentKey)); // add all following substrings and mention components as children of the caret component
|
774
|
+
substringComponentKey++;
|
775
|
+
};
|
784
776
|
|
785
|
-
|
786
|
-
|
787
|
-
// otherwise just push the plain text substring
|
788
|
-
components.push(_this2.renderSubstring(substr, substringComponentKey));
|
789
|
-
}
|
777
|
+
var mentionIteratee = function mentionIteratee(markup, index, indexInPlainText, id, display, mentionChildIndex, lastMentionEndIndex) {
|
778
|
+
var key = _generateComponentKey(componentKeys, id);
|
790
779
|
|
791
|
-
|
792
|
-
|
780
|
+
components.push(getMentionComponentForMatch(id, display, mentionChildIndex, key));
|
781
|
+
};
|
793
782
|
|
794
|
-
|
795
|
-
|
796
|
-
|
783
|
+
var renderSubstring = function renderSubstring(string, key) {
|
784
|
+
// set substring span to hidden, so that Emojis are not shown double in Mobile Safari
|
785
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, style('substring'), {
|
786
|
+
key: key
|
787
|
+
}), string);
|
788
|
+
};
|
797
789
|
|
798
|
-
|
799
|
-
|
790
|
+
var getMentionComponentForMatch = function getMentionComponentForMatch(id, display, mentionChildIndex, key) {
|
791
|
+
var props = {
|
792
|
+
id: id,
|
793
|
+
display: display,
|
794
|
+
key: key
|
795
|
+
};
|
796
|
+
var child = Children.toArray(children)[mentionChildIndex];
|
797
|
+
return /*#__PURE__*/React.cloneElement(child, props);
|
798
|
+
};
|
800
799
|
|
801
|
-
|
800
|
+
var renderHighlighterCaret = function renderHighlighterCaret(children) {
|
801
|
+
return /*#__PURE__*/React.createElement("span", _extends({}, style('caret'), {
|
802
|
+
ref: setCaretElement,
|
803
|
+
key: "caret"
|
804
|
+
}), children);
|
805
|
+
};
|
802
806
|
|
803
|
-
|
807
|
+
iterateMentionsMarkup(value, config, mentionIteratee, textIteratee); // append a span containing a space, to ensure the last text line has the correct height
|
804
808
|
|
805
|
-
|
806
|
-
// if a caret component is to be rendered, add all components that followed as its children
|
807
|
-
resultComponents.push(this.renderHighlighterCaret(components));
|
808
|
-
}
|
809
|
+
components.push(' ');
|
809
810
|
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
}, {
|
815
|
-
key: "renderSubstring",
|
816
|
-
value: function renderSubstring(string, key) {
|
817
|
-
// set substring span to hidden, so that Emojis are not shown double in Mobile Safari
|
818
|
-
return /*#__PURE__*/React.createElement("span", _extends({}, this.props.style('substring'), {
|
819
|
-
key: key
|
820
|
-
}), string);
|
821
|
-
} // Returns a clone of the Mention child applicable for the specified type to be rendered inside the highlighter
|
822
|
-
|
823
|
-
}, {
|
824
|
-
key: "getMentionComponentForMatch",
|
825
|
-
value: function getMentionComponentForMatch(id, display, mentionChildIndex, key) {
|
826
|
-
var props = {
|
827
|
-
id: id,
|
828
|
-
display: display,
|
829
|
-
key: key
|
830
|
-
};
|
831
|
-
var child = Children.toArray(this.props.children)[mentionChildIndex];
|
832
|
-
return /*#__PURE__*/React.cloneElement(child, props);
|
833
|
-
} // Renders an component to be inserted in the highlighter at the current caret position
|
834
|
-
|
835
|
-
}, {
|
836
|
-
key: "renderHighlighterCaret",
|
837
|
-
value: function renderHighlighterCaret(children) {
|
838
|
-
return /*#__PURE__*/React.createElement("span", _extends({}, this.props.style('caret'), {
|
839
|
-
ref: this.setCaretElement,
|
840
|
-
key: "caret"
|
841
|
-
}), children);
|
842
|
-
}
|
843
|
-
}]);
|
811
|
+
if (components !== resultComponents) {
|
812
|
+
// if a caret component is to be rendered, add all components that followed as its children
|
813
|
+
resultComponents.push(renderHighlighterCaret(components));
|
814
|
+
}
|
844
815
|
|
845
|
-
return
|
846
|
-
|
816
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, style, {
|
817
|
+
ref: containerRef
|
818
|
+
}), resultComponents);
|
819
|
+
}
|
847
820
|
|
848
|
-
|
821
|
+
Highlighter.propTypes = {
|
849
822
|
selectionStart: PropTypes.number,
|
850
823
|
selectionEnd: PropTypes.number,
|
851
824
|
value: PropTypes.string.isRequired,
|
@@ -854,12 +827,7 @@ _defineProperty(Highlighter, "propTypes", {
|
|
854
827
|
current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
|
855
828
|
})]),
|
856
829
|
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
|
857
|
-
}
|
858
|
-
|
859
|
-
_defineProperty(Highlighter, "defaultProps", {
|
860
|
-
value: ''
|
861
|
-
});
|
862
|
-
|
830
|
+
};
|
863
831
|
var styled = createDefaultStyle({
|
864
832
|
position: 'relative',
|
865
833
|
boxSizing: 'border-box',
|
@@ -981,162 +949,145 @@ function LoadingIndicator(_ref) {
|
|
981
949
|
|
982
950
|
var defaultstyle = {};
|
983
951
|
|
984
|
-
function
|
985
|
-
|
986
|
-
|
952
|
+
function SuggestionsOverlay(_ref) {
|
953
|
+
var id = _ref.id,
|
954
|
+
_ref$suggestions = _ref.suggestions,
|
955
|
+
suggestions = _ref$suggestions === void 0 ? {} : _ref$suggestions,
|
956
|
+
a11ySuggestionsListLabel = _ref.a11ySuggestionsListLabel,
|
957
|
+
focusIndex = _ref.focusIndex,
|
958
|
+
position = _ref.position,
|
959
|
+
left = _ref.left,
|
960
|
+
right = _ref.right,
|
961
|
+
top = _ref.top,
|
962
|
+
scrollFocusedIntoView = _ref.scrollFocusedIntoView,
|
963
|
+
isLoading = _ref.isLoading,
|
964
|
+
isOpened = _ref.isOpened,
|
965
|
+
_ref$onSelect = _ref.onSelect,
|
966
|
+
onSelect = _ref$onSelect === void 0 ? function () {
|
967
|
+
return null;
|
968
|
+
} : _ref$onSelect,
|
969
|
+
ignoreAccents = _ref.ignoreAccents,
|
970
|
+
containerRef = _ref.containerRef,
|
971
|
+
children = _ref.children,
|
972
|
+
style = _ref.style,
|
973
|
+
customSuggestionsContainer = _ref.customSuggestionsContainer,
|
974
|
+
onMouseDown = _ref.onMouseDown,
|
975
|
+
onMouseEnter = _ref.onMouseEnter;
|
976
|
+
|
977
|
+
var _useState = useState(undefined),
|
978
|
+
_useState2 = _slicedToArray(_useState, 2),
|
979
|
+
ulElement = _useState2[0],
|
980
|
+
setUlElement = _useState2[1];
|
981
|
+
|
982
|
+
useEffect(function () {
|
983
|
+
if (!ulElement || ulElement.offsetHeight >= ulElement.scrollHeight || !scrollFocusedIntoView) {
|
984
|
+
return;
|
985
|
+
}
|
987
986
|
|
988
|
-
var
|
989
|
-
_inherits(SuggestionsOverlay, _Component);
|
987
|
+
var scrollTop = ulElement.scrollTop;
|
990
988
|
|
991
|
-
|
989
|
+
var _ulElement$children$f = ulElement.children[focusIndex].getBoundingClientRect(),
|
990
|
+
top = _ulElement$children$f.top,
|
991
|
+
bottom = _ulElement$children$f.bottom;
|
992
992
|
|
993
|
-
|
994
|
-
|
993
|
+
var _ulElement$getBoundin = ulElement.getBoundingClientRect(),
|
994
|
+
topContainer = _ulElement$getBoundin.top;
|
995
995
|
|
996
|
-
|
996
|
+
top = top - topContainer + scrollTop;
|
997
|
+
bottom = bottom - topContainer + scrollTop;
|
997
998
|
|
998
|
-
|
999
|
-
|
999
|
+
if (top < scrollTop) {
|
1000
|
+
ulElement.scrollTop = top;
|
1001
|
+
} else if (bottom > ulElement.offsetHeight) {
|
1002
|
+
ulElement.scrollTop = bottom - ulElement.offsetHeight;
|
1000
1003
|
}
|
1004
|
+
}, [focusIndex, scrollFocusedIntoView, ulElement]);
|
1001
1005
|
|
1002
|
-
|
1006
|
+
var renderSuggestions = function renderSuggestions() {
|
1007
|
+
var suggestionsToRender = /*#__PURE__*/React.createElement("ul", _extends({
|
1008
|
+
ref: setUlElement,
|
1009
|
+
id: id,
|
1010
|
+
role: "listbox",
|
1011
|
+
"aria-label": a11ySuggestionsListLabel
|
1012
|
+
}, style('list')), Object.values(suggestions).reduce(function (accResults, _ref2) {
|
1013
|
+
var results = _ref2.results,
|
1014
|
+
queryInfo = _ref2.queryInfo;
|
1015
|
+
return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
|
1016
|
+
return renderSuggestion(result, queryInfo, accResults.length + index);
|
1017
|
+
})));
|
1018
|
+
}, []));
|
1019
|
+
if (customSuggestionsContainer) return customSuggestionsContainer(suggestionsToRender);
|
1020
|
+
return suggestionsToRender;
|
1021
|
+
};
|
1003
1022
|
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1023
|
+
var renderSuggestion = function renderSuggestion(result, queryInfo, index) {
|
1024
|
+
var isFocused = index === focusIndex;
|
1025
|
+
var childIndex = queryInfo.childIndex,
|
1026
|
+
query = queryInfo.query;
|
1027
|
+
var renderSuggestion = Children.toArray(children)[childIndex].props.renderSuggestion;
|
1028
|
+
return /*#__PURE__*/React.createElement(Suggestion$1, {
|
1029
|
+
style: style('item'),
|
1030
|
+
key: "".concat(childIndex, "-").concat(getID(result)),
|
1031
|
+
id: getSuggestionHtmlId(id, index),
|
1032
|
+
query: query,
|
1033
|
+
index: index,
|
1034
|
+
ignoreAccents: ignoreAccents,
|
1035
|
+
renderSuggestion: renderSuggestion,
|
1036
|
+
suggestion: result,
|
1037
|
+
focused: isFocused,
|
1038
|
+
onClick: function onClick() {
|
1039
|
+
return select(result, queryInfo);
|
1040
|
+
},
|
1041
|
+
onMouseEnter: function onMouseEnter() {
|
1042
|
+
return handleMouseEnter(index);
|
1007
1043
|
}
|
1008
1044
|
});
|
1045
|
+
};
|
1009
1046
|
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1047
|
+
var renderLoadingIndicator = function renderLoadingIndicator() {
|
1048
|
+
if (!isLoading) {
|
1049
|
+
return;
|
1050
|
+
}
|
1013
1051
|
|
1014
|
-
|
1015
|
-
|
1052
|
+
return /*#__PURE__*/React.createElement(LoadingIndicator, {
|
1053
|
+
style: style('loadingIndicator')
|
1016
1054
|
});
|
1055
|
+
};
|
1017
1056
|
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
_createClass(SuggestionsOverlay, [{
|
1022
|
-
key: "componentDidUpdate",
|
1023
|
-
value: function componentDidUpdate() {
|
1024
|
-
if (!this.ulElement || this.ulElement.offsetHeight >= this.ulElement.scrollHeight || !this.props.scrollFocusedIntoView) {
|
1025
|
-
return;
|
1026
|
-
}
|
1027
|
-
|
1028
|
-
var scrollTop = this.ulElement.scrollTop;
|
1029
|
-
|
1030
|
-
var _this$ulElement$child = this.ulElement.children[this.props.focusIndex].getBoundingClientRect(),
|
1031
|
-
top = _this$ulElement$child.top,
|
1032
|
-
bottom = _this$ulElement$child.bottom;
|
1033
|
-
|
1034
|
-
var _this$ulElement$getBo = this.ulElement.getBoundingClientRect(),
|
1035
|
-
topContainer = _this$ulElement$getBo.top;
|
1036
|
-
|
1037
|
-
top = top - topContainer + scrollTop;
|
1038
|
-
bottom = bottom - topContainer + scrollTop;
|
1039
|
-
|
1040
|
-
if (top < scrollTop) {
|
1041
|
-
this.ulElement.scrollTop = top;
|
1042
|
-
} else if (bottom > this.ulElement.offsetHeight) {
|
1043
|
-
this.ulElement.scrollTop = bottom - this.ulElement.offsetHeight;
|
1044
|
-
}
|
1057
|
+
var handleMouseEnter = function handleMouseEnter(index, ev) {
|
1058
|
+
if (onMouseEnter) {
|
1059
|
+
onMouseEnter(index);
|
1045
1060
|
}
|
1046
|
-
}
|
1047
|
-
key: "render",
|
1048
|
-
value: function render() {
|
1049
|
-
var _this$props = this.props,
|
1050
|
-
id = _this$props.id,
|
1051
|
-
a11ySuggestionsListLabel = _this$props.a11ySuggestionsListLabel,
|
1052
|
-
isOpened = _this$props.isOpened,
|
1053
|
-
style = _this$props.style,
|
1054
|
-
onMouseDown = _this$props.onMouseDown,
|
1055
|
-
containerRef = _this$props.containerRef,
|
1056
|
-
position = _this$props.position,
|
1057
|
-
left = _this$props.left,
|
1058
|
-
right = _this$props.right,
|
1059
|
-
top = _this$props.top; // do not show suggestions until there is some data
|
1060
|
-
|
1061
|
-
if (!isOpened) {
|
1062
|
-
return null;
|
1063
|
-
}
|
1061
|
+
};
|
1064
1062
|
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
right: right,
|
1069
|
-
top: top
|
1070
|
-
}, style), {
|
1071
|
-
onMouseDown: onMouseDown,
|
1072
|
-
ref: containerRef
|
1073
|
-
}), /*#__PURE__*/React.createElement("ul", _extends({
|
1074
|
-
ref: this.setUlElement,
|
1075
|
-
id: id,
|
1076
|
-
role: "listbox",
|
1077
|
-
"aria-label": a11ySuggestionsListLabel
|
1078
|
-
}, style('list')), this.renderSuggestions()), this.renderLoadingIndicator());
|
1079
|
-
}
|
1080
|
-
}, {
|
1081
|
-
key: "renderSuggestions",
|
1082
|
-
value: function renderSuggestions() {
|
1083
|
-
var _this2 = this;
|
1063
|
+
var select = function select(suggestion, queryInfo) {
|
1064
|
+
onSelect(suggestion, queryInfo);
|
1065
|
+
};
|
1084
1066
|
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
queryInfo = _ref.queryInfo;
|
1089
|
-
return [].concat(_toConsumableArray(accResults), _toConsumableArray(results.map(function (result, index) {
|
1090
|
-
return _this2.renderSuggestion(result, queryInfo, accResults.length + index);
|
1091
|
-
})));
|
1092
|
-
}, []);
|
1093
|
-
if (customSuggestionsContainer) return customSuggestionsContainer(suggestions);else return suggestions;
|
1094
|
-
}
|
1095
|
-
}, {
|
1096
|
-
key: "renderSuggestion",
|
1097
|
-
value: function renderSuggestion(result, queryInfo, index) {
|
1098
|
-
var _this3 = this;
|
1099
|
-
|
1100
|
-
var isFocused = index === this.props.focusIndex;
|
1101
|
-
var childIndex = queryInfo.childIndex,
|
1102
|
-
query = queryInfo.query;
|
1103
|
-
var renderSuggestion = Children.toArray(this.props.children)[childIndex].props.renderSuggestion;
|
1104
|
-
var ignoreAccents = this.props.ignoreAccents;
|
1105
|
-
return /*#__PURE__*/React.createElement(Suggestion$1, {
|
1106
|
-
style: this.props.style('item'),
|
1107
|
-
key: "".concat(childIndex, "-").concat(getID(result)),
|
1108
|
-
id: getSuggestionHtmlId(this.props.id, index),
|
1109
|
-
query: query,
|
1110
|
-
index: index,
|
1111
|
-
ignoreAccents: ignoreAccents,
|
1112
|
-
renderSuggestion: renderSuggestion,
|
1113
|
-
suggestion: result,
|
1114
|
-
focused: isFocused,
|
1115
|
-
onClick: function onClick() {
|
1116
|
-
return _this3.select(result, queryInfo);
|
1117
|
-
},
|
1118
|
-
onMouseEnter: function onMouseEnter() {
|
1119
|
-
return _this3.handleMouseEnter(index);
|
1120
|
-
}
|
1121
|
-
});
|
1067
|
+
var getID = function getID(suggestion) {
|
1068
|
+
if (typeof suggestion === 'string') {
|
1069
|
+
return suggestion;
|
1122
1070
|
}
|
1123
|
-
}, {
|
1124
|
-
key: "renderLoadingIndicator",
|
1125
|
-
value: function renderLoadingIndicator() {
|
1126
|
-
if (!this.props.isLoading) {
|
1127
|
-
return;
|
1128
|
-
}
|
1129
1071
|
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1072
|
+
return suggestion.id;
|
1073
|
+
};
|
1074
|
+
|
1075
|
+
if (!isOpened) {
|
1076
|
+
return null;
|
1077
|
+
}
|
1135
1078
|
|
1136
|
-
return
|
1137
|
-
|
1079
|
+
return /*#__PURE__*/React.createElement("div", _extends({}, inline({
|
1080
|
+
position: position || 'absolute',
|
1081
|
+
left: left,
|
1082
|
+
right: right,
|
1083
|
+
top: top
|
1084
|
+
}, style), {
|
1085
|
+
onMouseDown: onMouseDown,
|
1086
|
+
ref: containerRef
|
1087
|
+
}), renderSuggestions(), renderLoadingIndicator());
|
1088
|
+
}
|
1138
1089
|
|
1139
|
-
|
1090
|
+
SuggestionsOverlay.propTypes = {
|
1140
1091
|
id: PropTypes.string.isRequired,
|
1141
1092
|
suggestions: PropTypes.object.isRequired,
|
1142
1093
|
a11ySuggestionsListLabel: PropTypes.string,
|
@@ -1150,27 +1101,11 @@ _defineProperty(SuggestionsOverlay, "propTypes", {
|
|
1150
1101
|
isOpened: PropTypes.bool.isRequired,
|
1151
1102
|
onSelect: PropTypes.func,
|
1152
1103
|
ignoreAccents: PropTypes.bool,
|
1104
|
+
customSuggestionsContainer: PropTypes.func,
|
1153
1105
|
containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
|
1154
1106
|
current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
|
1155
|
-
})])
|
1156
|
-
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
|
1157
|
-
});
|
1158
|
-
|
1159
|
-
_defineProperty(SuggestionsOverlay, "defaultProps", {
|
1160
|
-
suggestions: {},
|
1161
|
-
onSelect: function onSelect() {
|
1162
|
-
return null;
|
1163
|
-
}
|
1164
|
-
});
|
1165
|
-
|
1166
|
-
var getID = function getID(suggestion) {
|
1167
|
-
if (typeof suggestion === 'string') {
|
1168
|
-
return suggestion;
|
1169
|
-
}
|
1170
|
-
|
1171
|
-
return suggestion.id;
|
1107
|
+
})])
|
1172
1108
|
};
|
1173
|
-
|
1174
1109
|
var styled$2 = createDefaultStyle({
|
1175
1110
|
zIndex: 1,
|
1176
1111
|
backgroundColor: 'white',
|
@@ -1184,13 +1119,13 @@ var styled$2 = createDefaultStyle({
|
|
1184
1119
|
});
|
1185
1120
|
var SuggestionsOverlay$1 = styled$2(SuggestionsOverlay);
|
1186
1121
|
|
1187
|
-
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; }
|
1122
|
+
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; }
|
1188
1123
|
|
1189
|
-
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; }
|
1124
|
+
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; }
|
1190
1125
|
|
1191
|
-
function _createSuper
|
1126
|
+
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); }; }
|
1192
1127
|
|
1193
|
-
function _isNativeReflectConstruct
|
1128
|
+
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; } }
|
1194
1129
|
var makeTriggerRegex = function makeTriggerRegex(trigger) {
|
1195
1130
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
1196
1131
|
|
@@ -1262,7 +1197,7 @@ var propTypes = {
|
|
1262
1197
|
var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
1263
1198
|
_inherits(MentionsInput, _React$Component);
|
1264
1199
|
|
1265
|
-
var _super = _createSuper
|
1200
|
+
var _super = _createSuper(MentionsInput);
|
1266
1201
|
|
1267
1202
|
function MentionsInput(_props) {
|
1268
1203
|
var _this;
|
@@ -1283,7 +1218,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1283
1218
|
|
1284
1219
|
var props = omit(_this.props, ['style', 'classNames', 'className'], // substyle props
|
1285
1220
|
keys(propTypes));
|
1286
|
-
return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, props), style('input')), {}, {
|
1221
|
+
return _objectSpread$1(_objectSpread$1(_objectSpread$1(_objectSpread$1({}, props), style('input')), {}, {
|
1287
1222
|
value: _this.getPlainText(),
|
1288
1223
|
onScroll: _this.updateHighlighterScroll
|
1289
1224
|
}, !readOnly && !disabled && {
|
@@ -1322,6 +1257,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1322
1257
|
|
1323
1258
|
_defineProperty(_assertThisInitialized(_this), "renderTextarea", function (props) {
|
1324
1259
|
return /*#__PURE__*/React.createElement("textarea", _extends({
|
1260
|
+
autoFocus: true,
|
1325
1261
|
ref: _this.setInputRef
|
1326
1262
|
}, props));
|
1327
1263
|
});
|
@@ -1826,7 +1762,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1826
1762
|
if (queryId !== _this._queryId) return; // save in property so that multiple sync state updates from different mentions sources
|
1827
1763
|
// won't overwrite each other
|
1828
1764
|
|
1829
|
-
_this.suggestions = _objectSpread(_objectSpread({}, _this.suggestions), {}, _defineProperty({}, childIndex, {
|
1765
|
+
_this.suggestions = _objectSpread$1(_objectSpread$1({}, _this.suggestions), {}, _defineProperty({}, childIndex, {
|
1830
1766
|
queryInfo: {
|
1831
1767
|
childIndex: childIndex,
|
1832
1768
|
query: query,
|
@@ -1931,7 +1867,8 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1931
1867
|
selectionEnd: null,
|
1932
1868
|
suggestions: {},
|
1933
1869
|
caretPosition: null,
|
1934
|
-
suggestionsPosition: {}
|
1870
|
+
suggestionsPosition: {},
|
1871
|
+
setSelectionAfterHandlePaste: false
|
1935
1872
|
};
|
1936
1873
|
return _this;
|
1937
1874
|
}
|
@@ -1961,6 +1898,13 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1961
1898
|
});
|
1962
1899
|
this.setSelection(this.state.selectionStart, this.state.selectionEnd);
|
1963
1900
|
}
|
1901
|
+
|
1902
|
+
if (this.state.setSelectionAfterHandlePaste) {
|
1903
|
+
this.setState({
|
1904
|
+
setSelectionAfterHandlePaste: false
|
1905
|
+
});
|
1906
|
+
this.setSelection(this.state.selectionStart, this.state.selectionEnd);
|
1907
|
+
}
|
1964
1908
|
}
|
1965
1909
|
}, {
|
1966
1910
|
key: "componentWillUnmount",
|
@@ -1985,9 +1929,9 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
1985
1929
|
|
1986
1930
|
if (!this.supportsClipboardActions(event)) {
|
1987
1931
|
return;
|
1988
|
-
}
|
1932
|
+
} // event.preventDefault()
|
1933
|
+
|
1989
1934
|
|
1990
|
-
event.preventDefault();
|
1991
1935
|
var _this$state3 = this.state,
|
1992
1936
|
selectionStart = _this$state3.selectionStart,
|
1993
1937
|
selectionEnd = _this$state3.selectionEnd;
|
@@ -2002,7 +1946,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
2002
1946
|
var newValue = spliceString(value, markupStartIndex, markupEndIndex, pastedMentions || pastedData).replace(/\r/g, '');
|
2003
1947
|
var newPlainTextValue = getPlainText(newValue, config);
|
2004
1948
|
var eventMock = {
|
2005
|
-
target: _objectSpread(_objectSpread({}, event.target), {}, {
|
1949
|
+
target: _objectSpread$1(_objectSpread$1({}, event.target), {}, {
|
2006
1950
|
value: newValue
|
2007
1951
|
})
|
2008
1952
|
};
|
@@ -2010,7 +1954,11 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
2010
1954
|
|
2011
1955
|
var startOfMention = findStartOfMentionInPlainText(value, config, selectionStart);
|
2012
1956
|
var nextPos = (startOfMention || selectionStart) + getPlainText(pastedMentions || pastedData, config).length;
|
2013
|
-
this.
|
1957
|
+
this.setState({
|
1958
|
+
selectionStart: nextPos,
|
1959
|
+
selectionEnd: nextPos,
|
1960
|
+
setSelectionAfterHandlePaste: true
|
1961
|
+
});
|
2014
1962
|
}
|
2015
1963
|
}, {
|
2016
1964
|
key: "saveSelectionToClipboard",
|
@@ -2072,7 +2020,7 @@ var MentionsInput = /*#__PURE__*/function (_React$Component) {
|
|
2072
2020
|
var newValue = [value.slice(0, markupStartIndex), value.slice(markupEndIndex)].join('');
|
2073
2021
|
var newPlainTextValue = getPlainText(newValue, config);
|
2074
2022
|
var eventMock = {
|
2075
|
-
target: _objectSpread(_objectSpread({}, event.target), {}, {
|
2023
|
+
target: _objectSpread$1(_objectSpread$1({}, event.target), {}, {
|
2076
2024
|
value: newPlainTextValue
|
2077
2025
|
})
|
2078
2026
|
};
|
@@ -2129,7 +2077,7 @@ var styled$3 = createDefaultStyle({
|
|
2129
2077
|
letterSpacing: 'inherit'
|
2130
2078
|
},
|
2131
2079
|
'&multiLine': {
|
2132
|
-
input: _objectSpread({
|
2080
|
+
input: _objectSpread$1({
|
2133
2081
|
height: '100%',
|
2134
2082
|
bottom: 0,
|
2135
2083
|
overflow: 'hidden',
|