@chayns-components/emoji-input 5.0.0-beta.91 → 5.0.0-beta.910
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -15
- package/lib/{api → cjs/api}/item-storage/get.js +4 -5
- package/lib/cjs/api/item-storage/get.js.map +1 -0
- package/lib/{api → cjs/api}/item-storage/put.js +5 -6
- package/lib/cjs/api/item-storage/put.js.map +1 -0
- package/lib/cjs/components/emoji-input/EmojiInput.js +510 -0
- package/lib/cjs/components/emoji-input/EmojiInput.js.map +1 -0
- package/lib/cjs/components/emoji-input/EmojiInput.styles.js +132 -0
- package/lib/cjs/components/emoji-input/EmojiInput.styles.js.map +1 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js +45 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js +65 -0
- package/lib/cjs/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.js +9 -11
- package/lib/cjs/components/emoji-picker/EmojiPicker.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/EmojiPicker.styles.js +3 -5
- package/lib/cjs/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +102 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +5 -6
- package/lib/cjs/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +69 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
- package/lib/{components → cjs/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +49 -21
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +24 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +130 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +99 -0
- package/lib/cjs/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js +52 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js +15 -0
- package/lib/cjs/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
- package/lib/{constants → cjs/constants}/alignment.js +6 -8
- package/lib/cjs/constants/alignment.js.map +1 -0
- package/lib/{constants → cjs/constants}/categories.js +1 -2
- package/lib/cjs/constants/categories.js.map +1 -0
- package/lib/cjs/constants/emoji.js +3804 -0
- package/lib/cjs/constants/emoji.js.map +1 -0
- package/lib/cjs/constants/externalServerUrl.js +8 -0
- package/lib/cjs/constants/externalServerUrl.js.map +1 -0
- package/lib/cjs/constants/regex.js +15 -0
- package/lib/cjs/constants/regex.js.map +1 -0
- package/lib/{hooks → cjs/hooks}/emojiHistory.js +13 -15
- package/lib/cjs/hooks/emojiHistory.js.map +1 -0
- package/lib/{index.js → cjs/index.js} +3 -3
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/api.js +2 -0
- package/lib/cjs/types/api.js.map +1 -0
- package/lib/cjs/types/category.js +2 -0
- package/lib/cjs/types/category.js.map +1 -0
- package/lib/cjs/utils/emoji.js +104 -0
- package/lib/cjs/utils/emoji.js.map +1 -0
- package/lib/{utils → cjs/utils}/environment.js +6 -4
- package/lib/cjs/utils/environment.js.map +1 -0
- package/lib/cjs/utils/font.js +17 -0
- package/lib/cjs/utils/font.js.map +1 -0
- package/lib/cjs/utils/insert.js +110 -0
- package/lib/cjs/utils/insert.js.map +1 -0
- package/lib/cjs/utils/number.js +17 -0
- package/lib/cjs/utils/number.js.map +1 -0
- package/lib/cjs/utils/selection.js +255 -0
- package/lib/cjs/utils/selection.js.map +1 -0
- package/lib/cjs/utils/text.js +57 -0
- package/lib/cjs/utils/text.js.map +1 -0
- package/lib/esm/api/item-storage/get.js +30 -0
- package/lib/esm/api/item-storage/get.js.map +1 -0
- package/lib/esm/api/item-storage/put.js +35 -0
- package/lib/esm/api/item-storage/put.js.map +1 -0
- package/lib/esm/components/emoji-input/EmojiInput.js +497 -0
- package/lib/esm/components/emoji-input/EmojiInput.js.map +1 -0
- package/lib/esm/components/emoji-input/EmojiInput.styles.js +151 -0
- package/lib/esm/components/emoji-input/EmojiInput.styles.js.map +1 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js +38 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.js.map +1 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js +69 -0
- package/lib/esm/components/emoji-input/prefix-element/PrefixElement.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.js +40 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.js.map +1 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.styles.js +16 -0
- package/lib/esm/components/emoji-picker/EmojiPicker.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +96 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js +18 -0
- package/lib/esm/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +240 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +76 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js +136 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +20 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +121 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +1 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +98 -0
- package/lib/esm/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +1 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js +43 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.js.map +1 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js +8 -0
- package/lib/esm/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +1 -0
- package/lib/esm/constants/alignment.js +13 -0
- package/lib/esm/constants/alignment.js.map +1 -0
- package/lib/esm/constants/categories.js +13 -0
- package/lib/esm/constants/categories.js.map +1 -0
- package/lib/esm/constants/emoji-de-DE.json +3827 -0
- package/lib/esm/constants/emoji.js +3798 -0
- package/lib/esm/constants/emoji.js.map +1 -0
- package/lib/esm/constants/externalServerUrl.js +2 -0
- package/lib/esm/constants/externalServerUrl.js.map +1 -0
- package/lib/esm/constants/regex.js +9 -0
- package/lib/esm/constants/regex.js.map +1 -0
- package/lib/esm/hooks/emojiHistory.js +83 -0
- package/lib/esm/hooks/emojiHistory.js.map +1 -0
- package/lib/{index.d.ts → esm/index.js} +2 -1
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/api.js +2 -0
- package/lib/esm/types/api.js.map +1 -0
- package/lib/esm/types/category.js +2 -0
- package/lib/esm/types/category.js.map +1 -0
- package/lib/esm/utils/emoji.js +92 -0
- package/lib/esm/utils/emoji.js.map +1 -0
- package/lib/esm/utils/environment.js +24 -0
- package/lib/esm/utils/environment.js.map +1 -0
- package/lib/esm/utils/font.js +10 -0
- package/lib/esm/utils/font.js.map +1 -0
- package/lib/esm/utils/insert.js +104 -0
- package/lib/esm/utils/insert.js.map +1 -0
- package/lib/esm/utils/number.js +10 -0
- package/lib/esm/utils/number.js.map +1 -0
- package/lib/esm/utils/selection.js +237 -0
- package/lib/esm/utils/selection.js.map +1 -0
- package/lib/esm/utils/text.js +48 -0
- package/lib/esm/utils/text.js.map +1 -0
- package/lib/types/components/emoji-input/EmojiInput.d.ts +94 -0
- package/lib/types/components/emoji-input/EmojiInput.styles.d.ts +549 -0
- package/lib/types/components/emoji-input/prefix-element/PrefixElement.d.ts +8 -0
- package/lib/types/components/emoji-input/prefix-element/PrefixElement.styles.d.ts +12 -0
- package/lib/types/components/emoji-picker/EmojiPicker.styles.d.ts +5 -0
- package/lib/types/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +267 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +10 -0
- package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/Emoji.d.ts +5 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +6 -0
- package/lib/types/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +283 -0
- package/lib/{components → types/components}/emoji-picker-popup/EmojiPickerPopup.d.ts +0 -13
- package/lib/types/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +1 -0
- package/lib/types/constants/emoji.d.ts +8 -0
- package/lib/types/constants/regex.d.ts +8 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/utils/emoji.d.ts +4 -0
- package/lib/{utils → types/utils}/environment.d.ts +1 -0
- package/lib/types/utils/font.d.ts +1 -0
- package/lib/{utils → types/utils}/insert.d.ts +8 -1
- package/lib/types/utils/number.d.ts +1 -0
- package/lib/types/utils/selection.d.ts +23 -0
- package/lib/types/utils/text.d.ts +3 -0
- package/package.json +48 -30
- package/lib/api/item-storage/get.js.map +0 -1
- package/lib/api/item-storage/put.js.map +0 -1
- package/lib/components/emoji-input/EmojiInput.d.ts +0 -49
- package/lib/components/emoji-input/EmojiInput.js +0 -156
- package/lib/components/emoji-input/EmojiInput.js.map +0 -1
- package/lib/components/emoji-input/EmojiInput.styles.d.ts +0 -16
- package/lib/components/emoji-input/EmojiInput.styles.js +0 -153
- package/lib/components/emoji-input/EmojiInput.styles.js.map +0 -1
- package/lib/components/emoji-picker/EmojiPicker.js.map +0 -1
- package/lib/components/emoji-picker/EmojiPicker.styles.d.ts +0 -5
- package/lib/components/emoji-picker/EmojiPicker.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js +0 -51
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.d.ts +0 -2
- package/lib/components/emoji-picker/emoji-picker-categories/EmojiPickerCategories.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js +0 -131
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.d.ts +0 -7
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js +0 -99
- package/lib/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.d.ts +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js +0 -20
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js +0 -74
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.js.map +0 -1
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.d.ts +0 -11
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js +0 -104
- package/lib/components/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.styles.js.map +0 -1
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.js +0 -150
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.js.map +0 -1
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.d.ts +0 -7
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js +0 -97
- package/lib/components/emoji-picker-popup/EmojiPickerPopup.styles.js.map +0 -1
- package/lib/constants/alignment.js.map +0 -1
- package/lib/constants/categories.js.map +0 -1
- package/lib/constants/externalServerUrl.js +0 -9
- package/lib/constants/externalServerUrl.js.map +0 -1
- package/lib/hooks/emojiHistory.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/api.js +0 -6
- package/lib/types/api.js.map +0 -1
- package/lib/types/category.js +0 -6
- package/lib/types/category.js.map +0 -1
- package/lib/utils/emoji.d.ts +0 -2
- package/lib/utils/emoji.js +0 -205
- package/lib/utils/emoji.js.map +0 -1
- package/lib/utils/environment.js.map +0 -1
- package/lib/utils/font.d.ts +0 -1
- package/lib/utils/font.js +0 -15
- package/lib/utils/font.js.map +0 -1
- package/lib/utils/insert.js +0 -57
- package/lib/utils/insert.js.map +0 -1
- package/lib/utils/selection.d.ts +0 -2
- package/lib/utils/selection.js +0 -43
- package/lib/utils/selection.js.map +0 -1
- /package/lib/{constants → cjs/constants}/emoji-de-DE.json +0 -0
- /package/lib/{api → types/api}/item-storage/get.d.ts +0 -0
- /package/lib/{api → types/api}/item-storage/put.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/EmojiPicker.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-categories/EmojiPickerCategories.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.d.ts +0 -0
- /package/lib/{components → types/components}/emoji-picker/emoji-picker-emojis/emoji/skin-tone-popup/SkinTonePopup.d.ts +0 -0
- /package/lib/{constants → types/constants}/alignment.d.ts +0 -0
- /package/lib/{constants → types/constants}/categories.d.ts +0 -0
- /package/lib/{constants → types/constants}/externalServerUrl.d.ts +0 -0
- /package/lib/{hooks → types/hooks}/emojiHistory.d.ts +0 -0
- /package/lib/types/{api.d.ts → types/api.d.ts} +0 -0
- /package/lib/types/{category.d.ts → types/category.d.ts} +0 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { getDevice } from 'chayns-api';
|
|
2
|
+
import emojiLib from 'emojilib';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
+
import emojiList from 'unicode-emoji-json/data-by-emoji.json';
|
|
5
|
+
import emojiCategories from 'unicode-emoji-json/data-by-group.json';
|
|
6
|
+
import germanEmojiLib from '../../../constants/emoji-de-DE.json';
|
|
7
|
+
import { useEmojiHistory } from '../../../hooks/emojiHistory';
|
|
8
|
+
import Emoji from './emoji/Emoji';
|
|
9
|
+
import { StyledEmojiPickerEmojis, StyledEmojiPickerEmojisNoContentInfo } from './EmojiPickerEmojis.styles';
|
|
10
|
+
const EmojiPickerEmojis = _ref => {
|
|
11
|
+
let {
|
|
12
|
+
accessToken,
|
|
13
|
+
onSelect,
|
|
14
|
+
personId,
|
|
15
|
+
searchString,
|
|
16
|
+
selectedCategory
|
|
17
|
+
} = _ref;
|
|
18
|
+
const [shouldPreventScroll, setShouldPreventScroll] = useState(false);
|
|
19
|
+
const [shouldShowSkinTonePopup, setShouldShowSkinTonePopup] = useState(false);
|
|
20
|
+
const [focusedIndex, setFocusedIndex] = useState(0);
|
|
21
|
+
const emojiRef = useRef(null);
|
|
22
|
+
const shouldPreventEmojiControlsRef = useRef(false);
|
|
23
|
+
const {
|
|
24
|
+
browser
|
|
25
|
+
} = getDevice();
|
|
26
|
+
const {
|
|
27
|
+
addOrUpdateEmojiInHistory,
|
|
28
|
+
historyEmojis
|
|
29
|
+
} = useEmojiHistory({
|
|
30
|
+
accessToken,
|
|
31
|
+
personId,
|
|
32
|
+
selectedCategory
|
|
33
|
+
});
|
|
34
|
+
const handlePopupVisibilityChange = useCallback(isVisible => {
|
|
35
|
+
setShouldShowSkinTonePopup(isVisible);
|
|
36
|
+
shouldPreventEmojiControlsRef.current = isVisible;
|
|
37
|
+
setShouldPreventScroll(isVisible);
|
|
38
|
+
}, []);
|
|
39
|
+
const handleSelect = useCallback(_ref2 => {
|
|
40
|
+
let {
|
|
41
|
+
emoji,
|
|
42
|
+
name,
|
|
43
|
+
skin_tone_support,
|
|
44
|
+
index
|
|
45
|
+
} = _ref2;
|
|
46
|
+
onSelect(emoji);
|
|
47
|
+
if (index) {
|
|
48
|
+
setFocusedIndex(index);
|
|
49
|
+
}
|
|
50
|
+
void addOrUpdateEmojiInHistory({
|
|
51
|
+
emoji,
|
|
52
|
+
name,
|
|
53
|
+
skin_tone_support
|
|
54
|
+
});
|
|
55
|
+
}, [addOrUpdateEmojiInHistory, onSelect]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (selectedCategory) {
|
|
58
|
+
setFocusedIndex(0);
|
|
59
|
+
const container = emojiRef.current;
|
|
60
|
+
if (!container) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
container.scrollTop = 0;
|
|
64
|
+
}
|
|
65
|
+
}, [selectedCategory]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const handleKeyDown = event => {
|
|
68
|
+
if (!shouldPreventEmojiControlsRef.current && (event.key === 'ArrowUp' || event.key === 'ArrowDown' || event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
|
|
69
|
+
event.preventDefault();
|
|
70
|
+
const children = emojiRef.current?.children;
|
|
71
|
+
if (children && children.length > 0) {
|
|
72
|
+
const container = emojiRef.current;
|
|
73
|
+
let newIndex = focusedIndex !== null ? focusedIndex : 0;
|
|
74
|
+
if (event.ctrlKey) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (event.key === 'ArrowUp') {
|
|
78
|
+
newIndex = (newIndex - 6) % children.length;
|
|
79
|
+
} else if (event.key === 'ArrowDown') {
|
|
80
|
+
newIndex = (newIndex + 6) % children.length;
|
|
81
|
+
} else if (event.key === 'ArrowLeft') {
|
|
82
|
+
newIndex = (newIndex - 1) % children.length;
|
|
83
|
+
} else if (event.key === 'ArrowRight') {
|
|
84
|
+
newIndex = (newIndex + 1) % children.length;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// remove focus from the old element
|
|
88
|
+
if (focusedIndex !== null) {
|
|
89
|
+
const prevElement = children[focusedIndex];
|
|
90
|
+
prevElement.tabIndex = -1;
|
|
91
|
+
}
|
|
92
|
+
if (newIndex < 0) {
|
|
93
|
+
newIndex = children.length - 1;
|
|
94
|
+
} else if (newIndex > children.length - 1) {
|
|
95
|
+
newIndex = 0;
|
|
96
|
+
}
|
|
97
|
+
setFocusedIndex(newIndex);
|
|
98
|
+
|
|
99
|
+
// Set focus to the element
|
|
100
|
+
const newElement = children[newIndex];
|
|
101
|
+
newElement.tabIndex = 0;
|
|
102
|
+
const containerRect = container.getBoundingClientRect();
|
|
103
|
+
const elementRect = newElement.getBoundingClientRect();
|
|
104
|
+
if (elementRect.bottom > containerRect.bottom) {
|
|
105
|
+
container.scrollTop += elementRect.bottom - containerRect.bottom;
|
|
106
|
+
} else if (elementRect.top < containerRect.top) {
|
|
107
|
+
container.scrollTop -= containerRect.top - elementRect.top;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} else if (event.key === 'Enter' && !shouldPreventEmojiControlsRef.current && focusedIndex !== null) {
|
|
111
|
+
if (event.ctrlKey) {
|
|
112
|
+
setShouldShowSkinTonePopup(true);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const {
|
|
116
|
+
dataset
|
|
117
|
+
} = emojiRef.current?.children[focusedIndex];
|
|
118
|
+
const {
|
|
119
|
+
emoji,
|
|
120
|
+
name,
|
|
121
|
+
skinToneSupport
|
|
122
|
+
} = dataset;
|
|
123
|
+
if (!emoji || !name || !skinToneSupport) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
handleSelect({
|
|
127
|
+
emoji,
|
|
128
|
+
name,
|
|
129
|
+
skin_tone_support: skinToneSupport === 'true'
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
134
|
+
return () => {
|
|
135
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
136
|
+
};
|
|
137
|
+
}, [focusedIndex, handleSelect]);
|
|
138
|
+
const handleRightClick = useCallback(index => {
|
|
139
|
+
setFocusedIndex(index);
|
|
140
|
+
}, []);
|
|
141
|
+
const emojis = useMemo(() => {
|
|
142
|
+
if (searchString.trim() !== '') {
|
|
143
|
+
const lowerSearchString = searchString.toLowerCase();
|
|
144
|
+
const searchResults = [];
|
|
145
|
+
Object.entries(emojiList).forEach((_ref3, index) => {
|
|
146
|
+
let [emoji, {
|
|
147
|
+
name,
|
|
148
|
+
skin_tone_support
|
|
149
|
+
}] = _ref3;
|
|
150
|
+
const keywords = emojiLib[emoji];
|
|
151
|
+
const germanKeywords = germanEmojiLib[emoji];
|
|
152
|
+
if (name.includes(lowerSearchString) || keywords?.some(keyword => keyword.includes(lowerSearchString)) || germanKeywords?.some(keyword => keyword.includes(lowerSearchString))) {
|
|
153
|
+
searchResults.push(/*#__PURE__*/React.createElement(Emoji, {
|
|
154
|
+
shouldShowSkinTonePopup: index === focusedIndex && skin_tone_support && shouldShowSkinTonePopup,
|
|
155
|
+
isSelected: index === focusedIndex,
|
|
156
|
+
emoji: emoji,
|
|
157
|
+
index: index,
|
|
158
|
+
onRightClick: handleRightClick,
|
|
159
|
+
isSkinToneSupported: skin_tone_support,
|
|
160
|
+
key: name,
|
|
161
|
+
name: name,
|
|
162
|
+
onPopupVisibilityChange: handlePopupVisibilityChange,
|
|
163
|
+
onSelect: e => handleSelect({
|
|
164
|
+
emoji: e,
|
|
165
|
+
name,
|
|
166
|
+
skin_tone_support,
|
|
167
|
+
index
|
|
168
|
+
})
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
return searchResults;
|
|
173
|
+
}
|
|
174
|
+
if (selectedCategory === 'history') {
|
|
175
|
+
return historyEmojis.map((_ref4, index) => {
|
|
176
|
+
let {
|
|
177
|
+
emoji,
|
|
178
|
+
name,
|
|
179
|
+
skin_tone_support
|
|
180
|
+
} = _ref4;
|
|
181
|
+
return /*#__PURE__*/React.createElement(Emoji, {
|
|
182
|
+
isSelected: index === focusedIndex,
|
|
183
|
+
shouldShowSkinTonePopup: index === focusedIndex && skin_tone_support && shouldShowSkinTonePopup,
|
|
184
|
+
emoji: emoji,
|
|
185
|
+
name: name,
|
|
186
|
+
key: name,
|
|
187
|
+
index: index,
|
|
188
|
+
onRightClick: handleRightClick,
|
|
189
|
+
onPopupVisibilityChange: handlePopupVisibilityChange,
|
|
190
|
+
onSelect: e => handleSelect({
|
|
191
|
+
emoji: e,
|
|
192
|
+
name,
|
|
193
|
+
skin_tone_support,
|
|
194
|
+
index
|
|
195
|
+
}),
|
|
196
|
+
isSkinToneSupported: false
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
return emojiCategories.find(_ref5 => {
|
|
201
|
+
let {
|
|
202
|
+
slug
|
|
203
|
+
} = _ref5;
|
|
204
|
+
return slug === selectedCategory;
|
|
205
|
+
})?.emojis.map((_ref6, index) => {
|
|
206
|
+
let {
|
|
207
|
+
emoji,
|
|
208
|
+
name,
|
|
209
|
+
skin_tone_support
|
|
210
|
+
} = _ref6;
|
|
211
|
+
return /*#__PURE__*/React.createElement(Emoji, {
|
|
212
|
+
isSelected: index === focusedIndex,
|
|
213
|
+
shouldShowSkinTonePopup: index === focusedIndex && skin_tone_support && shouldShowSkinTonePopup,
|
|
214
|
+
emoji: emoji,
|
|
215
|
+
name: name,
|
|
216
|
+
index: index,
|
|
217
|
+
onRightClick: handleRightClick,
|
|
218
|
+
isSkinToneSupported: skin_tone_support,
|
|
219
|
+
key: name,
|
|
220
|
+
onPopupVisibilityChange: handlePopupVisibilityChange,
|
|
221
|
+
onSelect: e => handleSelect({
|
|
222
|
+
emoji: e,
|
|
223
|
+
name,
|
|
224
|
+
skin_tone_support,
|
|
225
|
+
index
|
|
226
|
+
})
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
}, [searchString, selectedCategory, focusedIndex, shouldShowSkinTonePopup, handleRightClick, handlePopupVisibilityChange, handleSelect, historyEmojis]);
|
|
230
|
+
const shouldShowNoContentInfo = !emojis || emojis.length === 0;
|
|
231
|
+
return /*#__PURE__*/React.createElement(StyledEmojiPickerEmojis, {
|
|
232
|
+
$browser: browser?.name,
|
|
233
|
+
$shouldPreventScroll: shouldPreventScroll,
|
|
234
|
+
$shouldShowNoContentInfo: shouldShowNoContentInfo,
|
|
235
|
+
ref: emojiRef
|
|
236
|
+
}, emojis, shouldShowNoContentInfo && /*#__PURE__*/React.createElement(StyledEmojiPickerEmojisNoContentInfo, null, "Hier werden die zuletzt verwendeten Emojis angezeigt, die \xFCber diese Auswahl gew\xE4hlt wurden."));
|
|
237
|
+
};
|
|
238
|
+
EmojiPickerEmojis.displayName = 'EmojiPickerEmojis';
|
|
239
|
+
export default EmojiPickerEmojis;
|
|
240
|
+
//# sourceMappingURL=EmojiPickerEmojis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmojiPickerEmojis.js","names":["getDevice","emojiLib","React","useCallback","useEffect","useMemo","useRef","useState","emojiList","emojiCategories","germanEmojiLib","useEmojiHistory","Emoji","StyledEmojiPickerEmojis","StyledEmojiPickerEmojisNoContentInfo","EmojiPickerEmojis","_ref","accessToken","onSelect","personId","searchString","selectedCategory","shouldPreventScroll","setShouldPreventScroll","shouldShowSkinTonePopup","setShouldShowSkinTonePopup","focusedIndex","setFocusedIndex","emojiRef","shouldPreventEmojiControlsRef","browser","addOrUpdateEmojiInHistory","historyEmojis","handlePopupVisibilityChange","isVisible","current","handleSelect","_ref2","emoji","name","skin_tone_support","index","container","scrollTop","handleKeyDown","event","key","preventDefault","children","length","newIndex","ctrlKey","prevElement","tabIndex","newElement","containerRect","getBoundingClientRect","elementRect","bottom","top","dataset","skinToneSupport","document","addEventListener","removeEventListener","handleRightClick","emojis","trim","lowerSearchString","toLowerCase","searchResults","Object","entries","forEach","_ref3","keywords","germanKeywords","includes","some","keyword","push","createElement","isSelected","onRightClick","isSkinToneSupported","onPopupVisibilityChange","e","map","_ref4","find","_ref5","slug","_ref6","shouldShowNoContentInfo","$browser","$shouldPreventScroll","$shouldShowNoContentInfo","ref","displayName"],"sources":["../../../../../src/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.tsx"],"sourcesContent":["import { getDevice } from 'chayns-api';\nimport emojiLib from 'emojilib';\nimport React, { FC, useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport emojiList from 'unicode-emoji-json/data-by-emoji.json';\nimport emojiCategories from 'unicode-emoji-json/data-by-group.json';\nimport germanEmojiLib from '../../../constants/emoji-de-DE.json';\nimport { useEmojiHistory } from '../../../hooks/emojiHistory';\nimport type { Category } from '../../../types/category';\nimport Emoji from './emoji/Emoji';\nimport {\n StyledEmojiPickerEmojis,\n StyledEmojiPickerEmojisNoContentInfo,\n} from './EmojiPickerEmojis.styles';\n\nexport type EmojiPickerEmojisProps = {\n accessToken?: string;\n onSelect: (emoji: string) => void;\n personId?: string;\n searchString: string;\n selectedCategory: Category;\n};\n\nconst EmojiPickerEmojis: FC<EmojiPickerEmojisProps> = ({\n accessToken,\n onSelect,\n personId,\n searchString,\n selectedCategory,\n}) => {\n const [shouldPreventScroll, setShouldPreventScroll] = useState(false);\n const [shouldShowSkinTonePopup, setShouldShowSkinTonePopup] = useState(false);\n const [focusedIndex, setFocusedIndex] = useState<number>(0);\n\n const emojiRef = useRef<HTMLDivElement>(null);\n const shouldPreventEmojiControlsRef = useRef(false);\n\n const { browser } = getDevice();\n\n const { addOrUpdateEmojiInHistory, historyEmojis } = useEmojiHistory({\n accessToken,\n personId,\n selectedCategory,\n });\n\n const handlePopupVisibilityChange = useCallback((isVisible: boolean) => {\n setShouldShowSkinTonePopup(isVisible);\n shouldPreventEmojiControlsRef.current = isVisible;\n setShouldPreventScroll(isVisible);\n }, []);\n\n const handleSelect = useCallback(\n ({\n emoji,\n name,\n skin_tone_support,\n index,\n }: {\n emoji: string;\n name: string;\n skin_tone_support: boolean;\n index?: number;\n }) => {\n onSelect(emoji);\n\n if (index) {\n setFocusedIndex(index);\n }\n\n void addOrUpdateEmojiInHistory({ emoji, name, skin_tone_support });\n },\n [addOrUpdateEmojiInHistory, onSelect],\n );\n\n useEffect(() => {\n if (selectedCategory) {\n setFocusedIndex(0);\n\n const container = emojiRef.current;\n\n if (!container) {\n return;\n }\n\n container.scrollTop = 0;\n }\n }, [selectedCategory]);\n\n useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (\n !shouldPreventEmojiControlsRef.current &&\n (event.key === 'ArrowUp' ||\n event.key === 'ArrowDown' ||\n event.key === 'ArrowLeft' ||\n event.key === 'ArrowRight')\n ) {\n event.preventDefault();\n const children = emojiRef.current?.children;\n if (children && children.length > 0) {\n const container = emojiRef.current;\n let newIndex = focusedIndex !== null ? focusedIndex : 0;\n\n if (event.ctrlKey) {\n return;\n }\n\n if (event.key === 'ArrowUp') {\n newIndex = (newIndex - 6) % children.length;\n } else if (event.key === 'ArrowDown') {\n newIndex = (newIndex + 6) % children.length;\n } else if (event.key === 'ArrowLeft') {\n newIndex = (newIndex - 1) % children.length;\n } else if (event.key === 'ArrowRight') {\n newIndex = (newIndex + 1) % children.length;\n }\n\n // remove focus from the old element\n if (focusedIndex !== null) {\n const prevElement = children[focusedIndex] as HTMLDivElement;\n prevElement.tabIndex = -1;\n }\n\n if (newIndex < 0) {\n newIndex = children.length - 1;\n } else if (newIndex > children.length - 1) {\n newIndex = 0;\n }\n\n setFocusedIndex(newIndex);\n\n // Set focus to the element\n const newElement = children[newIndex] as HTMLDivElement;\n newElement.tabIndex = 0;\n\n const containerRect = container.getBoundingClientRect();\n const elementRect = newElement.getBoundingClientRect();\n\n if (elementRect.bottom > containerRect.bottom) {\n container.scrollTop += elementRect.bottom - containerRect.bottom;\n } else if (elementRect.top < containerRect.top) {\n container.scrollTop -= containerRect.top - elementRect.top;\n }\n }\n } else if (\n event.key === 'Enter' &&\n !shouldPreventEmojiControlsRef.current &&\n focusedIndex !== null\n ) {\n if (event.ctrlKey) {\n setShouldShowSkinTonePopup(true);\n\n return;\n }\n\n const { dataset } = emojiRef.current?.children[focusedIndex] as HTMLDivElement;\n\n const { emoji, name, skinToneSupport } = dataset;\n\n if (!emoji || !name || !skinToneSupport) {\n return;\n }\n\n handleSelect({ emoji, name, skin_tone_support: skinToneSupport === 'true' });\n }\n };\n\n document.addEventListener('keydown', handleKeyDown);\n\n return () => {\n document.removeEventListener('keydown', handleKeyDown);\n };\n }, [focusedIndex, handleSelect]);\n\n const handleRightClick = useCallback((index: number) => {\n setFocusedIndex(index);\n }, []);\n\n const emojis = useMemo(() => {\n if (searchString.trim() !== '') {\n const lowerSearchString = searchString.toLowerCase();\n\n const searchResults: JSX.Element[] = [];\n\n Object.entries(emojiList).forEach(([emoji, { name, skin_tone_support }], index) => {\n const keywords = (emojiLib as { [key: string]: string[] })[emoji] as\n | string[]\n | undefined;\n\n const germanKeywords = (germanEmojiLib as { [key: string]: string[] })[emoji] as\n | string[]\n | undefined;\n\n if (\n name.includes(lowerSearchString) ||\n keywords?.some((keyword) => keyword.includes(lowerSearchString)) ||\n germanKeywords?.some((keyword) => keyword.includes(lowerSearchString))\n ) {\n searchResults.push(\n <Emoji\n shouldShowSkinTonePopup={\n index === focusedIndex &&\n skin_tone_support &&\n shouldShowSkinTonePopup\n }\n isSelected={index === focusedIndex}\n emoji={emoji}\n index={index}\n onRightClick={handleRightClick}\n isSkinToneSupported={skin_tone_support}\n key={name}\n name={name}\n onPopupVisibilityChange={handlePopupVisibilityChange}\n onSelect={(e) =>\n handleSelect({ emoji: e, name, skin_tone_support, index })\n }\n />,\n );\n }\n });\n\n return searchResults;\n }\n\n if (selectedCategory === 'history') {\n return historyEmojis.map(({ emoji, name, skin_tone_support }, index) => (\n <Emoji\n isSelected={index === focusedIndex}\n shouldShowSkinTonePopup={\n index === focusedIndex && skin_tone_support && shouldShowSkinTonePopup\n }\n emoji={emoji}\n name={name}\n key={name}\n index={index}\n onRightClick={handleRightClick}\n onPopupVisibilityChange={handlePopupVisibilityChange}\n onSelect={(e) => handleSelect({ emoji: e, name, skin_tone_support, index })}\n isSkinToneSupported={false}\n />\n ));\n }\n\n return emojiCategories\n .find(({ slug }) => slug === selectedCategory)\n ?.emojis.map(({ emoji, name, skin_tone_support }, index) => (\n <Emoji\n isSelected={index === focusedIndex}\n shouldShowSkinTonePopup={\n index === focusedIndex && skin_tone_support && shouldShowSkinTonePopup\n }\n emoji={emoji}\n name={name}\n index={index}\n onRightClick={handleRightClick}\n isSkinToneSupported={skin_tone_support}\n key={name}\n onPopupVisibilityChange={handlePopupVisibilityChange}\n onSelect={(e) => handleSelect({ emoji: e, name, skin_tone_support, index })}\n />\n ));\n }, [\n searchString,\n selectedCategory,\n focusedIndex,\n shouldShowSkinTonePopup,\n handleRightClick,\n handlePopupVisibilityChange,\n handleSelect,\n historyEmojis,\n ]);\n\n const shouldShowNoContentInfo = !emojis || emojis.length === 0;\n\n return (\n <StyledEmojiPickerEmojis\n $browser={browser?.name}\n $shouldPreventScroll={shouldPreventScroll}\n $shouldShowNoContentInfo={shouldShowNoContentInfo}\n ref={emojiRef}\n >\n {emojis}\n {shouldShowNoContentInfo && (\n <StyledEmojiPickerEmojisNoContentInfo>\n Hier werden die zuletzt verwendeten Emojis angezeigt, die über diese Auswahl\n gewählt wurden.\n </StyledEmojiPickerEmojisNoContentInfo>\n )}\n </StyledEmojiPickerEmojis>\n );\n};\n\nEmojiPickerEmojis.displayName = 'EmojiPickerEmojis';\n\nexport default EmojiPickerEmojis;\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,YAAY;AACtC,OAAOC,QAAQ,MAAM,UAAU;AAC/B,OAAOC,KAAK,IAAQC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACpF,OAAOC,SAAS,MAAM,uCAAuC;AAC7D,OAAOC,eAAe,MAAM,uCAAuC;AACnE,OAAOC,cAAc,MAAM,qCAAqC;AAChE,SAASC,eAAe,QAAQ,6BAA6B;AAE7D,OAAOC,KAAK,MAAM,eAAe;AACjC,SACIC,uBAAuB,EACvBC,oCAAoC,QACjC,4BAA4B;AAUnC,MAAMC,iBAA6C,GAAGC,IAAA,IAMhD;EAAA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aAAa,CAChB,CAAC;EAEF,MAAM6D,uBAAuB,GAAG,CAAC3B,MAAM,IAAIA,MAAM,CAACjB,MAAM,KAAK,CAAC;EAE9D,oBACI/C,KAAA,CAAA+E,aAAA,CAACpE,uBAAuB;IACpBiF,QAAQ,EAAEhE,OAAO,EAAES,IAAK;IACxBwD,oBAAoB,EAAEzE,mBAAoB;IAC1C0E,wBAAwB,EAAEH,uBAAwB;IAClDI,GAAG,EAAErE;EAAS,GAEbsC,MAAM,EACN2B,uBAAuB,iBACpB3F,KAAA,CAAA+E,aAAA,CAACnE,oCAAoC,QAAC,oGAGA,CAErB,CAAC;AAElC,CAAC;AAEDC,iBAAiB,CAACmF,WAAW,GAAG,mBAAmB;AAEnD,eAAenF,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
|
+
export const StyledEmojiPickerEmojis = styled.div`
|
|
3
|
+
display: ${_ref => {
|
|
4
|
+
let {
|
|
5
|
+
$shouldShowNoContentInfo
|
|
6
|
+
} = _ref;
|
|
7
|
+
return $shouldShowNoContentInfo ? 'flex' : 'grid';
|
|
8
|
+
}};
|
|
9
|
+
flex: 1 1 auto;
|
|
10
|
+
grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
|
|
11
|
+
grid-template-rows: min-content;
|
|
12
|
+
overflow-y: ${_ref2 => {
|
|
13
|
+
let {
|
|
14
|
+
$shouldPreventScroll
|
|
15
|
+
} = _ref2;
|
|
16
|
+
return $shouldPreventScroll ? 'hidden' : 'scroll';
|
|
17
|
+
}};
|
|
18
|
+
padding: 5px 0 5px 5px;
|
|
19
|
+
position: relative;
|
|
20
|
+
width: 100%;
|
|
21
|
+
|
|
22
|
+
${_ref3 => {
|
|
23
|
+
let {
|
|
24
|
+
$shouldShowNoContentInfo
|
|
25
|
+
} = _ref3;
|
|
26
|
+
return $shouldShowNoContentInfo && css`
|
|
27
|
+
align-items: center;
|
|
28
|
+
`;
|
|
29
|
+
}}
|
|
30
|
+
|
|
31
|
+
${_ref4 => {
|
|
32
|
+
let {
|
|
33
|
+
$shouldPreventScroll
|
|
34
|
+
} = _ref4;
|
|
35
|
+
return $shouldPreventScroll && css`
|
|
36
|
+
padding-right: 5px;
|
|
37
|
+
`;
|
|
38
|
+
}}
|
|
39
|
+
|
|
40
|
+
// Styles for custom scrollbar
|
|
41
|
+
${_ref5 => {
|
|
42
|
+
let {
|
|
43
|
+
$browser,
|
|
44
|
+
theme
|
|
45
|
+
} = _ref5;
|
|
46
|
+
return $browser === 'firefox' ? css`
|
|
47
|
+
scrollbar-color: rgba(${theme['text-rgb']}, 0.15) transparent;
|
|
48
|
+
scrollbar-width: thin;
|
|
49
|
+
` : css`
|
|
50
|
+
&::-webkit-scrollbar {
|
|
51
|
+
width: 5px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
&::-webkit-scrollbar-track {
|
|
55
|
+
background-color: transparent;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&::-webkit-scrollbar-button {
|
|
59
|
+
background-color: transparent;
|
|
60
|
+
height: 5px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&::-webkit-scrollbar-thumb {
|
|
64
|
+
background-color: rgba(${theme['text-rgb']}, 0.15);
|
|
65
|
+
border-radius: 20px;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
}}
|
|
69
|
+
`;
|
|
70
|
+
export const StyledEmojiPickerEmojisNoContentInfo = styled.div`
|
|
71
|
+
font-size: 85%;
|
|
72
|
+
opacity: 0.85;
|
|
73
|
+
padding: 0 12.5%;
|
|
74
|
+
text-align: center;
|
|
75
|
+
`;
|
|
76
|
+
//# sourceMappingURL=EmojiPickerEmojis.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EmojiPickerEmojis.styles.js","names":["styled","css","StyledEmojiPickerEmojis","div","_ref","$shouldShowNoContentInfo","_ref2","$shouldPreventScroll","_ref3","_ref4","_ref5","$browser","theme","StyledEmojiPickerEmojisNoContentInfo"],"sources":["../../../../../src/components/emoji-picker/emoji-picker-emojis/EmojiPickerEmojis.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport type { Browser } from 'detect-browser';\nimport styled, { css } from 'styled-components';\n\ntype StyledEmojiPickerEmojisProps = WithTheme<{\n $shouldPreventScroll: boolean;\n $shouldShowNoContentInfo: boolean;\n $browser: Browser | 'bot' | null | undefined;\n}>;\n\nexport const StyledEmojiPickerEmojis = styled.div<StyledEmojiPickerEmojisProps>`\n display: ${({ $shouldShowNoContentInfo }) => ($shouldShowNoContentInfo ? 'flex' : 'grid')};\n flex: 1 1 auto;\n grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));\n grid-template-rows: min-content;\n overflow-y: ${({ $shouldPreventScroll }) => ($shouldPreventScroll ? 'hidden' : 'scroll')};\n padding: 5px 0 5px 5px;\n position: relative;\n width: 100%;\n\n ${({ $shouldShowNoContentInfo }) =>\n $shouldShowNoContentInfo &&\n css`\n align-items: center;\n `}\n\n ${({ $shouldPreventScroll }) =>\n $shouldPreventScroll &&\n css`\n padding-right: 5px;\n `}\n\n // Styles for custom scrollbar\n ${({ $browser, theme }: StyledEmojiPickerEmojisProps) =>\n $browser === 'firefox'\n ? css`\n scrollbar-color: rgba(${theme['text-rgb']}, 0.15) transparent;\n scrollbar-width: thin;\n `\n : css`\n &::-webkit-scrollbar {\n width: 5px;\n }\n\n &::-webkit-scrollbar-track {\n background-color: transparent;\n }\n\n &::-webkit-scrollbar-button {\n background-color: transparent;\n height: 5px;\n }\n\n &::-webkit-scrollbar-thumb {\n background-color: rgba(${theme['text-rgb']}, 0.15);\n border-radius: 20px;\n }\n `}\n`;\n\nexport const StyledEmojiPickerEmojisNoContentInfo = styled.div`\n font-size: 85%;\n opacity: 0.85;\n padding: 0 12.5%;\n text-align: center;\n`;\n"],"mappings":"AAEA,OAAOA,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAQ/C,OAAO,MAAMC,uBAAuB,GAAGF,MAAM,CAACG,GAAiC;AAC/E,eAAeC,IAAA;EAAA,IAAC;IAAEC;EAAyB,CAAC,GAAAD,IAAA;EAAA,OAAMC,wBAAwB,GAAG,MAAM,GAAG,MAAM;AAAA,CAAC;AAC7F;AACA;AACA;AACA,kBAAkBC,KAAA;EAAA,IAAC;IAAEC;EAAqB,CAAC,GAAAD,KAAA;EAAA,OAAMC,oBAAoB,GAAG,QAAQ,GAAG,QAAQ;AAAA,CAAC;AAC5F;AACA;AACA;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAEH;EAAyB,CAAC,GAAAG,KAAA;EAAA,OAC3BH,wBAAwB,IACxBJ,GAAG;AACX;AACA,SAAS;AAAA;AACT;AACA,MAAMQ,KAAA;EAAA,IAAC;IAAEF;EAAqB,CAAC,GAAAE,KAAA;EAAA,OACvBF,oBAAoB,IACpBN,GAAG;AACX;AACA,SAAS;AAAA;AACT;AACA;AACA,MAAMS,KAAA;EAAA,IAAC;IAAEC,QAAQ;IAAEC;EAAoC,CAAC,GAAAF,KAAA;EAAA,OAChDC,QAAQ,KAAK,SAAS,GAChBV,GAAG;AACjB,0CAA0CW,KAAK,CAAC,UAAU,CAAC;AAC3D;AACA,eAAe,GACDX,GAAG;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,+CAA+CW,KAAK,CAAC,UAAU,CAAC;AAChE;AACA;AACA,eAAe;AAAA;AACf,CAAC;AAED,OAAO,MAAMC,oCAAoC,GAAGb,MAAM,CAACG,GAAG;AAC9D;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { AnimatePresence } from 'framer-motion';
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { AnchorAlignment } from '../../../../constants/alignment';
|
|
4
|
+
import { StyledEmoji } from './Emoji.styles';
|
|
5
|
+
import SkinTonePopup from './skin-tone-popup/SkinTonePopup';
|
|
6
|
+
import { skinTonePopupContentSize } from './skin-tone-popup/SkinTonePopup.styles';
|
|
7
|
+
const Emoji = _ref => {
|
|
8
|
+
let {
|
|
9
|
+
emoji,
|
|
10
|
+
isSelected,
|
|
11
|
+
name,
|
|
12
|
+
isSkinToneSupported,
|
|
13
|
+
onPopupVisibilityChange,
|
|
14
|
+
onSelect,
|
|
15
|
+
shouldShowSkinTonePopup,
|
|
16
|
+
onRightClick,
|
|
17
|
+
index
|
|
18
|
+
} = _ref;
|
|
19
|
+
const [shouldShowPopup, setShouldShowPopup] = useState(false);
|
|
20
|
+
const [skinTonePopupAnchorAlignment, setSkinTonePopupAnchorAlignment] = useState(AnchorAlignment.Top);
|
|
21
|
+
const [skinTonePopupAnchorOffset, setSkinTonePopupAnchorOffset] = useState(0);
|
|
22
|
+
const [skinTonePopupOverlayPosition, setSkinTonePopupOverlayPosition] = useState({
|
|
23
|
+
top: 0
|
|
24
|
+
});
|
|
25
|
+
const [skinTonePopupPosition, setSkinTonePopupPosition] = useState({
|
|
26
|
+
left: 0,
|
|
27
|
+
top: 0
|
|
28
|
+
});
|
|
29
|
+
const emojiRef = useRef(null);
|
|
30
|
+
const handleClick = useCallback(() => {
|
|
31
|
+
onSelect(emoji);
|
|
32
|
+
}, [emoji, onSelect]);
|
|
33
|
+
const calculatePopupPosition = useCallback(() => {
|
|
34
|
+
if (!emojiRef.current) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const element = emojiRef.current;
|
|
38
|
+
const {
|
|
39
|
+
parentElement
|
|
40
|
+
} = emojiRef.current;
|
|
41
|
+
if (parentElement) {
|
|
42
|
+
const {
|
|
43
|
+
height: elementHeight,
|
|
44
|
+
left: elementLeft,
|
|
45
|
+
top: elementTop,
|
|
46
|
+
width: elementWidth
|
|
47
|
+
} = element.getBoundingClientRect();
|
|
48
|
+
const {
|
|
49
|
+
height: parentHeight,
|
|
50
|
+
left: parentLeft,
|
|
51
|
+
top: parentTop,
|
|
52
|
+
width: parentWidth
|
|
53
|
+
} = parentElement.getBoundingClientRect();
|
|
54
|
+
const {
|
|
55
|
+
scrollTop
|
|
56
|
+
} = parentElement;
|
|
57
|
+
let anchorAlignment = AnchorAlignment.Top;
|
|
58
|
+
let anchorOffset = 0;
|
|
59
|
+
let left = elementLeft - parentLeft - skinTonePopupContentSize.width / 2 + elementWidth / 2;
|
|
60
|
+
let top = elementTop - parentTop + elementHeight + scrollTop;
|
|
61
|
+
const maxLeft = parentWidth - skinTonePopupContentSize.width - 12;
|
|
62
|
+
const minLeft = 12;
|
|
63
|
+
if (left < minLeft) {
|
|
64
|
+
anchorOffset = left - minLeft;
|
|
65
|
+
left = minLeft;
|
|
66
|
+
} else if (left > maxLeft) {
|
|
67
|
+
anchorOffset = left - maxLeft;
|
|
68
|
+
left = maxLeft;
|
|
69
|
+
}
|
|
70
|
+
if (top + skinTonePopupContentSize.height > parentHeight + scrollTop) {
|
|
71
|
+
anchorAlignment = AnchorAlignment.Bottom;
|
|
72
|
+
top -= elementHeight + skinTonePopupContentSize.height;
|
|
73
|
+
}
|
|
74
|
+
if (isSkinToneSupported) {
|
|
75
|
+
setSkinTonePopupAnchorAlignment(anchorAlignment);
|
|
76
|
+
setSkinTonePopupAnchorOffset(anchorOffset);
|
|
77
|
+
setSkinTonePopupPosition({
|
|
78
|
+
left,
|
|
79
|
+
top
|
|
80
|
+
});
|
|
81
|
+
setSkinTonePopupOverlayPosition({
|
|
82
|
+
top: scrollTop
|
|
83
|
+
});
|
|
84
|
+
setShouldShowPopup(true);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}, [isSkinToneSupported]);
|
|
88
|
+
const handleContextMenu = useCallback(event => {
|
|
89
|
+
event.preventDefault();
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
if (isSkinToneSupported) {
|
|
92
|
+
onRightClick(index);
|
|
93
|
+
calculatePopupPosition();
|
|
94
|
+
}
|
|
95
|
+
}, [calculatePopupPosition, index, isSkinToneSupported, onRightClick]);
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (emojiRef.current && shouldShowSkinTonePopup && skinTonePopupPosition.top === 0 && skinTonePopupPosition.left === 0) {
|
|
98
|
+
calculatePopupPosition();
|
|
99
|
+
}
|
|
100
|
+
}, [calculatePopupPosition, index, isSkinToneSupported, shouldShowSkinTonePopup, skinTonePopupPosition]);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (shouldShowSkinTonePopup) {
|
|
103
|
+
setShouldShowPopup(shouldShowSkinTonePopup);
|
|
104
|
+
}
|
|
105
|
+
}, [shouldShowSkinTonePopup]);
|
|
106
|
+
const handleHidePopup = useCallback(() => {
|
|
107
|
+
setShouldShowPopup(false);
|
|
108
|
+
}, []);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
onPopupVisibilityChange(shouldShowPopup);
|
|
111
|
+
}, [onPopupVisibilityChange, shouldShowPopup]);
|
|
112
|
+
return /*#__PURE__*/React.createElement(StyledEmoji, {
|
|
113
|
+
ref: emojiRef,
|
|
114
|
+
$isSelected: isSelected,
|
|
115
|
+
"data-emoji": emoji,
|
|
116
|
+
"data-name": name,
|
|
117
|
+
"data-skin-tone-support": isSkinToneSupported,
|
|
118
|
+
className: "prevent-lose-focus",
|
|
119
|
+
onClick: handleClick,
|
|
120
|
+
onContextMenu: handleContextMenu
|
|
121
|
+
}, emoji, /*#__PURE__*/React.createElement(AnimatePresence, {
|
|
122
|
+
initial: false
|
|
123
|
+
}, shouldShowPopup && /*#__PURE__*/React.createElement(SkinTonePopup, {
|
|
124
|
+
anchorAlignment: skinTonePopupAnchorAlignment,
|
|
125
|
+
anchorOffset: skinTonePopupAnchorOffset,
|
|
126
|
+
emoji: emoji,
|
|
127
|
+
key: emoji,
|
|
128
|
+
onHidePopup: handleHidePopup,
|
|
129
|
+
onSelect: onSelect,
|
|
130
|
+
overlayPosition: skinTonePopupOverlayPosition,
|
|
131
|
+
position: skinTonePopupPosition
|
|
132
|
+
})));
|
|
133
|
+
};
|
|
134
|
+
Emoji.displayName = 'Emoji';
|
|
135
|
+
export default Emoji;
|
|
136
|
+
//# sourceMappingURL=Emoji.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Emoji.js","names":["AnimatePresence","React","useCallback","useEffect","useRef","useState","AnchorAlignment","StyledEmoji","SkinTonePopup","skinTonePopupContentSize","Emoji","_ref","emoji","isSelected","name","isSkinToneSupported","onPopupVisibilityChange","onSelect","shouldShowSkinTonePopup","onRightClick","index","shouldShowPopup","setShouldShowPopup","skinTonePopupAnchorAlignment","setSkinTonePopupAnchorAlignment","Top","skinTonePopupAnchorOffset","setSkinTonePopupAnchorOffset","skinTonePopupOverlayPosition","setSkinTonePopupOverlayPosition","top","skinTonePopupPosition","setSkinTonePopupPosition","left","emojiRef","handleClick","calculatePopupPosition","current","element","parentElement","height","elementHeight","elementLeft","elementTop","width","elementWidth","getBoundingClientRect","parentHeight","parentLeft","parentTop","parentWidth","scrollTop","anchorAlignment","anchorOffset","maxLeft","minLeft","Bottom","handleContextMenu","event","preventDefault","stopPropagation","handleHidePopup","createElement","ref","$isSelected","className","onClick","onContextMenu","initial","key","onHidePopup","overlayPosition","position","displayName"],"sources":["../../../../../../src/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.tsx"],"sourcesContent":["import { AnimatePresence } from 'framer-motion';\nimport React, { FC, MouseEvent, useCallback, useEffect, useRef, useState } from 'react';\nimport { AnchorAlignment } from '../../../../constants/alignment';\nimport { StyledEmoji } from './Emoji.styles';\nimport SkinTonePopup, { SkinTonePopupProps } from './skin-tone-popup/SkinTonePopup';\nimport { skinTonePopupContentSize } from './skin-tone-popup/SkinTonePopup.styles';\n\nexport type EmojiProps = {\n emoji: string;\n isSelected: boolean;\n name: string;\n index: number;\n isSkinToneSupported: boolean;\n onPopupVisibilityChange: (isVisible: boolean) => void;\n onSelect: (emoji: string) => void;\n onRightClick: (newIndex: number) => void;\n shouldShowSkinTonePopup: boolean;\n};\n\nconst Emoji: FC<EmojiProps> = ({\n emoji,\n isSelected,\n name,\n isSkinToneSupported,\n onPopupVisibilityChange,\n onSelect,\n shouldShowSkinTonePopup,\n onRightClick,\n index,\n}) => {\n const [shouldShowPopup, setShouldShowPopup] = useState(false);\n const [skinTonePopupAnchorAlignment, setSkinTonePopupAnchorAlignment] = useState(\n AnchorAlignment.Top,\n );\n const [skinTonePopupAnchorOffset, setSkinTonePopupAnchorOffset] = useState(0);\n const [skinTonePopupOverlayPosition, setSkinTonePopupOverlayPosition] = useState<\n SkinTonePopupProps['overlayPosition']\n >({ top: 0 });\n const [skinTonePopupPosition, setSkinTonePopupPosition] = useState<\n SkinTonePopupProps['position']\n >({ left: 0, top: 0 });\n\n const emojiRef = useRef<HTMLDivElement>(null);\n\n const handleClick = useCallback(() => {\n onSelect(emoji);\n }, [emoji, onSelect]);\n\n const calculatePopupPosition = useCallback(() => {\n if (!emojiRef.current) {\n return;\n }\n\n const element = emojiRef.current;\n const { parentElement } = emojiRef.current;\n\n if (parentElement) {\n const {\n height: elementHeight,\n left: elementLeft,\n top: elementTop,\n width: elementWidth,\n } = element.getBoundingClientRect();\n\n const {\n height: parentHeight,\n left: parentLeft,\n top: parentTop,\n width: parentWidth,\n } = parentElement.getBoundingClientRect();\n\n const { scrollTop } = parentElement;\n\n let anchorAlignment = AnchorAlignment.Top;\n let anchorOffset = 0;\n\n let left =\n elementLeft - parentLeft - skinTonePopupContentSize.width / 2 + elementWidth / 2;\n\n let top = elementTop - parentTop + elementHeight + scrollTop;\n\n const maxLeft = parentWidth - skinTonePopupContentSize.width - 12;\n const minLeft = 12;\n\n if (left < minLeft) {\n anchorOffset = left - minLeft;\n left = minLeft;\n } else if (left > maxLeft) {\n anchorOffset = left - maxLeft;\n left = maxLeft;\n }\n\n if (top + skinTonePopupContentSize.height > parentHeight + scrollTop) {\n anchorAlignment = AnchorAlignment.Bottom;\n top -= elementHeight + skinTonePopupContentSize.height;\n }\n\n if (isSkinToneSupported) {\n setSkinTonePopupAnchorAlignment(anchorAlignment);\n setSkinTonePopupAnchorOffset(anchorOffset);\n setSkinTonePopupPosition({ left, top });\n setSkinTonePopupOverlayPosition({ top: scrollTop });\n setShouldShowPopup(true);\n }\n }\n }, [isSkinToneSupported]);\n\n const handleContextMenu = useCallback(\n (event: MouseEvent) => {\n event.preventDefault();\n event.stopPropagation();\n\n if (isSkinToneSupported) {\n onRightClick(index);\n calculatePopupPosition();\n }\n },\n [calculatePopupPosition, index, isSkinToneSupported, onRightClick],\n );\n\n useEffect(() => {\n if (\n emojiRef.current &&\n shouldShowSkinTonePopup &&\n skinTonePopupPosition.top === 0 &&\n skinTonePopupPosition.left === 0\n ) {\n calculatePopupPosition();\n }\n }, [\n calculatePopupPosition,\n index,\n isSkinToneSupported,\n shouldShowSkinTonePopup,\n skinTonePopupPosition,\n ]);\n\n useEffect(() => {\n if (shouldShowSkinTonePopup) {\n setShouldShowPopup(shouldShowSkinTonePopup);\n }\n }, [shouldShowSkinTonePopup]);\n\n const handleHidePopup = useCallback(() => {\n setShouldShowPopup(false);\n }, []);\n\n useEffect(() => {\n onPopupVisibilityChange(shouldShowPopup);\n }, [onPopupVisibilityChange, shouldShowPopup]);\n\n return (\n <StyledEmoji\n ref={emojiRef}\n $isSelected={isSelected}\n data-emoji={emoji}\n data-name={name}\n data-skin-tone-support={isSkinToneSupported}\n className=\"prevent-lose-focus\"\n onClick={handleClick}\n onContextMenu={handleContextMenu}\n >\n {emoji}\n <AnimatePresence initial={false}>\n {shouldShowPopup && (\n <SkinTonePopup\n anchorAlignment={skinTonePopupAnchorAlignment}\n anchorOffset={skinTonePopupAnchorOffset}\n emoji={emoji}\n key={emoji}\n onHidePopup={handleHidePopup}\n onSelect={onSelect}\n overlayPosition={skinTonePopupOverlayPosition}\n position={skinTonePopupPosition}\n />\n )}\n </AnimatePresence>\n </StyledEmoji>\n );\n};\n\nEmoji.displayName = 'Emoji';\n\nexport default Emoji;\n"],"mappings":"AAA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M;IACtCoB,kBAAkB,CAAC,KAAK,CAAC;EAC7B,CAAC,EAAE,EAAE,CAAC;EAENnB,SAAS,CAAC,MAAM;IACZa,uBAAuB,CAACK,eAAe,CAAC;EAC5C,CAAC,EAAE,CAACL,uBAAuB,EAAEK,eAAe,CAAC,CAAC;EAE9C,oBACIpB,KAAA,CAAA6D,aAAA,CAACvD,WAAW;IACRwD,GAAG,EAAE7B,QAAS;IACd8B,WAAW,EAAEnD,UAAW;IACxB,cAAYD,KAAM;IAClB,aAAWE,IAAK;IAChB,0BAAwBC,mBAAoB;IAC5CkD,SAAS,EAAC,oBAAoB;IAC9BC,OAAO,EAAE/B,WAAY;IACrBgC,aAAa,EAAEV;EAAkB,GAEhC7C,KAAK,eACNX,KAAA,CAAA6D,aAAA,CAAC9D,eAAe;IAACoE,OAAO,EAAE;EAAM,GAC3B/C,eAAe,iBACZpB,KAAA,CAAA6D,aAAA,CAACtD,aAAa;IACV4C,eAAe,EAAE7B,4BAA6B;IAC9C8B,YAAY,EAAE3B,yBAA0B;IACxCd,KAAK,EAAEA,KAAM;IACbyD,GAAG,EAAEzD,KAAM;IACX0D,WAAW,EAAET,eAAgB;IAC7B5C,QAAQ,EAAEA,QAAS;IACnBsD,eAAe,EAAE3C,4BAA6B;IAC9C4C,QAAQ,EAAEzC;EAAsB,CACnC,CAEQ,CACR,CAAC;AAEtB,CAAC;AAEDrB,KAAK,CAAC+D,WAAW,GAAG,OAAO;AAE3B,eAAe/D,KAAK","ignoreList":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
import { getFontFamily } from '../../../../utils/font';
|
|
3
|
+
export const StyledEmoji = styled.div`
|
|
4
|
+
align-items: center;
|
|
5
|
+
cursor: pointer;
|
|
6
|
+
display: flex;
|
|
7
|
+
font-family: ${getFontFamily};
|
|
8
|
+
font-size: 32px;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
width: 48px;
|
|
11
|
+
height: 48px;
|
|
12
|
+
background-color: ${_ref => {
|
|
13
|
+
let {
|
|
14
|
+
theme,
|
|
15
|
+
$isSelected
|
|
16
|
+
} = _ref;
|
|
17
|
+
return $isSelected ? theme['secondary-102'] : 'none';
|
|
18
|
+
}};
|
|
19
|
+
`;
|
|
20
|
+
//# sourceMappingURL=Emoji.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Emoji.styles.js","names":["styled","getFontFamily","StyledEmoji","div","_ref","theme","$isSelected"],"sources":["../../../../../../src/components/emoji-picker/emoji-picker-emojis/emoji/Emoji.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled from 'styled-components';\nimport { getFontFamily } from '../../../../utils/font';\n\ntype StyledEmojiProps = WithTheme<{\n $isSelected: boolean;\n}>;\n\nexport const StyledEmoji = styled.div<StyledEmojiProps>`\n align-items: center;\n cursor: pointer;\n display: flex;\n font-family: ${getFontFamily};\n font-size: 32px;\n justify-content: center;\n width: 48px;\n height: 48px;\n background-color: ${({ theme, $isSelected }: StyledEmojiProps) =>\n $isSelected ? theme['secondary-102'] : 'none'};\n`;\n"],"mappings":"AACA,OAAOA,MAAM,MAAM,mBAAmB;AACtC,SAASC,aAAa,QAAQ,wBAAwB;AAMtD,OAAO,MAAMC,WAAW,GAAGF,MAAM,CAACG,GAAqB;AACvD;AACA;AACA;AACA,mBAAmBF,aAAa;AAChC;AACA;AACA;AACA;AACA,wBAAwBG,IAAA;EAAA,IAAC;IAAEC,KAAK;IAAEC;EAA8B,CAAC,GAAAF,IAAA;EAAA,OACzDE,WAAW,GAAGD,KAAK,CAAC,eAAe,CAAC,GAAG,MAAM;AAAA;AACrD,CAAC","ignoreList":[]}
|