emoji-picker-react 4.3.0 → 4.4.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/config.d.ts +2 -0
- package/dist/config/useConfig.d.ts +2 -0
- package/dist/emoji-picker-react.cjs.development.js +24 -4
- package/dist/emoji-picker-react.cjs.development.js.map +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js +1 -1
- package/dist/emoji-picker-react.cjs.production.min.js.map +1 -1
- package/dist/emoji-picker-react.esm.js +24 -4
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/dist/predicates/isFunction.d.ts +1 -0
- package/package.json +1 -1
- package/src/config/config.ts +3 -0
- package/src/config/useConfig.ts +8 -0
- package/src/hooks/useDisallowedEmojis.ts +17 -4
- package/src/hooks/useFilter.ts +10 -9
- package/src/predicates/isFunction.ts +5 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function isFunction(value: any): value is (...args: any[]) => any;
|
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GetEmojiUrl } from '../components/emoji/Emoji';
|
|
2
|
+
import { DataEmoji } from '../dataUtils/DataTypes';
|
|
2
3
|
import { emojiUrlByUnified } from '../dataUtils/emojiSelectors';
|
|
3
4
|
import {
|
|
4
5
|
EmojiClickData,
|
|
@@ -58,6 +59,7 @@ export function basePickerConfig(): PickerConfigInternal {
|
|
|
58
59
|
...basePreviewConfig
|
|
59
60
|
},
|
|
60
61
|
searchPlaceHolder: 'Search',
|
|
62
|
+
showEmoji: undefined,
|
|
61
63
|
skinTonesDisabled: false,
|
|
62
64
|
suggestedEmojisMode: SuggestionMode.FREQUENT,
|
|
63
65
|
theme: Theme.LIGHT,
|
|
@@ -81,6 +83,7 @@ export type PickerConfigInternal = {
|
|
|
81
83
|
height: PickerDimensions;
|
|
82
84
|
width: PickerDimensions;
|
|
83
85
|
getEmojiUrl: GetEmojiUrl;
|
|
86
|
+
showEmoji: undefined | ((emoji: DataEmoji) => boolean);
|
|
84
87
|
};
|
|
85
88
|
|
|
86
89
|
export type PreviewConfig = {
|
package/src/config/useConfig.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isSystemDarkTheme } from '../DomUtils/isDarkTheme';
|
|
2
2
|
import { usePickerConfig } from '../components/context/PickerConfigContext';
|
|
3
|
+
import { DataEmoji } from '../dataUtils/DataTypes';
|
|
3
4
|
import {
|
|
4
5
|
EmojiClickData,
|
|
5
6
|
EmojiStyle,
|
|
@@ -95,6 +96,13 @@ export function useGetEmojiUrlConfig(): (
|
|
|
95
96
|
return getEmojiUrl;
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
export function useShowEmojiConfig():
|
|
100
|
+
| undefined
|
|
101
|
+
| ((emoji: DataEmoji) => boolean) {
|
|
102
|
+
const { showEmoji } = usePickerConfig();
|
|
103
|
+
return showEmoji;
|
|
104
|
+
}
|
|
105
|
+
|
|
98
106
|
function getDimension(dimensionConfig: PickerDimensions): PickerDimensions {
|
|
99
107
|
return typeof dimensionConfig === 'number'
|
|
100
108
|
? `${dimensionConfig}px`
|
|
@@ -1,28 +1,41 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
2
|
|
|
3
|
-
import { useEmojiVersionConfig } from '../config/useConfig';
|
|
3
|
+
import { useEmojiVersionConfig, useShowEmojiConfig } from '../config/useConfig';
|
|
4
4
|
import { DataEmoji } from '../dataUtils/DataTypes';
|
|
5
5
|
import { addedIn, allEmojis, emojiUnified } from '../dataUtils/emojiSelectors';
|
|
6
|
+
import isFunction from '../predicates/isFunction';
|
|
6
7
|
|
|
7
8
|
export function useDisallowedEmojis() {
|
|
8
9
|
const DisallowedEmojisRef = useRef<Record<string, boolean>>({});
|
|
9
10
|
const emojiVersionConfig = useEmojiVersionConfig();
|
|
11
|
+
const shouldShowEmoji = useShowEmojiConfig();
|
|
10
12
|
|
|
11
13
|
return useMemo(() => {
|
|
12
14
|
const emojiVersion = parseFloat(`${emojiVersionConfig}`);
|
|
13
15
|
|
|
14
|
-
if (
|
|
16
|
+
if (
|
|
17
|
+
(!emojiVersionConfig || Number.isNaN(emojiVersion)) &&
|
|
18
|
+
!shouldShowEmoji
|
|
19
|
+
) {
|
|
15
20
|
return DisallowedEmojisRef.current;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
return allEmojis.reduce((disallowedEmojis, emoji) => {
|
|
24
|
+
if (isFunction(shouldShowEmoji) && !shouldShowEmoji(emoji)) {
|
|
25
|
+
disallowEmoji();
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
if (addedInNewerVersion(emoji, emojiVersion)) {
|
|
20
|
-
|
|
29
|
+
disallowEmoji();
|
|
21
30
|
}
|
|
22
31
|
|
|
23
32
|
return disallowedEmojis;
|
|
33
|
+
|
|
34
|
+
function disallowEmoji() {
|
|
35
|
+
disallowedEmojis[emojiUnified(emoji)] = true;
|
|
36
|
+
}
|
|
24
37
|
}, DisallowedEmojisRef.current);
|
|
25
|
-
}, [emojiVersionConfig]);
|
|
38
|
+
}, [emojiVersionConfig, shouldShowEmoji]);
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
function addedInNewerVersion(
|
package/src/hooks/useFilter.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { scrollTo } from '../DomUtils/scrollTo';
|
|
2
2
|
import {
|
|
3
3
|
usePickerMainRef,
|
|
4
|
-
useSearchInputRef
|
|
4
|
+
useSearchInputRef
|
|
5
5
|
} from '../components/context/ElementRefContext';
|
|
6
6
|
import {
|
|
7
7
|
FilterState,
|
|
8
8
|
useFilterRef,
|
|
9
|
-
useSearchTermState
|
|
9
|
+
useSearchTermState
|
|
10
10
|
} from '../components/context/PickerContext';
|
|
11
11
|
import { DataEmoji } from '../dataUtils/DataTypes';
|
|
12
12
|
import { emojiNames } from '../dataUtils/emojiSelectors';
|
|
13
|
+
import isFunction from '../predicates/isFunction';
|
|
13
14
|
|
|
14
15
|
import { useFocusSearchInput } from './useFocus';
|
|
15
16
|
|
|
@@ -19,7 +20,7 @@ function useSetFilterRef() {
|
|
|
19
20
|
return function setFilter(
|
|
20
21
|
setter: FilterState | ((current: FilterState) => FilterState)
|
|
21
22
|
): void {
|
|
22
|
-
if (
|
|
23
|
+
if (isFunction(setter)) {
|
|
23
24
|
return setFilter(setter(filterRef.current));
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -67,7 +68,7 @@ export function useFilter() {
|
|
|
67
68
|
return {
|
|
68
69
|
onChange,
|
|
69
70
|
searchTerm,
|
|
70
|
-
SearchInputRef
|
|
71
|
+
SearchInputRef
|
|
71
72
|
};
|
|
72
73
|
|
|
73
74
|
function onChange(inputValue: string) {
|
|
@@ -87,9 +88,9 @@ export function useFilter() {
|
|
|
87
88
|
return applySearch(nextValue);
|
|
88
89
|
}
|
|
89
90
|
|
|
90
|
-
setFilterRef(
|
|
91
|
+
setFilterRef(current =>
|
|
91
92
|
Object.assign(current, {
|
|
92
|
-
[nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue)
|
|
93
|
+
[nextValue]: filterEmojiObjectByKeyword(longestMatch, nextValue)
|
|
93
94
|
})
|
|
94
95
|
);
|
|
95
96
|
applySearch(nextValue);
|
|
@@ -129,14 +130,14 @@ function filterEmojiObjectByKeyword(
|
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
function hasMatch(emoji: DataEmoji, keyword: string): boolean {
|
|
132
|
-
return emojiNames(emoji).some(
|
|
133
|
+
return emojiNames(emoji).some(name => name.includes(keyword));
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
export function useIsEmojiFiltered(): (unified: string) => boolean {
|
|
136
137
|
const { current: filter } = useFilterRef();
|
|
137
138
|
const [searchTerm] = useSearchTermState();
|
|
138
139
|
|
|
139
|
-
return
|
|
140
|
+
return unified => isEmojiFilteredBySearchTerm(unified, filter, searchTerm);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
function isEmojiFilteredBySearchTerm(
|
|
@@ -167,7 +168,7 @@ function findLongestMatch(
|
|
|
167
168
|
|
|
168
169
|
const longestMatchingKey = Object.keys(dict)
|
|
169
170
|
.sort((a, b) => b.length - a.length)
|
|
170
|
-
.find(
|
|
171
|
+
.find(key => keyword.includes(key));
|
|
171
172
|
|
|
172
173
|
if (longestMatchingKey) {
|
|
173
174
|
return dict[longestMatchingKey];
|