@chayns-components/emoji-input 5.0.0-beta.997 → 5.0.0

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.
Files changed (127) hide show
  1. package/lib/cjs/components/emoji-input/EmojiInput.js +110 -73
  2. package/lib/cjs/components/emoji-input/EmojiInput.js.map +1 -1
  3. package/lib/cjs/components/emoji-input/EmojiInput.styles.js +4 -5
  4. package/lib/cjs/components/emoji-input/EmojiInput.styles.js.map +1 -1
  5. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js +1 -2
  6. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js.map +1 -1
  7. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js +1 -2
  8. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -1
  9. package/lib/cjs/components/emoji-picker/EmojiPicker.js +3 -5
  10. package/lib/cjs/components/emoji-picker/EmojiPicker.js.map +1 -1
  11. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +26 -29
  12. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -1
  13. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +2 -2
  14. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -1
  15. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +31 -11
  16. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -1
  17. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +1 -2
  18. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -1
  19. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +23 -22
  20. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -1
  21. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +5 -5
  22. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -1
  23. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +3 -4
  24. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -1
  25. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js +1 -2
  26. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -1
  27. package/lib/cjs/constants/emoji.js +1 -3679
  28. package/lib/cjs/constants/emoji.js.map +1 -1
  29. package/lib/cjs/hooks/cursor.js +110 -0
  30. package/lib/cjs/hooks/cursor.js.map +1 -0
  31. package/lib/cjs/hooks/emojiHistory.js.map +1 -1
  32. package/lib/cjs/index.js +27 -2
  33. package/lib/cjs/index.js.map +1 -1
  34. package/lib/cjs/types/api.js +4 -0
  35. package/lib/cjs/types/category.js +4 -0
  36. package/lib/cjs/utils/asyncEmojiData.js +10 -0
  37. package/lib/cjs/utils/asyncEmojiData.js.map +1 -0
  38. package/lib/cjs/utils/convertEmojisToUnicodeAsync.js +29 -0
  39. package/lib/cjs/utils/convertEmojisToUnicodeAsync.js.map +1 -0
  40. package/lib/cjs/utils/emoji.js +5 -8
  41. package/lib/cjs/utils/emoji.js.map +1 -1
  42. package/lib/cjs/utils/emojiShortList.js +3685 -0
  43. package/lib/cjs/utils/emojiShortList.js.map +1 -0
  44. package/lib/cjs/utils/insert.js +4 -2
  45. package/lib/cjs/utils/insert.js.map +1 -1
  46. package/lib/cjs/utils/scroll.js +65 -0
  47. package/lib/cjs/utils/scroll.js.map +1 -0
  48. package/lib/cjs/utils/selection.js +113 -17
  49. package/lib/cjs/utils/selection.js.map +1 -1
  50. package/lib/cjs/utils/text.js +7 -1
  51. package/lib/cjs/utils/text.js.map +1 -1
  52. package/lib/esm/api/item-storage/get.js +4 -5
  53. package/lib/esm/api/item-storage/get.js.map +1 -1
  54. package/lib/esm/api/item-storage/put.js +5 -6
  55. package/lib/esm/api/item-storage/put.js.map +1 -1
  56. package/lib/esm/components/emoji-input/EmojiInput.js +71 -40
  57. package/lib/esm/components/emoji-input/EmojiInput.js.map +1 -1
  58. package/lib/esm/components/emoji-input/EmojiInput.styles.js +33 -60
  59. package/lib/esm/components/emoji-input/EmojiInput.styles.js.map +1 -1
  60. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js +5 -6
  61. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js.map +1 -1
  62. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js +12 -24
  63. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -1
  64. package/lib/esm/components/emoji-picker/EmojiPicker.js +7 -8
  65. package/lib/esm/components/emoji-picker/EmojiPicker.js.map +1 -1
  66. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +30 -35
  67. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -1
  68. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +1 -1
  69. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -1
  70. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +75 -64
  71. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -1
  72. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +19 -34
  73. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -1
  74. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +15 -14
  75. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -1
  76. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +4 -7
  77. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -1
  78. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +13 -14
  79. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -1
  80. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +12 -19
  81. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -1
  82. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js +6 -7
  83. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -1
  84. package/lib/esm/constants/emoji.js +0 -3678
  85. package/lib/esm/constants/emoji.js.map +1 -1
  86. package/lib/esm/hooks/cursor.js +103 -0
  87. package/lib/esm/hooks/cursor.js.map +1 -0
  88. package/lib/esm/hooks/emojiHistory.js +10 -12
  89. package/lib/esm/hooks/emojiHistory.js.map +1 -1
  90. package/lib/esm/index.js +2 -1
  91. package/lib/esm/index.js.map +1 -1
  92. package/lib/esm/types/api.js +1 -1
  93. package/lib/esm/types/category.js +1 -1
  94. package/lib/esm/utils/asyncEmojiData.js +2 -0
  95. package/lib/esm/utils/asyncEmojiData.js.map +1 -0
  96. package/lib/esm/utils/convertEmojisToUnicodeAsync.js +20 -0
  97. package/lib/esm/utils/convertEmojisToUnicodeAsync.js.map +1 -0
  98. package/lib/esm/utils/emoji.js +3 -5
  99. package/lib/esm/utils/emoji.js.map +1 -1
  100. package/lib/esm/utils/emojiShortList.js +3679 -0
  101. package/lib/esm/utils/emojiShortList.js.map +1 -0
  102. package/lib/esm/utils/insert.js +13 -13
  103. package/lib/esm/utils/insert.js.map +1 -1
  104. package/lib/esm/utils/scroll.js +58 -0
  105. package/lib/esm/utils/scroll.js.map +1 -0
  106. package/lib/esm/utils/selection.js +118 -31
  107. package/lib/esm/utils/selection.js.map +1 -1
  108. package/lib/esm/utils/text.js +7 -1
  109. package/lib/esm/utils/text.js.map +1 -1
  110. package/lib/types/components/emoji-input/EmojiInput.d.ts +10 -3
  111. package/lib/types/components/emoji-input/EmojiInput.styles.d.ts +7 -529
  112. package/lib/types/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +3 -266
  113. package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.d.ts +5 -0
  114. package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.d.ts +5 -0
  115. package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +3 -266
  116. package/lib/types/constants/emoji.d.ts +0 -4
  117. package/lib/types/hooks/cursor.d.ts +11 -0
  118. package/lib/types/index.d.ts +2 -1
  119. package/lib/types/utils/asyncEmojiData.d.ts +1 -0
  120. package/lib/types/utils/convertEmojisToUnicodeAsync.d.ts +3 -0
  121. package/lib/types/utils/emoji.d.ts +8 -2
  122. package/lib/types/utils/emojiShortList.d.ts +4 -0
  123. package/lib/types/utils/insert.d.ts +3 -1
  124. package/lib/types/utils/scroll.d.ts +1 -0
  125. package/lib/types/utils/selection.d.ts +9 -2
  126. package/lib/types/utils/text.d.ts +3 -1
  127. package/package.json +18 -17
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _core = require("@chayns-components/core");
8
8
  var _chaynsApi = require("chayns-api");
9
- var _framerMotion = require("framer-motion");
10
- var _react = _interopRequireWildcard(require("react"));
9
+ var _react = require("motion/react");
10
+ var _react2 = _interopRequireWildcard(require("react"));
11
11
  var _emoji = require("../../utils/emoji");
12
12
  var _insert = require("../../utils/insert");
13
13
  var _selection = require("../../utils/selection");
@@ -15,11 +15,13 @@ var _text = require("../../utils/text");
15
15
  var _EmojiPickerPopup = _interopRequireDefault(require("../emoji-picker-popup/EmojiPickerPopup"));
16
16
  var _EmojiInput = require("./EmojiInput.styles");
17
17
  var _PrefixElement = _interopRequireDefault(require("./prefix-element/PrefixElement"));
18
+ var _asyncEmojiData = require("../../utils/asyncEmojiData");
19
+ var _scroll = require("../../utils/scroll");
20
+ var _cursor = require("../../hooks/cursor");
18
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
22
- const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
22
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
23
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react2.useLayoutEffect : _react2.useEffect;
24
+ const EmojiInput = /*#__PURE__*/(0, _react2.forwardRef)(({
23
25
  accessToken,
24
26
  height,
25
27
  inputId,
@@ -36,31 +38,45 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
36
38
  popupAlignment,
37
39
  prefixElement,
38
40
  rightElement,
39
- shouldHidePlaceholderOnFocus = true,
41
+ shouldHidePlaceholderOnFocus = false,
40
42
  shouldPreventEmojiPicker,
41
- value
43
+ value,
44
+ onCursorPositionChange
42
45
  }, ref) => {
43
- const [isTouch] = (0, _react.useState)((0, _core.getIsTouch)());
44
- const [plainTextValue, setPlainTextValue] = (0, _react.useState)(value);
45
- const [hasFocus, setHasFocus] = (0, _react.useState)(false);
46
- const [progressDuration, setProgressDuration] = (0, _react.useState)(0);
47
- const [labelWidth, setLabelWidth] = (0, _react.useState)(0);
48
- const [isPopupVisible, setIsPopupVisible] = (0, _react.useState)(false);
49
- const [isPrefixAnimationFinished, setIsPrefixAnimationFinished] = (0, _react.useState)(!prefixElement);
50
- const [prefixElementWidth, setPrefixElementWidth] = (0, _react.useState)();
51
- const [textLength, setTextLength] = (0, _react.useState)(0);
52
- const areaProvider = (0, _react.useContext)(_core.AreaContext);
53
- const editorRef = (0, _react.useRef)(null);
54
- const prefixElementRef = (0, _react.useRef)(null);
55
- const hasPrefixRendered = (0, _react.useRef)(false);
56
- const hasPrefixChanged = (0, _react.useRef)(false);
57
- const shouldDeleteOneMoreBackwards = (0, _react.useRef)(false);
58
- const shouldDeleteOneMoreForwards = (0, _react.useRef)(false);
59
- const valueRef = (0, _react.useRef)(value);
46
+ const isTouch = (0, _core.useIsTouch)();
47
+ const [plainTextValue, setPlainTextValue] = (0, _react2.useState)(value);
48
+ const [hasFocus, setHasFocus] = (0, _react2.useState)(false);
49
+ const [progressDuration, setProgressDuration] = (0, _react2.useState)(0);
50
+ const [labelWidth, setLabelWidth] = (0, _react2.useState)(0);
51
+ const [isPopupVisible, setIsPopupVisible] = (0, _react2.useState)(false);
52
+ const [isPrefixAnimationFinished, setIsPrefixAnimationFinished] = (0, _react2.useState)(!prefixElement);
53
+ const [prefixElementWidth, setPrefixElementWidth] = (0, _react2.useState)();
54
+ const [emojiShortNames, setEmojiShortNames] = (0, _react2.useState)({});
55
+ const [emojiRegShortNames, setEmojiRegShortNames] = (0, _react2.useState)(/./);
56
+ const areaProvider = (0, _react2.useContext)(_core.AreaContext);
57
+ const editorRef = (0, _react2.useRef)(null);
58
+ const prefixElementRef = (0, _react2.useRef)(null);
59
+ const hasPrefixRendered = (0, _react2.useRef)(false);
60
+ const hasPrefixChanged = (0, _react2.useRef)(false);
61
+ const shouldDeleteOneMoreBackwards = (0, _react2.useRef)(false);
62
+ const shouldDeleteOneMoreForwards = (0, _react2.useRef)(false);
63
+ const valueRef = (0, _react2.useRef)(value);
64
+ (0, _cursor.useCursorPosition)(editorRef, onCursorPositionChange, {
65
+ isDisabled
66
+ });
60
67
  const {
61
68
  browser
62
69
  } = (0, _chaynsApi.getDevice)();
63
- const shouldChangeColor = (0, _react.useMemo)(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
70
+ const shouldChangeColor = (0, _react2.useMemo)(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
71
+ (0, _react2.useEffect)(() => {
72
+ void (0, _asyncEmojiData.loadEmojiShortList)().then(({
73
+ shortNameList,
74
+ regShortnames
75
+ }) => {
76
+ setEmojiShortNames(shortNameList);
77
+ setEmojiRegShortNames(regShortnames);
78
+ });
79
+ }, []);
64
80
 
65
81
  /**
66
82
  * This function updates the content of the 'contentEditable' element if the new text is
@@ -70,11 +86,11 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
70
86
  * When updating the HTML, the current cursor position is saved before replacing the content, so
71
87
  * that it can be set again afterward.
72
88
  */
73
- const handleUpdateHTML = (0, _react.useCallback)(html => {
89
+ const handleUpdateHTML = (0, _react2.useCallback)(html => {
74
90
  if (!editorRef.current) {
75
91
  return;
76
92
  }
77
- let newInnerHTML = (0, _emoji.convertEmojisToUnicode)(html);
93
+ let newInnerHTML = (0, _emoji.convertEmojisToUnicode)(html, emojiRegShortNames, emojiShortNames);
78
94
  newInnerHTML = (0, _text.convertTextToHTML)(newInnerHTML);
79
95
  if (newInnerHTML !== editorRef.current.innerHTML) {
80
96
  (0, _selection.saveSelection)(editorRef.current, {
@@ -83,8 +99,8 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
83
99
  editorRef.current.innerHTML = newInnerHTML;
84
100
  (0, _selection.restoreSelection)(editorRef.current);
85
101
  }
86
- }, []);
87
- const handleBeforeInput = (0, _react.useCallback)(event => {
102
+ }, [emojiRegShortNames, emojiShortNames]);
103
+ const handleBeforeInput = (0, _react2.useCallback)(event => {
88
104
  if (!editorRef.current) {
89
105
  return;
90
106
  }
@@ -100,7 +116,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
100
116
  if (type === 'textInput' && data && data.includes('\n')) {
101
117
  event.preventDefault();
102
118
  event.stopPropagation();
103
- const text = (0, _emoji.convertEmojisToUnicode)(data);
119
+ const text = (0, _emoji.convertEmojisToUnicode)(data, emojiRegShortNames, emojiShortNames);
104
120
  (0, _insert.insertTextAtCursorPosition)({
105
121
  editorElement: editorRef.current,
106
122
  text
@@ -110,13 +126,13 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
110
126
  });
111
127
  editorRef.current.dispatchEvent(newEvent);
112
128
  }
113
- }, [isDisabled]);
129
+ }, [emojiRegShortNames, emojiShortNames, isDisabled]);
114
130
 
115
131
  /**
116
132
  * This function handles the 'input' events of the 'contentEditable' element and also passes the
117
133
  * respective event up accordingly if the 'onInput' property is a function.
118
134
  */
119
- const handleInput = (0, _react.useCallback)(event => {
135
+ const handleInput = (0, _react2.useCallback)(event => {
120
136
  if (!editorRef.current) {
121
137
  return;
122
138
  }
@@ -150,8 +166,9 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
150
166
  if (typeof onInput === 'function') {
151
167
  onInput(event, text);
152
168
  }
169
+ (0, _selection.insertCursorAtMarker)(editorRef);
153
170
  }, [handleUpdateHTML, isDisabled, onInput]);
154
- const handleKeyDown = (0, _react.useCallback)(event => {
171
+ const handleKeyDown = (0, _react2.useCallback)(event => {
155
172
  if (isDisabled) {
156
173
  event.preventDefault();
157
174
  event.stopPropagation();
@@ -170,6 +187,11 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
170
187
  // noinspection JSDeprecatedSymbols
171
188
  document.execCommand('insertLineBreak', false);
172
189
  }
190
+ if (event.key === 'Enter') {
191
+ requestAnimationFrame(() => {
192
+ if (editorRef.current) (0, _scroll.scrollCursorIntoView)(editorRef.current);
193
+ });
194
+ }
173
195
  if (event.key === 'Backspace' || event.key === 'Delete' || event.key === 'Unidentified') {
174
196
  const charCodeThatWillBeDeleted = (0, _selection.getCharCodeThatWillBeDeleted)(event);
175
197
  if (charCodeThatWillBeDeleted === 8203) {
@@ -181,7 +203,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
181
203
  }
182
204
  }
183
205
  }, [isDisabled, isPopupVisible, onKeyDown]);
184
- const handlePopupVisibility = (0, _react.useCallback)(isVisible => {
206
+ const handlePopupVisibility = (0, _react2.useCallback)(isVisible => {
185
207
  setIsPopupVisible(isVisible);
186
208
  if (editorRef.current && isVisible) {
187
209
  (0, _selection.saveSelection)(editorRef.current);
@@ -196,7 +218,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
196
218
  * plain text is read from the event after the default behavior has been prevented. The plain
197
219
  * text is then inserted at the correct position in the input field using document.execCommand('insertHTML')
198
220
  */
199
- const handlePaste = (0, _react.useCallback)(event => {
221
+ const handlePaste = (0, _react2.useCallback)(event => {
200
222
  if (editorRef.current) {
201
223
  event.preventDefault();
202
224
  if (isDisabled) {
@@ -206,13 +228,18 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
206
228
 
207
229
  // This ensures, that only the copied text is inserted and not its HTML formatting.
208
230
  let text = event.clipboardData.getData('text/plain');
209
- text = (0, _emoji.convertEmojisToUnicode)(text);
231
+ text = (0, _emoji.convertEmojisToUnicode)(text, emojiRegShortNames, emojiShortNames);
210
232
 
211
233
  /* This ensures, that valid HTML in the inserted text is not interpreted as such. e.g. if the user
212
234
  pasted the text '<b>test</b>' (not as formatted html), the <b> tags need to be escaped, to
213
235
  prevent it from being interpreted as html. */
214
236
  text = (0, _emoji.escapeHTML)(text);
215
237
 
238
+ // Insert an invisible control character at the end of the text to place the cursor in the correct position after insertion.
239
+ if (text.includes('\n')) {
240
+ text += '\u200C';
241
+ }
242
+
216
243
  // This deprecated function is used, because it causes the inserted content to be added to the undo stack.
217
244
  // If the text were to be inserted directly into the 'innerHTML' of the editor element, the undo stack would not be updated.
218
245
  // In that case on CTRL+Z the inserted text would not be removed.
@@ -222,14 +249,14 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
222
249
  });
223
250
  editorRef.current.dispatchEvent(newEvent);
224
251
  }
225
- }, [isDisabled]);
252
+ }, [emojiRegShortNames, emojiShortNames, isDisabled]);
226
253
 
227
254
  /**
228
255
  * This function prevents formatting from being adopted when texts are dropped. To do this, the
229
256
  * plain text is read from the event after the default behavior has been prevented. The plain
230
257
  * text is then inserted at the correct position in the input field using document.execCommand('insertHTML')
231
258
  */
232
- const handleDrop = (0, _react.useCallback)(event => {
259
+ const handleDrop = (0, _react2.useCallback)(event => {
233
260
  if (editorRef.current) {
234
261
  var _event$dataTransfer;
235
262
  event.preventDefault();
@@ -243,7 +270,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
243
270
  if (!text) {
244
271
  return;
245
272
  }
246
- text = (0, _emoji.convertEmojisToUnicode)(text);
273
+ text = (0, _emoji.convertEmojisToUnicode)(text, emojiRegShortNames, emojiShortNames);
247
274
 
248
275
  /* This ensures, that valid HTML in the inserted text is not interpreted as such. e.g. if the user
249
276
  drops the text '<b>test</b>' (not as formatted html), the <b> tags need to be escaped, to
@@ -259,7 +286,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
259
286
  });
260
287
  editorRef.current.dispatchEvent(newEvent);
261
288
  }
262
- }, [isDisabled]);
289
+ }, [emojiRegShortNames, emojiShortNames, isDisabled]);
263
290
 
264
291
  /**
265
292
  * This function uses the 'insertTextAtCursorPosition' function to insert the emoji at the
@@ -269,7 +296,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
269
296
  * which in turn executes the 'onInput' function from the props. So this serves to ensure that
270
297
  * the event is also passed through to the top when inserting via the popup.
271
298
  */
272
- const handlePopupSelect = (0, _react.useCallback)(emoji => {
299
+ const handlePopupSelect = (0, _react2.useCallback)(emoji => {
273
300
  if (editorRef.current) {
274
301
  (0, _insert.insertTextAtCursorPosition)({
275
302
  editorElement: editorRef.current,
@@ -282,7 +309,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
282
309
  editorRef.current.dispatchEvent(event);
283
310
  }
284
311
  }, []);
285
- (0, _react.useEffect)(() => {
312
+ (0, _react2.useEffect)(() => {
286
313
  var _editorRef$current;
287
314
  if (typeof onPrefixElementRemove !== 'function') {
288
315
  return;
@@ -302,12 +329,12 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
302
329
  onPrefixElementRemove();
303
330
  hasPrefixRendered.current = false;
304
331
  }, [onPrefixElementRemove, plainTextValue.length, prefixElement]);
305
- (0, _react.useEffect)(() => {
332
+ (0, _react2.useEffect)(() => {
306
333
  if (typeof prefixElement === 'string') {
307
334
  hasPrefixChanged.current = true;
308
335
  }
309
336
  }, [prefixElement]);
310
- (0, _react.useEffect)(() => {
337
+ (0, _react2.useEffect)(() => {
311
338
  if (value !== plainTextValue) {
312
339
  setPlainTextValue(value);
313
340
  handleUpdateHTML(value);
@@ -320,7 +347,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
320
347
  useIsomorphicLayoutEffect(() => {
321
348
  handleUpdateHTML(valueRef.current);
322
349
  }, [handleUpdateHTML]);
323
- const handleInsertTextAtCursorPosition = (0, _react.useCallback)(text => {
350
+ const handleInsertTextAtCursorPosition = (0, _react2.useCallback)(text => {
324
351
  if (editorRef.current) {
325
352
  (0, _insert.insertTextAtCursorPosition)({
326
353
  editorElement: editorRef.current,
@@ -332,32 +359,42 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
332
359
  editorRef.current.dispatchEvent(newEvent);
333
360
  }
334
361
  }, []);
335
- const handleReplaceText = (0, _react.useCallback)((searchText, pasteText) => {
362
+ const handleReplaceText = (0, _react2.useCallback)((searchText, pasteText, options) => {
336
363
  if (editorRef.current) {
337
364
  (0, _insert.replaceText)({
338
365
  editorElement: editorRef.current,
339
366
  searchText,
340
- pasteText
367
+ pasteText,
368
+ options
341
369
  });
370
+ (0, _selection.insertPseudoMarker)();
342
371
  const newEvent = new Event('input', {
343
372
  bubbles: true
344
373
  });
345
374
  editorRef.current.dispatchEvent(newEvent);
346
375
  }
347
376
  }, []);
348
- const handleStartProgress = (0, _react.useCallback)(duration => {
377
+ const handleStartProgress = (0, _react2.useCallback)(duration => {
349
378
  setProgressDuration(duration);
350
379
  }, []);
351
- const handleStopProgress = (0, _react.useCallback)(() => {
380
+ const handleStopProgress = (0, _react2.useCallback)(() => {
352
381
  setProgressDuration(0);
353
382
  }, []);
354
- (0, _react.useImperativeHandle)(ref, () => ({
383
+ (0, _react2.useImperativeHandle)(ref, () => ({
355
384
  insertTextAtCursorPosition: handleInsertTextAtCursorPosition,
356
385
  replaceText: handleReplaceText,
357
386
  startProgress: handleStartProgress,
358
- stopProgress: handleStopProgress
387
+ stopProgress: handleStopProgress,
388
+ focus: () => {
389
+ var _editorRef$current2;
390
+ return (_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.focus();
391
+ },
392
+ blur: () => {
393
+ var _editorRef$current3;
394
+ return (_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 ? void 0 : _editorRef$current3.blur();
395
+ }
359
396
  }), [handleInsertTextAtCursorPosition, handleReplaceText, handleStartProgress, handleStopProgress]);
360
- (0, _react.useEffect)(() => {
397
+ (0, _react2.useEffect)(() => {
361
398
  /**
362
399
  * This function ensures that the input field does not lose focus when the popup is opened
363
400
  * or an emoji is selected in it. For this purpose the corresponding elements get the class
@@ -379,12 +416,12 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
379
416
  document.body.removeEventListener('mousedown', handlePreventLoseFocus);
380
417
  };
381
418
  }, []);
382
- const shouldShowPlaceholder = (0, _react.useMemo)(() => {
383
- var _editorRef$current2;
419
+ const shouldShowPlaceholder = (0, _react2.useMemo)(() => {
420
+ var _editorRef$current4;
384
421
  if (!isPrefixAnimationFinished) {
385
422
  return false;
386
423
  }
387
- const isJustPrefixElement = prefixElement && (0, _text.convertTextToHTML)(prefixElement) === ((_editorRef$current2 = editorRef.current) === null || _editorRef$current2 === void 0 ? void 0 : _editorRef$current2.innerHTML);
424
+ const isJustPrefixElement = prefixElement && (0, _text.convertTextToHTML)(prefixElement) === ((_editorRef$current4 = editorRef.current) === null || _editorRef$current4 === void 0 ? void 0 : _editorRef$current4.innerHTML);
388
425
  const shouldRenderPlaceholder = prefixElement && !plainTextValue || (prefixElement ? prefixElementWidth && prefixElementWidth > 0 : true);
389
426
  switch (true) {
390
427
  case (!plainTextValue || isJustPrefixElement) && shouldHidePlaceholderOnFocus && !hasFocus:
@@ -396,7 +433,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
396
433
  return false;
397
434
  }
398
435
  }, [isPrefixAnimationFinished, hasFocus, plainTextValue, prefixElement, shouldHidePlaceholderOnFocus, prefixElementWidth]);
399
- (0, _react.useEffect)(() => {
436
+ (0, _react2.useEffect)(() => {
400
437
  if (prefixElement) {
401
438
  setIsPrefixAnimationFinished(false);
402
439
  }
@@ -413,9 +450,9 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
413
450
  }
414
451
  setHasFocus(false);
415
452
  };
416
- (0, _react.useEffect)(() => {
453
+ (0, _react2.useEffect)(() => {
417
454
  if (editorRef.current && prefixElement) {
418
- const text = (0, _emoji.convertEmojisToUnicode)(prefixElement);
455
+ const text = (0, _emoji.convertEmojisToUnicode)(prefixElement, emojiRegShortNames, emojiShortNames);
419
456
  (0, _insert.insertTextAtCursorPosition)({
420
457
  editorElement: editorRef.current,
421
458
  text
@@ -423,16 +460,16 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
423
460
  handleUpdateHTML(prefixElement);
424
461
  hasPrefixRendered.current = true;
425
462
  }
426
- }, [handleUpdateHTML, prefixElement]);
427
- (0, _react.useEffect)(() => {
428
- var _editorRef$current3;
429
- if (prefixElementRef.current && prefixElement && (0, _text.convertTextToHTML)(prefixElement) === ((_editorRef$current3 = editorRef.current) === null || _editorRef$current3 === void 0 ? void 0 : _editorRef$current3.innerHTML)) {
463
+ }, [emojiRegShortNames, emojiShortNames, handleUpdateHTML, prefixElement]);
464
+ (0, _react2.useEffect)(() => {
465
+ var _editorRef$current5;
466
+ if (prefixElementRef.current && prefixElement && (0, _text.convertTextToHTML)(prefixElement) === ((_editorRef$current5 = editorRef.current) === null || _editorRef$current5 === void 0 ? void 0 : _editorRef$current5.innerHTML)) {
430
467
  setPrefixElementWidth(prefixElementRef.current.offsetWidth + 2);
431
468
  } else {
432
469
  setPrefixElementWidth(undefined);
433
470
  }
434
471
  }, [plainTextValue, prefixElement]);
435
- (0, _react.useEffect)(() => {
472
+ (0, _react2.useEffect)(() => {
436
473
  const handleResize = () => {
437
474
  if (editorRef.current) {
438
475
  setLabelWidth(editorRef.current.offsetWidth);
@@ -446,7 +483,7 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
446
483
  resizeObserver.disconnect();
447
484
  };
448
485
  }, []);
449
- (0, _react.useEffect)(() => {
486
+ (0, _react2.useEffect)(() => {
450
487
  const blurElement = () => {
451
488
  if (editorRef.current && document.activeElement === editorRef.current && isDisabled) {
452
489
  editorRef.current.blur();
@@ -457,12 +494,12 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
457
494
  document.removeEventListener('focus', blurElement, true);
458
495
  };
459
496
  }, [isDisabled]);
460
- return /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInput, {
497
+ return /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledEmojiInput, {
461
498
  $isDisabled: isDisabled,
462
499
  $shouldChangeColor: shouldChangeColor
463
- }, /*#__PURE__*/_react.default.createElement(_framerMotion.AnimatePresence, {
500
+ }, /*#__PURE__*/_react2.default.createElement(_react.AnimatePresence, {
464
501
  initial: true
465
- }, progressDuration > 0 && /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledMotionEmojiInputProgress, {
502
+ }, progressDuration > 0 && /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledMotionEmojiInputProgress, {
466
503
  animate: {
467
504
  width: '100%'
468
505
  },
@@ -483,12 +520,12 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
483
520
  duration: 0.3
484
521
  }
485
522
  }
486
- })), /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputContent, null, prefixElement && /*#__PURE__*/_react.default.createElement(_PrefixElement.default, {
523
+ })), /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledEmojiInputContent, null, prefixElement && /*#__PURE__*/_react2.default.createElement(_PrefixElement.default, {
487
524
  key: prefixElement,
488
525
  element: prefixElement,
489
526
  prefixElementRef: prefixElementRef,
490
527
  setIsPrefixAnimationFinished: setIsPrefixAnimationFinished
491
- }), /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledMotionEmojiInputEditor, {
528
+ }), /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledMotionEmojiInputEditor, {
492
529
  $browser: browser === null || browser === void 0 ? void 0 : browser.name,
493
530
  animate: {
494
531
  maxHeight: height ?? maxHeight,
@@ -509,15 +546,15 @@ const EmojiInput = /*#__PURE__*/(0, _react.forwardRef)(({
509
546
  type: 'tween',
510
547
  duration: 0.2
511
548
  }
512
- }), shouldShowPlaceholder && /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputLabel, {
549
+ }), shouldShowPlaceholder && /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledEmojiInputLabel, {
513
550
  $maxWidth: labelWidth,
514
551
  $offsetWidth: prefixElementWidth
515
- }, placeholder), !isTouch && !shouldPreventEmojiPicker && /*#__PURE__*/_react.default.createElement(_EmojiPickerPopup.default, {
552
+ }, placeholder), !isTouch && !shouldPreventEmojiPicker && /*#__PURE__*/_react2.default.createElement(_EmojiPickerPopup.default, {
516
553
  accessToken: accessToken,
517
554
  onSelect: handlePopupSelect,
518
555
  onPopupVisibilityChange: handlePopupVisibility,
519
556
  personId: personId
520
- })), rightElement && /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputRightWrapper, null, rightElement));
557
+ })), rightElement && /*#__PURE__*/_react2.default.createElement(_EmojiInput.StyledEmojiInputRightWrapper, null, rightElement));
521
558
  });
522
559
  EmojiInput.displayName = 'EmojiInput';
523
560
  var _default = exports.default = EmojiInput;