react-mentions 3.3.0 → 4.0.1

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.
@@ -13,19 +13,15 @@ var _getPrototypeOf = _interopDefault(require('@babel/runtime/helpers/getPrototy
13
13
  var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
14
14
  var _inherits = _interopDefault(require('@babel/runtime/helpers/inherits'));
15
15
  var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty'));
16
- var isEqual = _interopDefault(require('lodash/isEqual'));
17
- var isNumber = _interopDefault(require('lodash/isNumber'));
18
- var keys = _interopDefault(require('lodash/keys'));
19
- var omit = _interopDefault(require('lodash/omit'));
20
- var values = _interopDefault(require('lodash/values'));
21
- var PropTypes = _interopDefault(require('prop-types'));
22
16
  var React = require('react');
23
17
  var React__default = _interopDefault(React);
24
- var ReactDOM = _interopDefault(require('react-dom'));
25
- var substyle = require('substyle');
26
- var substyle__default = _interopDefault(substyle);
27
18
  var invariant = _interopDefault(require('invariant'));
28
19
  var _slicedToArray = _interopDefault(require('@babel/runtime/helpers/slicedToArray'));
20
+ var _objectWithoutProperties = _interopDefault(require('@babel/runtime/helpers/objectWithoutProperties'));
21
+ var useStyles = require('substyle');
22
+ var useStyles__default = _interopDefault(useStyles);
23
+ var PropTypes = _interopDefault(require('prop-types'));
24
+ var ReactDOM = _interopDefault(require('react-dom'));
29
25
 
30
26
  // escape RegExp special characters https://stackoverflow.com/a/9310752/5142490
31
27
  var escapeRegex = function escapeRegex(str) {
@@ -629,9 +625,58 @@ var getSubstringIndex = function getSubstringIndex(str, substr, ignoreAccents) {
629
625
  return normalizeString(str).indexOf(normalizeString(substr));
630
626
  };
631
627
 
632
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
628
+ var isNumber = function isNumber(val) {
629
+ return typeof val === 'number';
630
+ };
633
631
 
634
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
632
+ var keys = function keys(obj) {
633
+ return obj === Object(obj) ? Object.keys(obj) : [];
634
+ };
635
+
636
+ var omit = function omit(obj) {
637
+ var _ref;
638
+
639
+ for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
640
+ rest[_key - 1] = arguments[_key];
641
+ }
642
+
643
+ var keys = (_ref = []).concat.apply(_ref, rest);
644
+
645
+ return Object.keys(obj).reduce(function (acc, k) {
646
+ if (obj.hasOwnProperty(k) && !keys.includes(k) && obj[k] !== undefined) {
647
+ acc[k] = obj[k];
648
+ }
649
+
650
+ return acc;
651
+ }, {});
652
+ };
653
+
654
+ function createDefaultStyle(defaultStyle, getModifiers) {
655
+ var enhance = function enhance(ComponentToWrap) {
656
+ var DefaultStyleEnhancer = function DefaultStyleEnhancer(_ref) {
657
+ var style = _ref.style,
658
+ className = _ref.className,
659
+ classNames = _ref.classNames,
660
+ rest = _objectWithoutProperties(_ref, ["style", "className", "classNames"]);
661
+
662
+ var modifiers = getModifiers ? getModifiers(rest) : undefined;
663
+ var styles = useStyles__default(defaultStyle, {
664
+ style: style,
665
+ className: className,
666
+ classNames: classNames
667
+ }, modifiers);
668
+ return React__default.createElement(ComponentToWrap, _extends({}, rest, {
669
+ style: styles
670
+ }));
671
+ };
672
+
673
+ var displayName = ComponentToWrap.displayName || ComponentToWrap.name || 'Component';
674
+ DefaultStyleEnhancer.displayName = "defaultStyle(".concat(displayName, ")");
675
+ return DefaultStyleEnhancer;
676
+ };
677
+
678
+ return enhance;
679
+ }
635
680
 
636
681
  var _generateComponentKey = function _generateComponentKey(usedKeys, id) {
637
682
  if (!usedKeys.hasOwnProperty(id)) {
@@ -654,8 +699,14 @@ function (_Component) {
654
699
  _classCallCheck(this, Highlighter);
655
700
 
656
701
  _this = _possibleConstructorReturn(this, _getPrototypeOf(Highlighter).apply(this, arguments));
702
+
703
+ _defineProperty(_assertThisInitialized(_this), "setCaretElement", function (el) {
704
+ _this.caretElement = el;
705
+ });
706
+
657
707
  _this.state = {
658
- lastPosition: {}
708
+ left: undefined,
709
+ top: undefined
659
710
  };
660
711
  return _this;
661
712
  }
@@ -673,24 +724,24 @@ function (_Component) {
673
724
  }, {
674
725
  key: "notifyCaretPosition",
675
726
  value: function notifyCaretPosition() {
676
- if (!this.caretRef) {
727
+ if (!this.caretElement) {
677
728
  return;
678
729
  }
679
730
 
680
- var position = {
681
- left: this.caretRef.offsetLeft,
682
- top: this.caretRef.offsetTop
683
- };
684
- var lastPosition = this.state.lastPosition;
731
+ var _this$caretElement = this.caretElement,
732
+ offsetLeft = _this$caretElement.offsetLeft,
733
+ offsetTop = _this$caretElement.offsetTop;
685
734
 
686
- if (isEqual(lastPosition, position)) {
735
+ if (this.state.left === offsetLeft && this.state.top === offsetTop) {
687
736
  return;
688
737
  }
689
738
 
690
- this.setState({
691
- lastPosition: position
692
- });
693
- this.props.onCaretPositionChange(position);
739
+ var newPosition = {
740
+ left: offsetLeft,
741
+ top: offsetTop
742
+ };
743
+ this.setState(newPosition);
744
+ this.props.onCaretPositionChange(newPosition);
694
745
  }
695
746
  }, {
696
747
  key: "render",
@@ -698,17 +749,18 @@ function (_Component) {
698
749
  var _this2 = this;
699
750
 
700
751
  var _this$props = this.props,
701
- selection = _this$props.selection,
752
+ selectionStart = _this$props.selectionStart,
753
+ selectionEnd = _this$props.selectionEnd,
702
754
  value = _this$props.value,
703
755
  style = _this$props.style,
704
- inputStyle = _this$props.inputStyle,
705
- children = _this$props.children;
756
+ children = _this$props.children,
757
+ containerRef = _this$props.containerRef;
706
758
  var config = readConfigFromChildren(children); // If there's a caret (i.e. no range selection), map the caret position into the marked up value
707
759
 
708
760
  var caretPositionInMarkup;
709
761
 
710
- if (selection.start === selection.end) {
711
- caretPositionInMarkup = mapPlainTextIndex(value, config, selection.start, 'START');
762
+ if (selectionStart === selectionEnd) {
763
+ caretPositionInMarkup = mapPlainTextIndex(value, config, selectionStart, 'START');
712
764
  }
713
765
 
714
766
  var resultComponents = [];
@@ -750,7 +802,7 @@ function (_Component) {
750
802
  }
751
803
 
752
804
  return React__default.createElement("div", _extends({}, style, {
753
- style: _objectSpread({}, inputStyle, {}, style.style)
805
+ ref: containerRef
754
806
  }), resultComponents);
755
807
  }
756
808
  }, {
@@ -777,12 +829,8 @@ function (_Component) {
777
829
  }, {
778
830
  key: "renderHighlighterCaret",
779
831
  value: function renderHighlighterCaret(children) {
780
- var _this3 = this;
781
-
782
832
  return React__default.createElement("span", _extends({}, this.props.style('caret'), {
783
- ref: function ref(el) {
784
- _this3.caretRef = el;
785
- },
833
+ ref: this.setCaretElement,
786
834
  key: "caret"
787
835
  }), children);
788
836
  }
@@ -792,28 +840,30 @@ function (_Component) {
792
840
  }(React.Component);
793
841
 
794
842
  _defineProperty(Highlighter, "propTypes", {
795
- selection: PropTypes.shape({
796
- start: PropTypes.number,
797
- end: PropTypes.number
798
- }).isRequired,
843
+ selectionStart: PropTypes.number,
844
+ selectionEnd: PropTypes.number,
799
845
  value: PropTypes.string.isRequired,
800
846
  onCaretPositionChange: PropTypes.func.isRequired,
801
- inputStyle: PropTypes.object,
847
+ containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
848
+ current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
849
+ })]),
802
850
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
803
851
  });
804
852
 
805
853
  _defineProperty(Highlighter, "defaultProps", {
806
- value: '',
807
- inputStyle: {}
854
+ value: ''
808
855
  });
809
856
 
810
- var styled = substyle.defaultStyle({
857
+ var styled = createDefaultStyle({
811
858
  position: 'relative',
812
- width: 'inherit',
859
+ boxSizing: 'border-box',
860
+ width: '100%',
813
861
  color: 'transparent',
814
862
  overflow: 'hidden',
815
863
  whiteSpace: 'pre-wrap',
816
864
  wordWrap: 'break-word',
865
+ border: '1px solid transparent',
866
+ textAlign: 'start',
817
867
  '&singleLine': {
818
868
  whiteSpace: 'pre',
819
869
  wordWrap: null
@@ -842,7 +892,8 @@ function (_Component) {
842
892
  _createClass(Suggestion, [{
843
893
  key: "render",
844
894
  value: function render() {
845
- var rest = omit(this.props, 'style', keys(Suggestion.propTypes));
895
+ var rest = omit(this.props, ['style', 'classNames', 'className'], // substyle props
896
+ keys(Suggestion.propTypes));
846
897
  return React__default.createElement("li", _extends({}, rest, this.props.style), this.renderContent());
847
898
  }
848
899
  }, {
@@ -914,7 +965,7 @@ _defineProperty(Suggestion, "propTypes", {
914
965
  focused: PropTypes.bool
915
966
  });
916
967
 
917
- var styled$1 = substyle.defaultStyle({
968
+ var styled$1 = createDefaultStyle({
918
969
  cursor: 'pointer'
919
970
  }, function (props) {
920
971
  return {
@@ -923,75 +974,98 @@ var styled$1 = substyle.defaultStyle({
923
974
  });
924
975
  var Suggestion$1 = styled$1(Suggestion);
925
976
 
926
- function LoadingIndicator(_ref) {
927
- var style = _ref.style;
928
- var spinnerStyle = style('spinner');
929
- return React__default.createElement("div", style, React__default.createElement("div", spinnerStyle, React__default.createElement("div", spinnerStyle(['element', 'element1'])), React__default.createElement("div", spinnerStyle(['element', 'element2'])), React__default.createElement("div", spinnerStyle(['element', 'element3'])), React__default.createElement("div", spinnerStyle(['element', 'element4'])), React__default.createElement("div", spinnerStyle(['element', 'element5']))));
977
+ function LoadingIndicator() {
978
+ var styles = useStyles__default();
979
+ var spinnerStyles = styles('spinner');
980
+ return React__default.createElement("div", styles, React__default.createElement("div", spinnerStyles, React__default.createElement("div", spinnerStyles(['element', 'element1'])), React__default.createElement("div", spinnerStyles(['element', 'element2'])), React__default.createElement("div", spinnerStyles(['element', 'element3'])), React__default.createElement("div", spinnerStyles(['element', 'element4'])), React__default.createElement("div", spinnerStyles(['element', 'element5']))));
930
981
  }
931
982
 
932
- var LoadingIndicator$1 = substyle__default(LoadingIndicator);
933
-
934
- function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
935
-
936
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
937
-
938
983
  var SuggestionsOverlay =
939
984
  /*#__PURE__*/
940
985
  function (_Component) {
941
986
  _inherits(SuggestionsOverlay, _Component);
942
987
 
943
988
  function SuggestionsOverlay() {
989
+ var _getPrototypeOf2;
990
+
991
+ var _this;
992
+
944
993
  _classCallCheck(this, SuggestionsOverlay);
945
994
 
946
- return _possibleConstructorReturn(this, _getPrototypeOf(SuggestionsOverlay).apply(this, arguments));
995
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
996
+ args[_key] = arguments[_key];
997
+ }
998
+
999
+ _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(SuggestionsOverlay)).call.apply(_getPrototypeOf2, [this].concat(args)));
1000
+
1001
+ _defineProperty(_assertThisInitialized(_this), "handleMouseEnter", function (index, ev) {
1002
+ if (_this.props.onMouseEnter) {
1003
+ _this.props.onMouseEnter(index);
1004
+ }
1005
+ });
1006
+
1007
+ _defineProperty(_assertThisInitialized(_this), "select", function (suggestion, queryInfo) {
1008
+ _this.props.onSelect(suggestion, queryInfo);
1009
+ });
1010
+
1011
+ _defineProperty(_assertThisInitialized(_this), "setUlElement", function (el) {
1012
+ _this.ulElement = el;
1013
+ });
1014
+
1015
+ return _this;
947
1016
  }
948
1017
 
949
1018
  _createClass(SuggestionsOverlay, [{
950
1019
  key: "componentDidUpdate",
951
1020
  value: function componentDidUpdate() {
952
- if (!this.suggestionsRef || this.suggestionsRef.offsetHeight >= this.suggestionsRef.scrollHeight || !this.props.scrollFocusedIntoView) {
1021
+ if (!this.ulElement || this.ulElement.offsetHeight >= this.ulElement.scrollHeight || !this.props.scrollFocusedIntoView) {
953
1022
  return;
954
1023
  }
955
1024
 
956
- var scrollTop = this.suggestionsRef.scrollTop;
1025
+ var scrollTop = this.ulElement.scrollTop;
957
1026
 
958
- var _this$suggestionsRef$ = this.suggestionsRef.children[this.props.focusIndex].getBoundingClientRect(),
959
- top = _this$suggestionsRef$.top,
960
- bottom = _this$suggestionsRef$.bottom;
1027
+ var _this$ulElement$child = this.ulElement.children[this.props.focusIndex].getBoundingClientRect(),
1028
+ top = _this$ulElement$child.top,
1029
+ bottom = _this$ulElement$child.bottom;
961
1030
 
962
- var _this$suggestionsRef$2 = this.suggestionsRef.getBoundingClientRect(),
963
- topContainer = _this$suggestionsRef$2.top;
1031
+ var _this$ulElement$getBo = this.ulElement.getBoundingClientRect(),
1032
+ topContainer = _this$ulElement$getBo.top;
964
1033
 
965
1034
  top = top - topContainer + scrollTop;
966
1035
  bottom = bottom - topContainer + scrollTop;
967
1036
 
968
1037
  if (top < scrollTop) {
969
- this.suggestionsRef.scrollTop = top;
970
- } else if (bottom > this.suggestionsRef.offsetHeight) {
971
- this.suggestionsRef.scrollTop = bottom - this.suggestionsRef.offsetHeight;
1038
+ this.ulElement.scrollTop = top;
1039
+ } else if (bottom > this.ulElement.offsetHeight) {
1040
+ this.ulElement.scrollTop = bottom - this.ulElement.offsetHeight;
972
1041
  }
973
1042
  }
974
1043
  }, {
975
1044
  key: "render",
976
1045
  value: function render() {
977
- var _this = this;
978
-
979
1046
  var _this$props = this.props,
980
1047
  suggestions = _this$props.suggestions,
981
1048
  isLoading = _this$props.isLoading,
982
1049
  style = _this$props.style,
983
- onMouseDown = _this$props.onMouseDown; // do not show suggestions until there is some data
1050
+ onMouseDown = _this$props.onMouseDown,
1051
+ containerRef = _this$props.containerRef,
1052
+ position = _this$props.position,
1053
+ left = _this$props.left,
1054
+ top = _this$props.top; // do not show suggestions until there is some data
984
1055
 
985
1056
  if (countSuggestions(suggestions) === 0 && !isLoading) {
986
1057
  return null;
987
1058
  }
988
1059
 
989
- return React__default.createElement("div", _extends({}, style, {
990
- onMouseDown: onMouseDown
1060
+ return React__default.createElement("div", _extends({}, useStyles.inline({
1061
+ position: position || 'absolute',
1062
+ left: left,
1063
+ top: top
1064
+ }, style), {
1065
+ onMouseDown: onMouseDown,
1066
+ ref: containerRef
991
1067
  }), React__default.createElement("ul", _extends({
992
- ref: function ref(el) {
993
- _this.suggestionsRef = el;
994
- }
1068
+ ref: this.setUlElement
995
1069
  }, style('list')), this.renderSuggestions()), this.renderLoadingIndicator());
996
1070
  }
997
1071
  }, {
@@ -1012,7 +1086,7 @@ function (_Component) {
1012
1086
  value: function renderSuggestion(result, queryInfo, index) {
1013
1087
  var _this3 = this;
1014
1088
 
1015
- var id = this.getID(result);
1089
+ var id = getID(result);
1016
1090
  var isFocused = index === this.props.focusIndex;
1017
1091
  var childIndex = queryInfo.childIndex,
1018
1092
  query = queryInfo.query;
@@ -1036,15 +1110,6 @@ function (_Component) {
1036
1110
  }
1037
1111
  });
1038
1112
  }
1039
- }, {
1040
- key: "getID",
1041
- value: function getID(suggestion) {
1042
- if (suggestion instanceof String) {
1043
- return suggestion;
1044
- }
1045
-
1046
- return suggestion.id;
1047
- }
1048
1113
  }, {
1049
1114
  key: "renderLoadingIndicator",
1050
1115
  value: function renderLoadingIndicator() {
@@ -1052,22 +1117,10 @@ function (_Component) {
1052
1117
  return;
1053
1118
  }
1054
1119
 
1055
- return React__default.createElement(LoadingIndicator$1, {
1120
+ return React__default.createElement(LoadingIndicator, {
1056
1121
  style: this.props.style('loadingIndicator')
1057
1122
  });
1058
1123
  }
1059
- }, {
1060
- key: "handleMouseEnter",
1061
- value: function handleMouseEnter(index, ev) {
1062
- if (this.props.onMouseEnter) {
1063
- this.props.onMouseEnter(index);
1064
- }
1065
- }
1066
- }, {
1067
- key: "select",
1068
- value: function select(suggestion, queryInfo) {
1069
- this.props.onSelect(suggestion, queryInfo);
1070
- }
1071
1124
  }]);
1072
1125
 
1073
1126
  return SuggestionsOverlay;
@@ -1076,10 +1129,16 @@ function (_Component) {
1076
1129
  _defineProperty(SuggestionsOverlay, "propTypes", {
1077
1130
  suggestions: PropTypes.object.isRequired,
1078
1131
  focusIndex: PropTypes.number,
1132
+ position: PropTypes.string,
1133
+ left: PropTypes.number,
1134
+ top: PropTypes.number,
1079
1135
  scrollFocusedIntoView: PropTypes.bool,
1080
1136
  isLoading: PropTypes.bool,
1081
1137
  onSelect: PropTypes.func,
1082
1138
  ignoreAccents: PropTypes.bool,
1139
+ containerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
1140
+ current: typeof Element === 'undefined' ? PropTypes.any : PropTypes.instanceOf(Element)
1141
+ })]),
1083
1142
  children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]).isRequired
1084
1143
  });
1085
1144
 
@@ -1090,27 +1149,30 @@ _defineProperty(SuggestionsOverlay, "defaultProps", {
1090
1149
  }
1091
1150
  });
1092
1151
 
1093
- var styled$2 = substyle.defaultStyle(function (_ref2) {
1094
- var position = _ref2.position;
1095
- return _objectSpread$1({
1096
- position: 'absolute',
1097
- zIndex: 1,
1098
- backgroundColor: 'white',
1099
- marginTop: 14,
1100
- minWidth: 100
1101
- }, position, {
1102
- list: {
1103
- margin: 0,
1104
- padding: 0,
1105
- listStyleType: 'none'
1106
- }
1107
- });
1152
+ var getID = function getID(suggestion) {
1153
+ if (suggestion instanceof String) {
1154
+ return suggestion;
1155
+ }
1156
+
1157
+ return suggestion.id;
1158
+ };
1159
+
1160
+ var styled$2 = createDefaultStyle({
1161
+ zIndex: 1,
1162
+ backgroundColor: 'white',
1163
+ marginTop: 14,
1164
+ minWidth: 100,
1165
+ list: {
1166
+ margin: 0,
1167
+ padding: 0,
1168
+ listStyleType: 'none'
1169
+ }
1108
1170
  });
1109
1171
  var SuggestionsOverlay$1 = styled$2(SuggestionsOverlay);
1110
1172
 
1111
- function ownKeys$2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
1173
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
1112
1174
 
1113
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1175
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
1114
1176
  var makeTriggerRegex = function makeTriggerRegex(trigger) {
1115
1177
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1116
1178
 
@@ -1162,7 +1224,6 @@ var propTypes = {
1162
1224
  */
1163
1225
  singleLine: PropTypes.bool,
1164
1226
  allowSpaceInQuery: PropTypes.bool,
1165
- EXPERIMENTAL_cutCopyPaste: PropTypes.bool,
1166
1227
  allowSuggestionsAboveCursor: PropTypes.bool,
1167
1228
  ignoreAccents: PropTypes.bool,
1168
1229
  value: PropTypes.string,
@@ -1189,14 +1250,19 @@ function (_React$Component) {
1189
1250
 
1190
1251
  _this = _possibleConstructorReturn(this, _getPrototypeOf(MentionsInput).call(this, _props));
1191
1252
 
1192
- _defineProperty(_assertThisInitialized(_this), "getInputProps", function (isTextarea) {
1253
+ _defineProperty(_assertThisInitialized(_this), "setContainerElement", function (el) {
1254
+ _this.containerElement = el;
1255
+ });
1256
+
1257
+ _defineProperty(_assertThisInitialized(_this), "getInputProps", function () {
1193
1258
  var _this$props = _this.props,
1194
1259
  readOnly = _this$props.readOnly,
1195
1260
  disabled = _this$props.disabled,
1196
- style = _this$props.style; // pass all props that we don't use through to the input control
1261
+ style = _this$props.style; // pass all props that neither we, nor substyle, consume through to the input control
1197
1262
 
1198
- var props = omit(_this.props, 'style', keys(propTypes));
1199
- return _objectSpread$2({}, props, {}, style('input'), {
1263
+ var props = omit(_this.props, ['style', 'classNames', 'className'], // substyle props
1264
+ keys(propTypes));
1265
+ return _objectSpread({}, props, {}, style('input'), {
1200
1266
  value: _this.getPlainText()
1201
1267
  }, !readOnly && !disabled && {
1202
1268
  onChange: _this.handleChange,
@@ -1214,9 +1280,9 @@ function (_React$Component) {
1214
1280
  singleLine = _this$props2.singleLine,
1215
1281
  style = _this$props2.style;
1216
1282
 
1217
- var inputProps = _this.getInputProps(!singleLine);
1283
+ var inputProps = _this.getInputProps();
1218
1284
 
1219
- return React__default.createElement("div", style('control'), _this.renderHighlighter(inputProps.style), singleLine ? _this.renderInput(inputProps) : _this.renderTextarea(inputProps));
1285
+ return React__default.createElement("div", style('control'), _this.renderHighlighter(), singleLine ? _this.renderInput(inputProps) : _this.renderTextarea(inputProps));
1220
1286
  });
1221
1287
 
1222
1288
  _defineProperty(_assertThisInitialized(_this), "renderInput", function (props) {
@@ -1233,7 +1299,7 @@ function (_React$Component) {
1233
1299
  });
1234
1300
 
1235
1301
  _defineProperty(_assertThisInitialized(_this), "setInputRef", function (el) {
1236
- _this.inputRef = el;
1302
+ _this.inputElement = el;
1237
1303
  var inputRef = _this.props.inputRef;
1238
1304
 
1239
1305
  if (typeof inputRef === 'function') {
@@ -1243,29 +1309,32 @@ function (_React$Component) {
1243
1309
  }
1244
1310
  });
1245
1311
 
1312
+ _defineProperty(_assertThisInitialized(_this), "setSuggestionsElement", function (el) {
1313
+ _this.suggestionsElement = el;
1314
+ });
1315
+
1246
1316
  _defineProperty(_assertThisInitialized(_this), "renderSuggestionsOverlay", function () {
1247
1317
  if (!isNumber(_this.state.selectionStart)) {
1248
1318
  // do not show suggestions when the input does not have the focus
1249
1319
  return null;
1250
1320
  }
1251
1321
 
1322
+ var _this$state$suggestio = _this.state.suggestionsPosition,
1323
+ position = _this$state$suggestio.position,
1324
+ left = _this$state$suggestio.left,
1325
+ top = _this$state$suggestio.top;
1252
1326
  var suggestionsNode = React__default.createElement(SuggestionsOverlay$1, {
1253
1327
  style: _this.props.style('suggestions'),
1254
- position: _this.state.suggestionsPosition,
1328
+ position: position,
1329
+ left: left,
1330
+ top: top,
1255
1331
  focusIndex: _this.state.focusIndex,
1256
1332
  scrollFocusedIntoView: _this.state.scrollFocusedIntoView,
1257
- ref: function ref(el) {
1258
- _this.suggestionsRef = el;
1259
- },
1333
+ containerRef: _this.setSuggestionsElement,
1260
1334
  suggestions: _this.state.suggestions,
1261
1335
  onSelect: _this.addMention,
1262
1336
  onMouseDown: _this.handleSuggestionsMouseDown,
1263
- onMouseEnter: function onMouseEnter(focusIndex) {
1264
- return _this.setState({
1265
- focusIndex: focusIndex,
1266
- scrollFocusedIntoView: false
1267
- });
1268
- },
1337
+ onMouseEnter: _this.handleSuggestionsMouseEnter,
1269
1338
  isLoading: _this.isLoading(),
1270
1339
  ignoreAccents: _this.props.ignoreAccents
1271
1340
  }, _this.props.children);
@@ -1277,7 +1346,7 @@ function (_React$Component) {
1277
1346
  }
1278
1347
  });
1279
1348
 
1280
- _defineProperty(_assertThisInitialized(_this), "renderHighlighter", function (inputStyle) {
1349
+ _defineProperty(_assertThisInitialized(_this), "renderHighlighter", function () {
1281
1350
  var _this$state = _this.state,
1282
1351
  selectionStart = _this$state.selectionStart,
1283
1352
  selectionEnd = _this$state.selectionEnd;
@@ -1287,25 +1356,26 @@ function (_React$Component) {
1287
1356
  value = _this$props3.value,
1288
1357
  style = _this$props3.style;
1289
1358
  return React__default.createElement(Highlighter$1, {
1290
- ref: function ref(el) {
1291
- _this.highlighterRef = el;
1292
- },
1359
+ containerRef: _this.setHighlighterElement,
1293
1360
  style: style('highlighter'),
1294
- inputStyle: inputStyle,
1295
1361
  value: value,
1296
1362
  singleLine: singleLine,
1297
- selection: {
1298
- start: selectionStart,
1299
- end: selectionEnd
1300
- },
1301
- onCaretPositionChange: function onCaretPositionChange(position) {
1302
- return _this.setState({
1303
- caretPosition: position
1304
- });
1305
- }
1363
+ selectionStart: selectionStart,
1364
+ selectionEnd: selectionEnd,
1365
+ onCaretPositionChange: _this.handleCaretPositionChange
1306
1366
  }, children);
1307
1367
  });
1308
1368
 
1369
+ _defineProperty(_assertThisInitialized(_this), "setHighlighterElement", function (el) {
1370
+ _this.highlighterElement = el;
1371
+ });
1372
+
1373
+ _defineProperty(_assertThisInitialized(_this), "handleCaretPositionChange", function (position) {
1374
+ _this.setState({
1375
+ caretPosition: position
1376
+ });
1377
+ });
1378
+
1309
1379
  _defineProperty(_assertThisInitialized(_this), "getPlainText", function () {
1310
1380
  return getPlainText(_this.props.value || '', readConfigFromChildren(_this.props.children));
1311
1381
  });
@@ -1329,7 +1399,8 @@ function (_React$Component) {
1329
1399
  });
1330
1400
 
1331
1401
  _defineProperty(_assertThisInitialized(_this), "handleChange", function (ev) {
1332
- // if we are inside iframe, we need to find activeElement within its contentDocument
1402
+ isComposing = false; // if we are inside iframe, we need to find activeElement within its contentDocument
1403
+
1333
1404
  var currentDocument = document.activeElement && document.activeElement.contentDocument || document;
1334
1405
 
1335
1406
  if (currentDocument.activeElement !== ev.target) {
@@ -1391,7 +1462,7 @@ function (_React$Component) {
1391
1462
 
1392
1463
  if (isComposing) return; // refresh suggestions queries
1393
1464
 
1394
- var el = _this.inputRef;
1465
+ var el = _this.inputElement;
1395
1466
 
1396
1467
  if (ev.target.selectionStart === ev.target.selectionEnd) {
1397
1468
  _this.updateMentionsQueries(el.value, ev.target.selectionStart);
@@ -1408,15 +1479,14 @@ function (_React$Component) {
1408
1479
  _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (ev) {
1409
1480
  // do not intercept key events if the suggestions overlay is not shown
1410
1481
  var suggestionsCount = countSuggestions(_this.state.suggestions);
1411
- var suggestionsComp = _this.suggestionsRef;
1412
1482
 
1413
- if (suggestionsCount === 0 || !suggestionsComp) {
1483
+ if (suggestionsCount === 0 || !_this.suggestionsElement) {
1414
1484
  _this.props.onKeyDown(ev);
1415
1485
 
1416
1486
  return;
1417
1487
  }
1418
1488
 
1419
- if (values(KEY).indexOf(ev.keyCode) >= 0) {
1489
+ if (Object.values(KEY).indexOf(ev.keyCode) >= 0) {
1420
1490
  ev.preventDefault();
1421
1491
  }
1422
1492
 
@@ -1519,18 +1589,25 @@ function (_React$Component) {
1519
1589
  _this._suggestionsMouseDown = true;
1520
1590
  });
1521
1591
 
1592
+ _defineProperty(_assertThisInitialized(_this), "handleSuggestionsMouseEnter", function (focusIndex) {
1593
+ _this.setState({
1594
+ focusIndex: focusIndex,
1595
+ scrollFocusedIntoView: false
1596
+ });
1597
+ });
1598
+
1522
1599
  _defineProperty(_assertThisInitialized(_this), "updateSuggestionsPosition", function () {
1523
1600
  var caretPosition = _this.state.caretPosition;
1524
1601
  var _this$props5 = _this.props,
1525
1602
  suggestionsPortalHost = _this$props5.suggestionsPortalHost,
1526
1603
  allowSuggestionsAboveCursor = _this$props5.allowSuggestionsAboveCursor;
1527
1604
 
1528
- if (!caretPosition || !_this.suggestionsRef) {
1605
+ if (!caretPosition || !_this.suggestionsElement) {
1529
1606
  return;
1530
1607
  }
1531
1608
 
1532
- var suggestions = ReactDOM.findDOMNode(_this.suggestionsRef);
1533
- var highlighter = ReactDOM.findDOMNode(_this.highlighterRef); // first get viewport-relative position (highlighter is offsetParent of caret):
1609
+ var suggestions = _this.suggestionsElement;
1610
+ var highlighter = _this.highlighterElement; // first get viewport-relative position (highlighter is offsetParent of caret):
1534
1611
 
1535
1612
  var caretOffsetParentRect = highlighter.getBoundingClientRect();
1536
1613
  var caretHeight = getComputedStyleLengthProp(highlighter, 'font-size');
@@ -1579,7 +1656,7 @@ function (_React$Component) {
1579
1656
  var _top = caretPosition.top - highlighter.scrollTop; // guard for mentions suggestions list clipped by right edge of window
1580
1657
 
1581
1658
 
1582
- if (_left + suggestions.offsetWidth > _this.containerRef.offsetWidth) {
1659
+ if (_left + suggestions.offsetWidth > _this.containerElement.offsetWidth) {
1583
1660
  position.right = 0;
1584
1661
  } else {
1585
1662
  position.left = _left;
@@ -1595,7 +1672,7 @@ function (_React$Component) {
1595
1672
  }
1596
1673
  }
1597
1674
 
1598
- if (isEqual(position, _this.state.suggestionsPosition)) {
1675
+ if (position.left === _this.state.suggestionsPosition.left && position.top === _this.state.suggestionsPosition.top && position.position === _this.state.suggestionsPosition.position) {
1599
1676
  return;
1600
1677
  }
1601
1678
 
@@ -1605,14 +1682,15 @@ function (_React$Component) {
1605
1682
  });
1606
1683
 
1607
1684
  _defineProperty(_assertThisInitialized(_this), "updateHighlighterScroll", function () {
1608
- if (!_this.inputRef || !_this.highlighterRef) {
1685
+ var input = _this.inputElement;
1686
+ var highlighter = _this.highlighterElement;
1687
+
1688
+ if (!input || !highlighter) {
1609
1689
  // since the invocation of this function is deferred,
1610
1690
  // the whole component may have been unmounted in the meanwhile
1611
1691
  return;
1612
1692
  }
1613
1693
 
1614
- var input = _this.inputRef;
1615
- var highlighter = ReactDOM.findDOMNode(_this.highlighterRef);
1616
1694
  highlighter.scrollLeft = input.scrollLeft;
1617
1695
  highlighter.scrollTop = input.scrollTop;
1618
1696
  highlighter.height = input.height;
@@ -1628,7 +1706,7 @@ function (_React$Component) {
1628
1706
 
1629
1707
  _defineProperty(_assertThisInitialized(_this), "setSelection", function (selectionStart, selectionEnd) {
1630
1708
  if (selectionStart === null || selectionEnd === null) return;
1631
- var el = _this.inputRef;
1709
+ var el = _this.inputElement;
1632
1710
 
1633
1711
  if (el.setSelectionRange) {
1634
1712
  el.setSelectionRange(selectionStart, selectionEnd);
@@ -1709,7 +1787,7 @@ function (_React$Component) {
1709
1787
  if (queryId !== _this._queryId) return; // save in property so that multiple sync state updates from different mentions sources
1710
1788
  // won't overwrite each other
1711
1789
 
1712
- _this.suggestions = _objectSpread$2({}, _this.suggestions, _defineProperty({}, childIndex, {
1790
+ _this.suggestions = _objectSpread({}, _this.suggestions, _defineProperty({}, childIndex, {
1713
1791
  queryInfo: {
1714
1792
  childIndex: childIndex,
1715
1793
  query: query,
@@ -1754,7 +1832,7 @@ function (_React$Component) {
1754
1832
 
1755
1833
  var newValue = spliceString(value, start, end, insert); // Refocus input and set caret position to end of mention
1756
1834
 
1757
- _this.inputRef.focus();
1835
+ _this.inputElement.focus();
1758
1836
 
1759
1837
  var displayValue = displayTransform(id, display);
1760
1838
 
@@ -1809,7 +1887,7 @@ function (_React$Component) {
1809
1887
  selectionEnd: null,
1810
1888
  suggestions: {},
1811
1889
  caretPosition: null,
1812
- suggestionsPosition: null
1890
+ suggestionsPosition: {}
1813
1891
  };
1814
1892
  return _this;
1815
1893
  }
@@ -1817,14 +1895,9 @@ function (_React$Component) {
1817
1895
  _createClass(MentionsInput, [{
1818
1896
  key: "componentDidMount",
1819
1897
  value: function componentDidMount() {
1820
- var EXPERIMENTAL_cutCopyPaste = this.props.EXPERIMENTAL_cutCopyPaste;
1821
-
1822
- if (EXPERIMENTAL_cutCopyPaste) {
1823
- document.addEventListener('copy', this.handleCopy);
1824
- document.addEventListener('cut', this.handleCut);
1825
- document.addEventListener('paste', this.handlePaste);
1826
- }
1827
-
1898
+ document.addEventListener('copy', this.handleCopy);
1899
+ document.addEventListener('cut', this.handleCut);
1900
+ document.addEventListener('paste', this.handlePaste);
1828
1901
  this.updateSuggestionsPosition();
1829
1902
  }
1830
1903
  }, {
@@ -1848,29 +1921,21 @@ function (_React$Component) {
1848
1921
  }, {
1849
1922
  key: "componentWillUnmount",
1850
1923
  value: function componentWillUnmount() {
1851
- var EXPERIMENTAL_cutCopyPaste = this.props.EXPERIMENTAL_cutCopyPaste;
1852
-
1853
- if (EXPERIMENTAL_cutCopyPaste) {
1854
- document.removeEventListener('copy', this.handleCopy);
1855
- document.removeEventListener('cut', this.handleCut);
1856
- document.removeEventListener('paste', this.handlePaste);
1857
- }
1924
+ document.removeEventListener('copy', this.handleCopy);
1925
+ document.removeEventListener('cut', this.handleCut);
1926
+ document.removeEventListener('paste', this.handlePaste);
1858
1927
  }
1859
1928
  }, {
1860
1929
  key: "render",
1861
1930
  value: function render() {
1862
- var _this2 = this;
1863
-
1864
1931
  return React__default.createElement("div", _extends({
1865
- ref: function ref(el) {
1866
- _this2.containerRef = el;
1867
- }
1932
+ ref: this.setContainerElement
1868
1933
  }, this.props.style), this.renderControl(), this.renderSuggestionsOverlay());
1869
1934
  }
1870
1935
  }, {
1871
1936
  key: "handlePaste",
1872
1937
  value: function handlePaste(event) {
1873
- if (event.target !== this.inputRef) {
1938
+ if (event.target !== this.inputElement) {
1874
1939
  return;
1875
1940
  }
1876
1941
 
@@ -1890,10 +1955,10 @@ function (_React$Component) {
1890
1955
  var markupEndIndex = mapPlainTextIndex(value, config, selectionEnd, 'END');
1891
1956
  var pastedMentions = event.clipboardData.getData('text/react-mentions');
1892
1957
  var pastedData = event.clipboardData.getData('text/plain');
1893
- var newValue = spliceString(value, markupStartIndex, markupEndIndex, pastedMentions || pastedData);
1958
+ var newValue = spliceString(value, markupStartIndex, markupEndIndex, pastedMentions || pastedData).replace(/\r/g, '');
1894
1959
  var newPlainTextValue = getPlainText(newValue, config);
1895
1960
  var eventMock = {
1896
- target: _objectSpread$2({}, event.target, {
1961
+ target: _objectSpread({}, event.target, {
1897
1962
  value: newValue
1898
1963
  })
1899
1964
  };
@@ -1922,7 +1987,7 @@ function (_React$Component) {
1922
1987
  }, {
1923
1988
  key: "handleCopy",
1924
1989
  value: function handleCopy(event) {
1925
- if (event.target !== this.inputRef) {
1990
+ if (event.target !== this.inputElement) {
1926
1991
  return;
1927
1992
  }
1928
1993
 
@@ -1936,7 +2001,7 @@ function (_React$Component) {
1936
2001
  }, {
1937
2002
  key: "handleCut",
1938
2003
  value: function handleCut(event) {
1939
- if (event.target !== this.inputRef) {
2004
+ if (event.target !== this.inputElement) {
1940
2005
  return;
1941
2006
  }
1942
2007
 
@@ -1958,7 +2023,7 @@ function (_React$Component) {
1958
2023
  var newValue = [value.slice(0, markupStartIndex), value.slice(markupEndIndex)].join('');
1959
2024
  var newPlainTextValue = getPlainText(newValue, config);
1960
2025
  var eventMock = {
1961
- target: _objectSpread$2({}, event.target, {
2026
+ target: _objectSpread({}, event.target, {
1962
2027
  value: newPlainTextValue
1963
2028
  })
1964
2029
  };
@@ -1998,24 +2063,24 @@ var getComputedStyleLengthProp = function getComputedStyleLengthProp(forElement,
1998
2063
  };
1999
2064
 
2000
2065
  var isMobileSafari = typeof navigator !== 'undefined' && /iPhone|iPad|iPod/i.test(navigator.userAgent);
2001
- var styled$3 = substyle.defaultStyle({
2066
+ var styled$3 = createDefaultStyle({
2002
2067
  position: 'relative',
2003
2068
  overflowY: 'visible',
2004
2069
  input: {
2005
2070
  display: 'block',
2071
+ width: '100%',
2006
2072
  position: 'absolute',
2073
+ margin: 0,
2007
2074
  top: 0,
2008
2075
  left: 0,
2009
2076
  boxSizing: 'border-box',
2010
2077
  backgroundColor: 'transparent',
2011
- width: 'inherit',
2012
2078
  fontFamily: 'inherit',
2013
2079
  fontSize: 'inherit',
2014
2080
  letterSpacing: 'inherit'
2015
2081
  },
2016
2082
  '&multiLine': {
2017
- input: _objectSpread$2({
2018
- width: '100%',
2083
+ input: _objectSpread({
2019
2084
  height: '100%',
2020
2085
  bottom: 0,
2021
2086
  overflow: 'hidden',
@@ -2034,14 +2099,23 @@ var styled$3 = substyle.defaultStyle({
2034
2099
  });
2035
2100
  var MentionsInput$1 = styled$3(MentionsInput);
2036
2101
 
2037
- var styled$4 = substyle.defaultStyle({
2102
+ var defaultStyle = {
2038
2103
  fontWeight: 'inherit'
2039
- });
2040
- var Mention = styled$4(function (_ref) {
2104
+ };
2105
+
2106
+ var Mention = function Mention(_ref) {
2041
2107
  var display = _ref.display,
2042
- style = _ref.style;
2043
- return React__default.createElement("strong", style, display);
2044
- });
2108
+ style = _ref.style,
2109
+ className = _ref.className,
2110
+ classNames = _ref.classNames;
2111
+ var styles = useStyles__default(defaultStyle, {
2112
+ style: style,
2113
+ className: className,
2114
+ classNames: classNames
2115
+ });
2116
+ return React__default.createElement("strong", styles, display);
2117
+ };
2118
+
2045
2119
  Mention.propTypes = {
2046
2120
  /**
2047
2121
  * Called when a new mention is added in the input