@chayns-components/emoji-input 5.0.0-beta.90 → 5.0.0-beta.900

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 (228) hide show
  1. package/README.md +4 -15
  2. package/lib/{api → cjs/api}/item-storage/get.js +4 -5
  3. package/lib/cjs/api/item-storage/get.js.map +1 -0
  4. package/lib/{api → cjs/api}/item-storage/put.js +5 -6
  5. package/lib/cjs/api/item-storage/put.js.map +1 -0
  6. package/lib/cjs/components/emoji-input/EmojiInput.js +510 -0
  7. package/lib/cjs/components/emoji-input/EmojiInput.js.map +1 -0
  8. package/lib/cjs/components/emoji-input/EmojiInput.styles.js +132 -0
  9. package/lib/cjs/components/emoji-input/EmojiInput.styles.js.map +1 -0
  10. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js +45 -0
  11. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
  12. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js +65 -0
  13. package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
  14. package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.js +9 -11
  15. package/lib/cjs/components/emoji-picker/EmojiPicker.js.map +1 -0
  16. package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.styles.js +3 -5
  17. package/lib/cjs/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
  18. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +102 -0
  19. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
  20. package/lib/{components → cjs/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +5 -6
  21. package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
  22. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
  23. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
  24. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +69 -0
  25. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
  26. package/lib/{components → cjs/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +49 -21
  27. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
  28. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +24 -0
  29. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
  30. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +130 -0
  31. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
  32. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +99 -0
  33. package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
  34. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js +52 -0
  35. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
  36. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js +15 -0
  37. package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
  38. package/lib/{constants → cjs/constants}/alignment.js +6 -8
  39. package/lib/cjs/constants/alignment.js.map +1 -0
  40. package/lib/{constants → cjs/constants}/categories.js +1 -2
  41. package/lib/cjs/constants/categories.js.map +1 -0
  42. package/lib/cjs/constants/emoji.js +3804 -0
  43. package/lib/cjs/constants/emoji.js.map +1 -0
  44. package/lib/cjs/constants/externalServerUrl.js +8 -0
  45. package/lib/cjs/constants/externalServerUrl.js.map +1 -0
  46. package/lib/cjs/constants/regex.js +15 -0
  47. package/lib/cjs/constants/regex.js.map +1 -0
  48. package/lib/{hooks → cjs/hooks}/emojiHistory.js +13 -15
  49. package/lib/cjs/hooks/emojiHistory.js.map +1 -0
  50. package/lib/{index.js → cjs/index.js} +3 -3
  51. package/lib/cjs/index.js.map +1 -0
  52. package/lib/cjs/types/api.js +2 -0
  53. package/lib/cjs/types/api.js.map +1 -0
  54. package/lib/cjs/types/category.js +2 -0
  55. package/lib/cjs/types/category.js.map +1 -0
  56. package/lib/cjs/utils/emoji.js +104 -0
  57. package/lib/cjs/utils/emoji.js.map +1 -0
  58. package/lib/{utils → cjs/utils}/environment.js +6 -4
  59. package/lib/cjs/utils/environment.js.map +1 -0
  60. package/lib/cjs/utils/font.js +17 -0
  61. package/lib/cjs/utils/font.js.map +1 -0
  62. package/lib/cjs/utils/insert.js +110 -0
  63. package/lib/cjs/utils/insert.js.map +1 -0
  64. package/lib/cjs/utils/number.js +17 -0
  65. package/lib/cjs/utils/number.js.map +1 -0
  66. package/lib/cjs/utils/selection.js +255 -0
  67. package/lib/cjs/utils/selection.js.map +1 -0
  68. package/lib/cjs/utils/text.js +57 -0
  69. package/lib/cjs/utils/text.js.map +1 -0
  70. package/lib/esm/api/item-storage/get.js +30 -0
  71. package/lib/esm/api/item-storage/get.js.map +1 -0
  72. package/lib/esm/api/item-storage/put.js +35 -0
  73. package/lib/esm/api/item-storage/put.js.map +1 -0
  74. package/lib/esm/components/emoji-input/EmojiInput.js +497 -0
  75. package/lib/esm/components/emoji-input/EmojiInput.js.map +1 -0
  76. package/lib/esm/components/emoji-input/EmojiInput.styles.js +151 -0
  77. package/lib/esm/components/emoji-input/EmojiInput.styles.js.map +1 -0
  78. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js +38 -0
  79. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
  80. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js +69 -0
  81. package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
  82. package/lib/esm/components/emoji-picker/EmojiPicker.js +40 -0
  83. package/lib/esm/components/emoji-picker/EmojiPicker.js.map +1 -0
  84. package/lib/esm/components/emoji-picker/EmojiPicker.styles.js +16 -0
  85. package/lib/esm/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
  86. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +96 -0
  87. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
  88. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +18 -0
  89. package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
  90. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
  91. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
  92. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +76 -0
  93. package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
  94. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +136 -0
  95. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
  96. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +20 -0
  97. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
  98. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +121 -0
  99. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
  100. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +98 -0
  101. package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
  102. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js +43 -0
  103. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
  104. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js +8 -0
  105. package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
  106. package/lib/esm/constants/alignment.js +13 -0
  107. package/lib/esm/constants/alignment.js.map +1 -0
  108. package/lib/esm/constants/categories.js +13 -0
  109. package/lib/esm/constants/categories.js.map +1 -0
  110. package/lib/esm/constants/emoji-de-DE.json +3827 -0
  111. package/lib/esm/constants/emoji.js +3798 -0
  112. package/lib/esm/constants/emoji.js.map +1 -0
  113. package/lib/esm/constants/externalServerUrl.js +2 -0
  114. package/lib/esm/constants/externalServerUrl.js.map +1 -0
  115. package/lib/esm/constants/regex.js +9 -0
  116. package/lib/esm/constants/regex.js.map +1 -0
  117. package/lib/esm/hooks/emojiHistory.js +83 -0
  118. package/lib/esm/hooks/emojiHistory.js.map +1 -0
  119. package/lib/{index.d.ts → esm/index.js} +2 -1
  120. package/lib/esm/index.js.map +1 -0
  121. package/lib/esm/types/api.js +2 -0
  122. package/lib/esm/types/api.js.map +1 -0
  123. package/lib/esm/types/category.js +2 -0
  124. package/lib/esm/types/category.js.map +1 -0
  125. package/lib/esm/utils/emoji.js +92 -0
  126. package/lib/esm/utils/emoji.js.map +1 -0
  127. package/lib/esm/utils/environment.js +24 -0
  128. package/lib/esm/utils/environment.js.map +1 -0
  129. package/lib/esm/utils/font.js +10 -0
  130. package/lib/esm/utils/font.js.map +1 -0
  131. package/lib/esm/utils/insert.js +104 -0
  132. package/lib/esm/utils/insert.js.map +1 -0
  133. package/lib/esm/utils/number.js +10 -0
  134. package/lib/esm/utils/number.js.map +1 -0
  135. package/lib/esm/utils/selection.js +237 -0
  136. package/lib/esm/utils/selection.js.map +1 -0
  137. package/lib/esm/utils/text.js +48 -0
  138. package/lib/esm/utils/text.js.map +1 -0
  139. package/lib/types/components/emoji-input/EmojiInput.d.ts +94 -0
  140. package/lib/types/components/emoji-input/EmojiInput.styles.d.ts +549 -0
  141. package/lib/types/components/emoji-input/prefix-element/PrefixElement.d.ts +8 -0
  142. package/lib/types/components/emoji-input/prefix-element/PrefixElement.styles.d.ts +12 -0
  143. package/lib/types/components/emoji-picker/EmojiPicker.styles.d.ts +5 -0
  144. package/lib/types/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +267 -0
  145. package/lib/types/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +10 -0
  146. package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.d.ts +5 -0
  147. package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +6 -0
  148. package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +283 -0
  149. package/lib/{components → types/components}/emoji-picker-popup/EmojiPickerPopup.d.ts +0 -13
  150. package/lib/types/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +1 -0
  151. package/lib/types/constants/emoji.d.ts +8 -0
  152. package/lib/types/constants/regex.d.ts +8 -0
  153. package/lib/types/index.d.ts +6 -0
  154. package/lib/types/utils/emoji.d.ts +4 -0
  155. package/lib/{utils → types/utils}/environment.d.ts +1 -0
  156. package/lib/types/utils/font.d.ts +1 -0
  157. package/lib/types/utils/insert.d.ts +26 -0
  158. package/lib/types/utils/number.d.ts +1 -0
  159. package/lib/types/utils/selection.d.ts +23 -0
  160. package/lib/types/utils/text.d.ts +3 -0
  161. package/package.json +48 -30
  162. package/lib/api/item-storage/get.js.map +0 -1
  163. package/lib/api/item-storage/put.js.map +0 -1
  164. package/lib/components/emoji-input/EmojiInput.d.ts +0 -49
  165. package/lib/components/emoji-input/EmojiInput.js +0 -168
  166. package/lib/components/emoji-input/EmojiInput.js.map +0 -1
  167. package/lib/components/emoji-input/EmojiInput.styles.d.ts +0 -16
  168. package/lib/components/emoji-input/EmojiInput.styles.js +0 -152
  169. package/lib/components/emoji-input/EmojiInput.styles.js.map +0 -1
  170. package/lib/components/emoji-picker/EmojiPicker.js.map +0 -1
  171. package/lib/components/emoji-picker/EmojiPicker.styles.d.ts +0 -5
  172. package/lib/components/emoji-picker/EmojiPicker.styles.js.map +0 -1
  173. package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +0 -51
  174. package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +0 -1
  175. package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +0 -2
  176. package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +0 -1
  177. package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +0 -131
  178. package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +0 -1
  179. package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +0 -7
  180. package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +0 -99
  181. package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +0 -1
  182. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +0 -1
  183. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +0 -1
  184. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +0 -20
  185. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +0 -1
  186. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +0 -74
  187. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +0 -1
  188. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +0 -11
  189. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +0 -104
  190. package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +0 -1
  191. package/lib/components/emoji-picker-popup/EmojiPickerPopup.js +0 -150
  192. package/lib/components/emoji-picker-popup/EmojiPickerPopup.js.map +0 -1
  193. package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +0 -7
  194. package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js +0 -97
  195. package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +0 -1
  196. package/lib/constants/alignment.js.map +0 -1
  197. package/lib/constants/categories.js.map +0 -1
  198. package/lib/constants/externalServerUrl.js +0 -9
  199. package/lib/constants/externalServerUrl.js.map +0 -1
  200. package/lib/hooks/emojiHistory.js.map +0 -1
  201. package/lib/index.js.map +0 -1
  202. package/lib/types/api.js +0 -6
  203. package/lib/types/api.js.map +0 -1
  204. package/lib/types/category.js +0 -6
  205. package/lib/types/category.js.map +0 -1
  206. package/lib/utils/emoji.d.ts +0 -2
  207. package/lib/utils/emoji.js +0 -205
  208. package/lib/utils/emoji.js.map +0 -1
  209. package/lib/utils/environment.js.map +0 -1
  210. package/lib/utils/font.d.ts +0 -1
  211. package/lib/utils/font.js +0 -15
  212. package/lib/utils/font.js.map +0 -1
  213. package/lib/utils/selection.d.ts +0 -2
  214. package/lib/utils/selection.js +0 -43
  215. package/lib/utils/selection.js.map +0 -1
  216. /package/lib/{constants → cjs/constants}/emoji-de-DE.json +0 -0
  217. /package/lib/{api → types/api}/item-storage/get.d.ts +0 -0
  218. /package/lib/{api → types/api}/item-storage/put.d.ts +0 -0
  219. /package/lib/{components → types/components}/emoji-picker/EmojiPicker.d.ts +0 -0
  220. /package/lib/{components → types/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.d.ts +0 -0
  221. /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.d.ts +0 -0
  222. /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.d.ts +0 -0
  223. /package/lib/{constants → types/constants}/alignment.d.ts +0 -0
  224. /package/lib/{constants → types/constants}/categories.d.ts +0 -0
  225. /package/lib/{constants → types/constants}/externalServerUrl.d.ts +0 -0
  226. /package/lib/{hooks → types/hooks}/emojiHistory.d.ts +0 -0
  227. /package/lib/types/{api.d.ts → types/api.d.ts} +0 -0
  228. /package/lib/types/{category.d.ts → types/category.d.ts} +0 -0
@@ -0,0 +1,8 @@
1
+ export declare const asciiList: {
2
+ [key: string]: string;
3
+ };
4
+ export declare const regAscii: RegExp;
5
+ export declare const shortNameList: {
6
+ [key: string]: string;
7
+ };
8
+ export declare const regShortnames: RegExp;
@@ -0,0 +1,8 @@
1
+ export declare const BB_LC_MENTION_REGEX: RegExp;
2
+ export declare const BB_NER_IGNORE_REGEX: RegExp;
3
+ export declare const BB_NER_REPLACE_REGEX: RegExp;
4
+ export declare const HTML_LC_MENTION_REGEX: RegExp;
5
+ export declare const HTML_NER_IGNORE_REGEX: RegExp;
6
+ export declare const HTML_NER_REPLACE_REGEX: RegExp;
7
+ export declare const HTML_BOLD_REGEX: RegExp;
8
+ export declare const HTML_A_TAG_REGEX: RegExp;
@@ -0,0 +1,6 @@
1
+ export { default as EmojiInput } from './components/emoji-input/EmojiInput';
2
+ export type { EmojiInputRef } from './components/emoji-input/EmojiInput';
3
+ export { default as EmojiPickerPopup } from './components/emoji-picker-popup/EmojiPickerPopup';
4
+ export { default as EmojiPicker } from './components/emoji-picker/EmojiPicker';
5
+ export { PopupAlignment } from './constants/alignment';
6
+ export { convertEmojisToUnicode } from './utils/emoji';
@@ -0,0 +1,4 @@
1
+ export declare const unescapeHTML: (text: string) => string;
2
+ export declare const escapeHTML: (text: string) => string;
3
+ export declare const convertEmojisToUnicode: (text: string) => string;
4
+ export declare const addSkinToneToEmoji: (emoji: string, skinTone: string) => string;
@@ -4,5 +4,6 @@ declare enum DeviceType {
4
4
  Tablet = 2
5
5
  }
6
6
  export declare const getDeviceType: () => DeviceType;
7
+ export declare const getIsMacOS: () => boolean;
7
8
  export declare const getIsMobile: () => boolean;
8
9
  export {};
@@ -0,0 +1 @@
1
+ export declare const getFontFamily: () => string;
@@ -0,0 +1,26 @@
1
+ interface InsertTextAtCursorPositionOptions {
2
+ editorElement: HTMLDivElement;
3
+ text: string;
4
+ shouldUseSavedSelection?: boolean;
5
+ }
6
+ /**
7
+ * This function inserts the passed text at the correct position in the editor element. If the
8
+ * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji
9
+ * will be appended to the back of the input field content.
10
+ *
11
+ * In addition, this function also sets the cursor to the correct position when the input field
12
+ * has the focus. For this purpose, the current position of the cursor or a selection is read to
13
+ * calculate the cursor position after inserting the text.
14
+ *
15
+ * @param {Object} options - Object with element and text to insert
16
+ * @param {HTMLDivElement} options.editorElement - Element to insert text into
17
+ * @param {string} options.text - Text to insert into element
18
+ */
19
+ export declare const insertTextAtCursorPosition: ({ editorElement, text, shouldUseSavedSelection, }: InsertTextAtCursorPositionOptions) => void;
20
+ export interface ReplaceTextOptions {
21
+ editorElement: HTMLDivElement;
22
+ searchText: string;
23
+ pasteText: string;
24
+ }
25
+ export declare const replaceText: ({ editorElement, searchText, pasteText }: ReplaceTextOptions) => void;
26
+ export {};
@@ -0,0 +1 @@
1
+ export declare const clamp: (value: number, min: number, max: number) => number;
@@ -0,0 +1,23 @@
1
+ import type { KeyboardEvent } from 'react';
2
+ interface SaveSelectionOptions {
3
+ shouldIgnoreEmptyTextNodes?: boolean;
4
+ }
5
+ export declare const saveSelection: (element: HTMLDivElement, { shouldIgnoreEmptyTextNodes }?: SaveSelectionOptions) => void;
6
+ export declare const restoreSelection: (element: HTMLDivElement) => void;
7
+ export declare const insertInvisibleCursorMarker: () => void;
8
+ export declare const moveSelectionOffset: (distance: number) => void;
9
+ export declare const setChildIndex: (index: number) => void;
10
+ /**
11
+ * This function returns the code of the character that will be removed by the KeyDown event in the
12
+ * next step, if the "Backspace" or "Delete" key was pressed and there is no selection of multiple
13
+ * characters.
14
+ *
15
+ * @param event - Keyboard event from "onKeyDown"
16
+ */
17
+ export declare const getCharCodeThatWillBeDeleted: (event: KeyboardEvent<HTMLDivElement>) => number | null | undefined;
18
+ interface FindAndSelectTextOptions {
19
+ editorElement: HTMLDivElement;
20
+ searchText: string;
21
+ }
22
+ export declare const findAndSelectText: ({ editorElement, searchText, }: FindAndSelectTextOptions) => Range | null;
23
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const convertTextToHTML: (text: string) => string;
2
+ export declare const convertHTMLToText: (text: string) => string;
3
+ export declare const getElementTextLength: (element: Element) => number;
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@chayns-components/emoji-input",
3
- "version": "5.0.0-beta.90",
3
+ "version": "5.0.0-beta.900",
4
4
  "description": "Input field that supports HTML elements and emojis",
5
+ "sideEffects": false,
6
+ "browserslist": [
7
+ ">0.5%",
8
+ "not dead",
9
+ "not op_mini all",
10
+ "not IE 11"
11
+ ],
5
12
  "keywords": [
6
13
  "chayns",
7
14
  "react",
@@ -13,8 +20,16 @@
13
20
  "author": "Tobit.Software",
14
21
  "homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/emoji-input#readme",
15
22
  "license": "MIT",
16
- "main": "lib/index.js",
17
- "types": "lib/index.d.ts",
23
+ "main": "lib/cjs/index.js",
24
+ "module": "lib/esm/index.js",
25
+ "types": "lib/types/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "require": "./lib/cjs/index.js",
29
+ "import": "./lib/esm/index.js",
30
+ "types": "./lib/types/index.d.ts"
31
+ }
32
+ },
18
33
  "directories": {
19
34
  "lib": "lib",
20
35
  "test": "__tests__"
@@ -27,46 +42,49 @@
27
42
  "url": "git+https://github.com/TobitSoftware/chayns-components.git"
28
43
  },
29
44
  "scripts": {
30
- "build": "npm run build:js && npm run build:types",
31
- "build:js": "babel src --out-dir lib --extensions=.ts,.tsx --source-maps --ignore=src/stories --copy-files",
45
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
32
46
  "build:types": "tsc",
33
- "prepublishOnly": "npm run build"
47
+ "build:cjs": "cross-env NODE_ENV=cjs babel src --out-dir lib/cjs --extensions=.ts,.tsx --source-maps --ignore=src/stories --copy-files",
48
+ "build:esm": "cross-env NODE_ENV=esm babel src --out-dir lib/esm --extensions=.ts,.tsx --source-maps --ignore=src/stories --copy-files",
49
+ "prepublishOnly": "npm run build",
50
+ "watch:js": "npm run build:esm -- --watch",
51
+ "link": "npm link && npm run watch:js"
34
52
  },
35
53
  "bugs": {
36
54
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
37
55
  },
38
56
  "devDependencies": {
39
- "@babel/cli": "^7.21.0",
40
- "@babel/core": "^7.21.0",
41
- "@babel/preset-env": "^7.20.2",
42
- "@babel/preset-react": "^7.18.6",
43
- "@babel/preset-typescript": "^7.21.0",
44
- "@types/react": "^17.0.53",
45
- "@types/react-dom": "^17.0.19",
46
- "@types/styled-components": "^5.1.26",
47
- "@types/uuid": "^9.0.1",
48
- "babel-loader": "^8.3.0",
49
- "lerna": "^6.5.1",
50
- "react": "^17.0.2",
51
- "react-dom": "^17.0.2",
52
- "typescript": "^4.9.5"
57
+ "@babel/cli": "^7.25.9",
58
+ "@babel/core": "^7.26.0",
59
+ "@babel/preset-env": "^7.26.0",
60
+ "@babel/preset-react": "^7.25.9",
61
+ "@babel/preset-typescript": "^7.26.0",
62
+ "@types/react": "^18.3.12",
63
+ "@types/react-dom": "^18.3.1",
64
+ "@types/styled-components": "^5.1.34",
65
+ "@types/uuid": "^10.0.0",
66
+ "babel-loader": "^9.2.1",
67
+ "cross-env": "^7.0.3",
68
+ "lerna": "^8.1.9",
69
+ "react": "^18.3.1",
70
+ "react-dom": "^18.3.1",
71
+ "styled-components": "^6.1.13",
72
+ "typescript": "^5.7.2"
53
73
  },
54
74
  "dependencies": {
55
- "@chayns-components/core": "^5.0.0-beta.90",
56
- "@chayns/colors": "^2.0.0",
57
- "clsx": "^1.2.1",
58
- "emojilib": "^3.0.8",
59
- "framer-motion": "^6.5.1",
60
- "styled-components": "^5.3.8",
61
- "unicode-emoji-json": "^0.5.0",
62
- "uuid": "^9.0.0"
75
+ "@chayns-components/core": "^5.0.0-beta.900",
76
+ "emojilib": "^3.0.12",
77
+ "unicode-emoji-json": "^0.8.0"
63
78
  },
64
79
  "peerDependencies": {
80
+ "chayns-api": ">=1.0.73",
81
+ "framer-motion": ">=10.18.0",
65
82
  "react": ">=16.14.0",
66
- "react-dom": ">=16.14.0"
83
+ "react-dom": ">=16.14.0",
84
+ "styled-components": ">=5.3.11"
67
85
  },
68
86
  "publishConfig": {
69
87
  "access": "public"
70
88
  },
71
- "gitHead": "f0e8c6a4f8faf043c756bb397ba0aa3e6165882d"
89
+ "gitHead": "cfbfe5a437b403a9c6b3812d4215cb568bd8d91f"
72
90
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"get.js","names":["_externalServerUrl","require","getEmojiHistory","_ref","accessToken","personId","requestInit","headers","Authorization","method","url","ITEM_STORAGE_BASE_URL","response","fetch","status","data","json","value","e","exports"],"sources":["../../../src/api/item-storage/get.ts"],"sourcesContent":["import { ITEM_STORAGE_BASE_URL } from '../../constants/externalServerUrl';\nimport type { HistoryItem } from '../../hooks/emojiHistory';\nimport type { ApiFunctionResult } from '../../types/api';\n\ninterface GetEmojiHistoryOptions {\n accessToken: string;\n personId: string;\n}\n\ninterface GetEmojiHistoryResponseData {\n key: string;\n personId: string;\n schemeId: string;\n value: HistoryItem[];\n}\n\nexport const getEmojiHistory = async ({\n accessToken,\n personId,\n}: GetEmojiHistoryOptions): Promise<ApiFunctionResult<HistoryItem[]>> => {\n const requestInit: RequestInit = {\n headers: {\n Authorization: `Bearer ${accessToken}`,\n },\n method: 'GET',\n };\n\n const url = `${ITEM_STORAGE_BASE_URL}/7/users/${personId}/keys/emojis`;\n\n const response = await fetch(url, requestInit);\n\n if (response.status === 200) {\n try {\n const data = (await response.json()) as GetEmojiHistoryResponseData;\n\n return { data: data.value, status: 200 };\n } catch (e) {\n // Do nothing\n }\n }\n\n return { status: response.status };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAgBO,MAAMC,eAAe,GAAG,MAAAC,IAAA,IAG0C;EAAA,IAHnC;IAClCC,WAAW;IACXC;EACoB,CAAC,GAAAF,IAAA;EACrB,MAAMG,WAAwB,GAAG;IAC7BC,OAAO,EAAE;MACLC,aAAa,EAAG,UAASJ,WAAY;IACzC,CAAC;IACDK,MAAM,EAAE;EACZ,CAAC;EAED,MAAMC,GAAG,GAAI,GAAEC,wCAAsB,YAAWN,QAAS,cAAa;EAEtE,MAAMO,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAG,EAAEJ,WAAW,CAAC;EAE9C,IAAIM,QAAQ,CAACE,MAAM,KAAK,GAAG,EAAE;IACzB,IAAI;MACA,MAAMC,IAAI,GAAI,MAAMH,QAAQ,CAACI,IAAI,EAAkC;MAEnE,OAAO;QAAED,IAAI,EAAEA,IAAI,CAACE,KAAK;QAAEH,MAAM,EAAE;MAAI,CAAC;IAC5C,CAAC,CAAC,OAAOI,CAAC,EAAE;MACR;IAAA;EAER;EAEA,OAAO;IAAEJ,MAAM,EAAEF,QAAQ,CAACE;EAAO,CAAC;AACtC,CAAC;AAACK,OAAA,CAAAjB,eAAA,GAAAA,eAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"put.js","names":["_externalServerUrl","require","putEmojiHistory","_ref","accessToken","personId","value","requestInit","body","JSON","stringify","headers","Authorization","method","url","ITEM_STORAGE_BASE_URL","response","fetch","status","data","json","e","exports"],"sources":["../../../src/api/item-storage/put.ts"],"sourcesContent":["import { ITEM_STORAGE_BASE_URL } from '../../constants/externalServerUrl';\nimport type { HistoryItem } from '../../hooks/emojiHistory';\nimport type { ApiFunctionResult } from '../../types/api';\n\ninterface PutEmojiHistoryOptions {\n accessToken: string;\n personId: string;\n value: HistoryItem[];\n}\n\ninterface PutEmojiHistoryResponseData {\n key: string;\n personId: string;\n schemeId: string;\n value: HistoryItem[];\n}\n\nexport const putEmojiHistory = async ({\n accessToken,\n personId,\n value,\n}: PutEmojiHistoryOptions): Promise<ApiFunctionResult<HistoryItem[]>> => {\n const requestInit: RequestInit = {\n body: JSON.stringify({ value }),\n headers: {\n Authorization: `Bearer ${accessToken}`,\n 'Content-Type': 'application/json',\n },\n method: 'PUT',\n };\n\n const url = `${ITEM_STORAGE_BASE_URL}/7/users/${personId}/keys/emojis`;\n\n const response = await fetch(url, requestInit);\n\n if (response.status === 201) {\n try {\n const data = (await response.json()) as PutEmojiHistoryResponseData;\n\n return { data: data.value, status: 200 };\n } catch (e) {\n // Do nothing\n }\n }\n\n return { status: response.status };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,kBAAA,GAAAC,OAAA;AAiBO,MAAMC,eAAe,GAAG,MAAAC,IAAA,IAI0C;EAAA,IAJnC;IAClCC,WAAW;IACXC,QAAQ;IACRC;EACoB,CAAC,GAAAH,IAAA;EACrB,MAAMI,WAAwB,GAAG;IAC7BC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAAC;MAAEJ;IAAM,CAAC,CAAC;IAC/BK,OAAO,EAAE;MACLC,aAAa,EAAG,UAASR,WAAY,EAAC;MACtC,cAAc,EAAE;IACpB,CAAC;IACDS,MAAM,EAAE;EACZ,CAAC;EAED,MAAMC,GAAG,GAAI,GAAEC,wCAAsB,YAAWV,QAAS,cAAa;EAEtE,MAAMW,QAAQ,GAAG,MAAMC,KAAK,CAACH,GAAG,EAAEP,WAAW,CAAC;EAE9C,IAAIS,QAAQ,CAACE,MAAM,KAAK,GAAG,EAAE;IACzB,IAAI;MACA,MAAMC,IAAI,GAAI,MAAMH,QAAQ,CAACI,IAAI,EAAkC;MAEnE,OAAO;QAAED,IAAI,EAAEA,IAAI,CAACb,KAAK;QAAEY,MAAM,EAAE;MAAI,CAAC;IAC5C,CAAC,CAAC,OAAOG,CAAC,EAAE;MACR;IAAA;EAER;EAEA,OAAO;IAAEH,MAAM,EAAEF,QAAQ,CAACE;EAAO,CAAC;AACtC,CAAC;AAACI,OAAA,CAAApB,eAAA,GAAAA,eAAA"}
@@ -1,49 +0,0 @@
1
- import { ChangeEventHandler, FC, KeyboardEventHandler, ReactNode } from 'react';
2
- import type { PopupAlignment } from '../../constants/alignment';
3
- export type EmojiInputProps = {
4
- /**
5
- * Access token of the logged-in user. Is needed to load and save the history of the emojis.
6
- */
7
- accessToken?: string;
8
- /**
9
- * Disables the input so that it cannot be changed anymore
10
- */
11
- isDisabled?: boolean;
12
- /**
13
- * Function that is executed when the text of the input changes
14
- */
15
- onInput?: ChangeEventHandler<HTMLDivElement>;
16
- /**
17
- * Function that is executed when a key is pressed down.
18
- */
19
- onKeyDown?: KeyboardEventHandler<HTMLDivElement>;
20
- /**
21
- * Function that is executed when the visibility of the popup changes.
22
- * @param {boolean} isVisible - Whether the popup is visible or not
23
- */
24
- onPopupVisibilityChange?: (isVisible: boolean) => void;
25
- /**
26
- * Person id of the logged-in user. Is needed to load and save the history of the emojis.
27
- */
28
- personId?: string;
29
- /**
30
- * Placeholder for the input field
31
- */
32
- placeholder?: string;
33
- /**
34
- * Sets the alignment of the popup to a fixed value. If this value is not set, the component
35
- * calculates the best position on its own. Use the imported 'PopupAlignment' enum to set this
36
- * value.
37
- */
38
- popupAlignment?: PopupAlignment;
39
- /**
40
- * Element that is rendered inside the EmojiInput on the right side.
41
- */
42
- rightElement?: ReactNode;
43
- /**
44
- * Value of the input field
45
- */
46
- value: string;
47
- };
48
- declare const EmojiInput: FC<EmojiInputProps>;
49
- export default EmojiInput;
@@ -1,168 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _emoji = require("../../utils/emoji");
9
- var _environment = require("../../utils/environment");
10
- var _font = require("../../utils/font");
11
- var _selection = require("../../utils/selection");
12
- var _EmojiPickerPopup = _interopRequireDefault(require("../emoji-picker-popup/EmojiPickerPopup"));
13
- var _EmojiInput = require("./EmojiInput.styles");
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- const EmojiInput = _ref => {
18
- let {
19
- accessToken,
20
- isDisabled,
21
- onInput,
22
- onKeyDown,
23
- onPopupVisibilityChange,
24
- personId,
25
- placeholder,
26
- popupAlignment,
27
- rightElement,
28
- value
29
- } = _ref;
30
- const [isMobile] = (0, _react.useState)((0, _environment.getIsMobile)());
31
- const [rootFontFamily] = (0, _react.useState)((0, _font.getRootFontFamily)());
32
- const editorRef = (0, _react.useRef)(null);
33
-
34
- /**
35
- * This function updates the content of the 'contentEditable' element if the new text is
36
- * different from the previous content. So this is only true if, for example, a text like ":-)"
37
- * has been replaced to the corresponding emoji.
38
- *
39
- * When updating the HTML, the current cursor position is saved before replacing the content, so
40
- * that it can be set again afterward.
41
- */
42
- const handleUpdateText = (0, _react.useCallback)(text => {
43
- if (!editorRef.current) {
44
- return;
45
- }
46
- const newInnerText = (0, _emoji.convertAsciiToUnicode)(text);
47
- if (newInnerText !== editorRef.current.innerText) {
48
- (0, _selection.saveSelection)(editorRef.current);
49
- editorRef.current.innerText = newInnerText;
50
- (0, _selection.restoreSelection)(editorRef.current);
51
- }
52
- }, []);
53
-
54
- /**
55
- * This function handles the 'input' events of the 'contentEditable' element and also passes the
56
- * respective event up accordingly if the 'onInput' property is a function.
57
- */
58
- const handleInput = (0, _react.useCallback)(event => {
59
- if (!editorRef.current) {
60
- return;
61
- }
62
- handleUpdateText(editorRef.current.innerText);
63
- if (typeof onInput === 'function') {
64
- onInput(event);
65
- }
66
- }, [handleUpdateText, onInput]);
67
-
68
- /**
69
- * This function processes the selection of an emoji via the popup. If the 'contentEditable'
70
- * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji
71
- * will be appended to the back of the input field content.
72
- *
73
- * In addition, this function also sets the cursor to the correct position when the input field
74
- * has the focus. For this purpose, the current position of the cursor or a selection is read to
75
- * calculate the cursor position after inserting the emoji.
76
- *
77
- * At the end an 'input' event is dispatched, so that the function 'handleInput' is triggered,
78
- * which in turn executes the 'onInput' function from the props. So this serves to ensure that
79
- * the event is also passed through to the top when inserting via the popup.
80
- */
81
- const handlePopupSelect = (0, _react.useCallback)(emoji => {
82
- if (!editorRef.current) {
83
- return;
84
- }
85
- const selection = window.getSelection();
86
- if (selection !== null && selection !== void 0 && selection.anchorNode && editorRef.current.contains(selection.anchorNode)) {
87
- const {
88
- endOffset,
89
- startOffset
90
- } = selection.getRangeAt(0);
91
- const rangeDistance = endOffset - startOffset;
92
- let offset = endOffset + emoji.length - rangeDistance;
93
- let {
94
- anchorNode
95
- } = selection;
96
- if (anchorNode.nodeValue) {
97
- anchorNode.nodeValue = anchorNode.nodeValue.substring(0, startOffset) + emoji + anchorNode.nodeValue.substring(endOffset);
98
- } else if (anchorNode === editorRef.current) {
99
- const newTextNode = document.createTextNode(emoji);
100
- editorRef.current.appendChild(newTextNode);
101
- anchorNode = newTextNode;
102
- }
103
- const newRange = document.createRange();
104
- if (anchorNode.nodeValue) {
105
- offset = Math.min(offset, anchorNode.nodeValue.length);
106
- }
107
- newRange.setStart(anchorNode, offset);
108
- newRange.setEnd(anchorNode, offset);
109
- selection.removeAllRanges();
110
- selection.addRange(newRange);
111
- } else {
112
- editorRef.current.innerText += emoji;
113
- }
114
- const event = new Event('input', {
115
- bubbles: true
116
- });
117
- editorRef.current.dispatchEvent(event);
118
- }, []);
119
-
120
- /**
121
- * This function ensures that the input field does not lose focus when the popup is opened or an
122
- * emoji is selected in it. For this purpose the corresponding elements get the class
123
- * 'prevent-lose-focus'.
124
- *
125
- * The class can also be set to any other elements that should also not cause the input field to
126
- * lose focus.
127
- */
128
- const handlePreventLoseFocus = (0, _react.useCallback)(event => {
129
- var _element$parentElemen;
130
- const element = event.target;
131
- if (element.classList.contains('prevent-lose-focus') || (_element$parentElemen = element.parentElement) !== null && _element$parentElemen !== void 0 && _element$parentElemen.classList.contains('prevent-lose-focus')) {
132
- event.preventDefault();
133
- event.stopPropagation();
134
- }
135
- }, []);
136
- (0, _react.useEffect)(() => {
137
- handleUpdateText(value);
138
- }, [handleUpdateText, value]);
139
- (0, _react.useEffect)(() => {
140
- document.body.addEventListener('mousedown', handlePreventLoseFocus);
141
- return () => {
142
- document.body.removeEventListener('mousedown', handlePreventLoseFocus);
143
- };
144
- }, [handlePreventLoseFocus]);
145
- return /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInput, {
146
- isDisabled: isDisabled
147
- }, /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputContent, {
148
- isRightElementGiven: !!rightElement
149
- }, /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputEditor, {
150
- contentEditable: !isDisabled,
151
- isMobile: isMobile,
152
- onInput: handleInput,
153
- onKeyDown: onKeyDown,
154
- placeholder: placeholder,
155
- ref: editorRef,
156
- rootFontFamily: rootFontFamily
157
- }), !isMobile && /*#__PURE__*/_react.default.createElement(_EmojiPickerPopup.default, {
158
- accessToken: accessToken,
159
- alignment: popupAlignment,
160
- onSelect: handlePopupSelect,
161
- onPopupVisibilityChange: onPopupVisibilityChange,
162
- personId: personId
163
- })), rightElement && /*#__PURE__*/_react.default.createElement(_EmojiInput.StyledEmojiInputRightWrapper, null, rightElement));
164
- };
165
- EmojiInput.displayName = 'EmojiInput';
166
- var _default = EmojiInput;
167
- exports.default = _default;
168
- //# sourceMappingURL=EmojiInput.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmojiInput.js","names":["_react","_interopRequireWildcard","require","_emoji","_environment","_font","_selection","_EmojiPickerPopup","_interopRequireDefault","_EmojiInput","obj","__esModule","default","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","EmojiInput","_ref","accessToken","isDisabled","onInput","onKeyDown","onPopupVisibilityChange","personId","placeholder","popupAlignment","rightElement","value","isMobile","useState","getIsMobile","rootFontFamily","getRootFontFamily","editorRef","useRef","handleUpdateText","useCallback","text","current","newInnerText","convertAsciiToUnicode","innerText","saveSelection","restoreSelection","handleInput","event","handlePopupSelect","emoji","selection","window","getSelection","anchorNode","contains","endOffset","startOffset","getRangeAt","rangeDistance","offset","length","nodeValue","substring","newTextNode","document","createTextNode","appendChild","newRange","createRange","Math","min","setStart","setEnd","removeAllRanges","addRange","Event","bubbles","dispatchEvent","handlePreventLoseFocus","_element$parentElemen","element","target","classList","parentElement","preventDefault","stopPropagation","useEffect","body","addEventListener","removeEventListener","createElement","StyledEmojiInput","StyledEmojiInputContent","isRightElementGiven","StyledEmojiInputEditor","contentEditable","ref","alignment","onSelect","StyledEmojiInputRightWrapper","displayName","_default","exports"],"sources":["../../../src/components/emoji-input/EmojiInput.tsx"],"sourcesContent":["import React, {\n ChangeEvent,\n ChangeEventHandler,\n FC,\n KeyboardEventHandler,\n ReactNode,\n useCallback,\n useEffect,\n useRef,\n useState,\n} from 'react';\nimport type { PopupAlignment } from '../../constants/alignment';\nimport { convertAsciiToUnicode } from '../../utils/emoji';\nimport { getIsMobile } from '../../utils/environment';\nimport { getRootFontFamily } from '../../utils/font';\nimport { restoreSelection, saveSelection } from '../../utils/selection';\nimport EmojiPickerPopup from '../emoji-picker-popup/EmojiPickerPopup';\nimport {\n StyledEmojiInput,\n StyledEmojiInputContent,\n StyledEmojiInputEditor,\n StyledEmojiInputRightWrapper,\n} from './EmojiInput.styles';\n\nexport type EmojiInputProps = {\n /**\n * Access token of the logged-in user. Is needed to load and save the history of the emojis.\n */\n accessToken?: string;\n /**\n * Disables the input so that it cannot be changed anymore\n */\n isDisabled?: boolean;\n /**\n * Function that is executed when the text of the input changes\n */\n onInput?: ChangeEventHandler<HTMLDivElement>;\n /**\n * Function that is executed when a key is pressed down.\n */\n onKeyDown?: KeyboardEventHandler<HTMLDivElement>;\n /**\n * Function that is executed when the visibility of the popup changes.\n * @param {boolean} isVisible - Whether the popup is visible or not\n */\n onPopupVisibilityChange?: (isVisible: boolean) => void;\n /**\n * Person id of the logged-in user. Is needed to load and save the history of the emojis.\n */\n personId?: string;\n /**\n * Placeholder for the input field\n */\n placeholder?: string;\n /**\n * Sets the alignment of the popup to a fixed value. If this value is not set, the component\n * calculates the best position on its own. Use the imported 'PopupAlignment' enum to set this\n * value.\n */\n popupAlignment?: PopupAlignment;\n /**\n * Element that is rendered inside the EmojiInput on the right side.\n */\n rightElement?: ReactNode;\n /**\n * Value of the input field\n */\n value: string;\n};\n\nconst EmojiInput: FC<EmojiInputProps> = ({\n accessToken,\n isDisabled,\n onInput,\n onKeyDown,\n onPopupVisibilityChange,\n personId,\n placeholder,\n popupAlignment,\n rightElement,\n value,\n}) => {\n const [isMobile] = useState(getIsMobile());\n const [rootFontFamily] = useState(getRootFontFamily());\n\n const editorRef = useRef<HTMLDivElement>(null);\n\n /**\n * This function updates the content of the 'contentEditable' element if the new text is\n * different from the previous content. So this is only true if, for example, a text like \":-)\"\n * has been replaced to the corresponding emoji.\n *\n * When updating the HTML, the current cursor position is saved before replacing the content, so\n * that it can be set again afterward.\n */\n const handleUpdateText = useCallback((text: string) => {\n if (!editorRef.current) {\n return;\n }\n\n const newInnerText = convertAsciiToUnicode(text);\n\n if (newInnerText !== editorRef.current.innerText) {\n saveSelection(editorRef.current);\n\n editorRef.current.innerText = newInnerText;\n\n restoreSelection(editorRef.current);\n }\n }, []);\n\n /**\n * This function handles the 'input' events of the 'contentEditable' element and also passes the\n * respective event up accordingly if the 'onInput' property is a function.\n */\n const handleInput = useCallback(\n (event: ChangeEvent<HTMLDivElement>) => {\n if (!editorRef.current) {\n return;\n }\n\n handleUpdateText(editorRef.current.innerText);\n\n if (typeof onInput === 'function') {\n onInput(event);\n }\n },\n [handleUpdateText, onInput]\n );\n\n /**\n * This function processes the selection of an emoji via the popup. If the 'contentEditable'\n * element has the focus, the new emoji is inserted at the cursor position. If not, the emoji\n * will be appended to the back of the input field content.\n *\n * In addition, this function also sets the cursor to the correct position when the input field\n * has the focus. For this purpose, the current position of the cursor or a selection is read to\n * calculate the cursor position after inserting the emoji.\n *\n * At the end an 'input' event is dispatched, so that the function 'handleInput' is triggered,\n * which in turn executes the 'onInput' function from the props. So this serves to ensure that\n * the event is also passed through to the top when inserting via the popup.\n */\n const handlePopupSelect = useCallback((emoji: string) => {\n if (!editorRef.current) {\n return;\n }\n\n const selection = window.getSelection();\n\n if (selection?.anchorNode && editorRef.current.contains(selection.anchorNode)) {\n const { endOffset, startOffset } = selection.getRangeAt(0);\n\n const rangeDistance = endOffset - startOffset;\n\n let offset = endOffset + emoji.length - rangeDistance;\n\n let { anchorNode } = selection;\n\n if (anchorNode.nodeValue) {\n anchorNode.nodeValue =\n anchorNode.nodeValue.substring(0, startOffset) +\n emoji +\n anchorNode.nodeValue.substring(endOffset);\n } else if (anchorNode === editorRef.current) {\n const newTextNode = document.createTextNode(emoji);\n\n editorRef.current.appendChild(newTextNode);\n\n anchorNode = newTextNode;\n }\n\n const newRange = document.createRange();\n\n if (anchorNode.nodeValue) {\n offset = Math.min(offset, anchorNode.nodeValue.length);\n }\n\n newRange.setStart(anchorNode, offset);\n newRange.setEnd(anchorNode, offset);\n\n selection.removeAllRanges();\n selection.addRange(newRange);\n } else {\n editorRef.current.innerText += emoji;\n }\n\n const event = new Event('input', { bubbles: true });\n\n editorRef.current.dispatchEvent(event);\n }, []);\n\n /**\n * This function ensures that the input field does not lose focus when the popup is opened or an\n * emoji is selected in it. For this purpose the corresponding elements get the class\n * 'prevent-lose-focus'.\n *\n * The class can also be set to any other elements that should also not cause the input field to\n * lose focus.\n */\n const handlePreventLoseFocus = useCallback((event: MouseEvent) => {\n const element = event.target as Element;\n\n if (\n element.classList.contains('prevent-lose-focus') ||\n element.parentElement?.classList.contains('prevent-lose-focus')\n ) {\n event.preventDefault();\n event.stopPropagation();\n }\n }, []);\n\n useEffect(() => {\n handleUpdateText(value);\n }, [handleUpdateText, value]);\n\n useEffect(() => {\n document.body.addEventListener('mousedown', handlePreventLoseFocus);\n\n return () => {\n document.body.removeEventListener('mousedown', handlePreventLoseFocus);\n };\n }, [handlePreventLoseFocus]);\n\n return (\n <StyledEmojiInput isDisabled={isDisabled}>\n <StyledEmojiInputContent isRightElementGiven={!!rightElement}>\n <StyledEmojiInputEditor\n contentEditable={!isDisabled}\n isMobile={isMobile}\n onInput={handleInput}\n onKeyDown={onKeyDown}\n placeholder={placeholder}\n ref={editorRef}\n rootFontFamily={rootFontFamily}\n />\n {!isMobile && (\n <EmojiPickerPopup\n accessToken={accessToken}\n alignment={popupAlignment}\n onSelect={handlePopupSelect}\n onPopupVisibilityChange={onPopupVisibilityChange}\n personId={personId}\n />\n )}\n </StyledEmojiInputContent>\n {rightElement && (\n <StyledEmojiInputRightWrapper>{rightElement}</StyledEmojiInputRightWrapper>\n )}\n </StyledEmojiInput>\n );\n};\n\nEmojiInput.displayName = 'Emoj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Y,CAC9C,CACc;AAE3B,CAAC;AAEDV,UAAU,CAACkF,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAEvBnF,UAAU;AAAAoF,OAAA,CAAAxG,OAAA,GAAAuG,QAAA"}
@@ -1,16 +0,0 @@
1
- import type { EmojiInputProps } from './EmojiInput';
2
- export declare const StyledEmojiInput: import("styled-components").StyledComponent<"div", any, Pick<EmojiInputProps, "isDisabled"> & {
3
- theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
4
- }, never>;
5
- type StyledEmojiInputContentProps = {
6
- isRightElementGiven: boolean;
7
- };
8
- export declare const StyledEmojiInputContent: import("styled-components").StyledComponent<"div", any, StyledEmojiInputContentProps, never>;
9
- export declare const StyledEmojiInputEditor: import("styled-components").StyledComponent<"div", any, Pick<EmojiInputProps, "placeholder"> & {
10
- theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
11
- } & {
12
- isMobile: boolean;
13
- rootFontFamily: string;
14
- }, never>;
15
- export declare const StyledEmojiInputRightWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
16
- export {};