emoji-picker-react 4.0.8 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -4
- package/dist/components/context/PickerContext.d.ts +1 -0
- package/dist/config/config.d.ts +1 -0
- package/dist/config/useConfig.d.ts +1 -0
- package/dist/dataUtils/DataTypes.d.ts +1 -0
- package/dist/dataUtils/emojiSelectors.d.ts +1 -0
- package/dist/emoji-picker-react.cjs.development.js +3758 -1855
- 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 +3759 -1856
- package/dist/emoji-picker-react.esm.js.map +1 -1
- package/dist/hooks/useDisallowedEmojis.d.ts +1 -0
- package/package.json +5 -5
- package/src/components/body/EmojiList.tsx +14 -6
- package/src/components/context/PickerContext.tsx +16 -3
- package/src/config/config.ts +9 -7
- package/src/config/useConfig.ts +6 -1
- package/src/data/emojis.json +1 -1
- package/src/dataUtils/DataTypes.ts +1 -0
- package/src/dataUtils/emojiSelectors.ts +8 -3
- package/src/hooks/useDisallowedEmojis.ts +33 -0
- package/src/types/exposedTypes.ts +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useDisallowedEmojis(): Record<string, boolean>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "4.0
|
|
2
|
+
"version": "4.1.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -92,12 +92,12 @@
|
|
|
92
92
|
"tiny-invariant": "^1.2.0",
|
|
93
93
|
"tsdx": "^0.14.1",
|
|
94
94
|
"tslib": "^2.4.0",
|
|
95
|
-
"typescript": "^4.7.4"
|
|
96
|
-
},
|
|
97
|
-
"dependencies": {
|
|
98
|
-
"clsx": "^1.2.1",
|
|
95
|
+
"typescript": "^4.7.4",
|
|
99
96
|
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
100
97
|
"eslint-plugin-react": "^7.31.8",
|
|
101
98
|
"eslint-plugin-react-hooks": "^4.6.0"
|
|
99
|
+
},
|
|
100
|
+
"dependencies": {
|
|
101
|
+
"clsx": "^1.2.1"
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -3,18 +3,19 @@ import * as React from 'react';
|
|
|
3
3
|
import {
|
|
4
4
|
Categories,
|
|
5
5
|
CategoryConfig,
|
|
6
|
-
categoryFromCategoryConfig
|
|
6
|
+
categoryFromCategoryConfig,
|
|
7
7
|
} from '../../config/categoryConfig';
|
|
8
8
|
import {
|
|
9
9
|
useCategoriesConfig,
|
|
10
10
|
useEmojiStyleConfig,
|
|
11
|
-
useLazyLoadEmojisConfig
|
|
11
|
+
useLazyLoadEmojisConfig,
|
|
12
12
|
} from '../../config/useConfig';
|
|
13
13
|
import { emojisByCategory, emojiUnified } from '../../dataUtils/emojiSelectors';
|
|
14
14
|
import { useIsEmojiHidden } from '../../hooks/useIsEmojiHidden';
|
|
15
15
|
import {
|
|
16
16
|
useActiveSkinToneState,
|
|
17
|
-
|
|
17
|
+
useDisallowedEmojisRef,
|
|
18
|
+
useIsPastInitialLoad,
|
|
18
19
|
} from '../context/PickerContext';
|
|
19
20
|
import { ClickableEmoji } from '../emoji/Emoji';
|
|
20
21
|
|
|
@@ -51,7 +52,7 @@ export function EmojiList() {
|
|
|
51
52
|
function RenderCategory({
|
|
52
53
|
index,
|
|
53
54
|
category,
|
|
54
|
-
categoryConfig
|
|
55
|
+
categoryConfig,
|
|
55
56
|
}: {
|
|
56
57
|
index: number;
|
|
57
58
|
category: Categories;
|
|
@@ -62,6 +63,7 @@ function RenderCategory({
|
|
|
62
63
|
const emojiStyle = useEmojiStyleConfig();
|
|
63
64
|
const isPastInitialLoad = useIsPastInitialLoad();
|
|
64
65
|
const [activeSkinTone] = useActiveSkinToneState();
|
|
66
|
+
const disallowedEmojisRef = useDisallowedEmojisRef();
|
|
65
67
|
|
|
66
68
|
// Small trick to defer the rendering of all emoji categories until the first category is visible
|
|
67
69
|
// This way the user gets to actually see something and not wait for the whole picker to render.
|
|
@@ -70,14 +72,20 @@ function RenderCategory({
|
|
|
70
72
|
|
|
71
73
|
let hiddenCounter = 0;
|
|
72
74
|
|
|
73
|
-
const emojis = emojisToPush.map(emoji => {
|
|
75
|
+
const emojis = emojisToPush.map((emoji) => {
|
|
74
76
|
const unified = emojiUnified(emoji, activeSkinTone);
|
|
75
77
|
const { failedToLoad, filteredOut, hidden } = isEmojiHidden(emoji);
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
const isDisallowed = !!disallowedEmojisRef.current[unified];
|
|
80
|
+
|
|
81
|
+
if (hidden || isDisallowed) {
|
|
78
82
|
hiddenCounter++;
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
if (isDisallowed) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
81
89
|
return (
|
|
82
90
|
<ClickableEmoji
|
|
83
91
|
key={unified}
|
|
@@ -5,17 +5,22 @@ import { useDefaultSkinToneConfig } from '../../config/useConfig';
|
|
|
5
5
|
import { DataEmoji } from '../../dataUtils/DataTypes';
|
|
6
6
|
import { alphaNumericEmojiIndex } from '../../dataUtils/alphaNumericEmojiIndex';
|
|
7
7
|
import { useDebouncedState } from '../../hooks/useDebouncedState';
|
|
8
|
+
import { useDisallowedEmojis } from '../../hooks/useDisallowedEmojis';
|
|
8
9
|
import { FilterDict } from '../../hooks/useFilter';
|
|
9
10
|
import { useMarkInitialLoad } from '../../hooks/useInitialLoad';
|
|
10
11
|
import { SkinTones } from '../../types/exposedTypes';
|
|
11
12
|
|
|
12
13
|
export function PickerContextProvider({ children }: Props) {
|
|
14
|
+
const disallowedEmojis = useDisallowedEmojis();
|
|
13
15
|
const defaultSkinTone = useDefaultSkinToneConfig();
|
|
14
16
|
|
|
15
17
|
// Initialize the filter with the inititial dictionary
|
|
16
18
|
const filterRef = React.useRef<FilterState>(alphaNumericEmojiIndex);
|
|
17
19
|
const disallowClickRef = React.useRef<boolean>(false);
|
|
18
20
|
const disallowMouseRef = React.useRef<boolean>(false);
|
|
21
|
+
const disallowedEmojisRef = React.useRef<Record<string, boolean>>(
|
|
22
|
+
disallowedEmojis
|
|
23
|
+
);
|
|
19
24
|
|
|
20
25
|
const suggestedUpdateState = useDebouncedState(Date.now(), 200);
|
|
21
26
|
const searchTerm = useDebouncedState('', 100);
|
|
@@ -41,7 +46,8 @@ export function PickerContextProvider({ children }: Props) {
|
|
|
41
46
|
isPastInitialLoad,
|
|
42
47
|
searchTerm,
|
|
43
48
|
skinToneFanOpenState,
|
|
44
|
-
suggestedUpdateState
|
|
49
|
+
suggestedUpdateState,
|
|
50
|
+
disallowedEmojisRef,
|
|
45
51
|
}}
|
|
46
52
|
>
|
|
47
53
|
{children}
|
|
@@ -63,18 +69,20 @@ const PickerContext = React.createContext<{
|
|
|
63
69
|
filterRef: React.MutableRefObject<FilterState>;
|
|
64
70
|
disallowClickRef: React.MutableRefObject<boolean>;
|
|
65
71
|
disallowMouseRef: React.MutableRefObject<boolean>;
|
|
72
|
+
disallowedEmojisRef: React.MutableRefObject<Record<string, boolean>>;
|
|
66
73
|
}>({
|
|
67
74
|
activeCategoryState: [null, () => {}],
|
|
68
75
|
activeSkinTone: [SkinTones.NEUTRAL, () => {}],
|
|
69
76
|
disallowClickRef: { current: false },
|
|
70
77
|
disallowMouseRef: { current: false },
|
|
78
|
+
disallowedEmojisRef: { current: {} },
|
|
71
79
|
emojiVariationPickerState: [null, () => {}],
|
|
72
80
|
emojisThatFailedToLoadState: [new Set(), () => {}],
|
|
73
81
|
filterRef: { current: {} },
|
|
74
82
|
isPastInitialLoad: true,
|
|
75
83
|
searchTerm: ['', () => new Promise<string>(() => undefined)],
|
|
76
84
|
skinToneFanOpenState: [false, () => {}],
|
|
77
|
-
suggestedUpdateState: [Date.now(), () => {}]
|
|
85
|
+
suggestedUpdateState: [Date.now(), () => {}],
|
|
78
86
|
});
|
|
79
87
|
|
|
80
88
|
type Props = Readonly<{
|
|
@@ -129,6 +137,11 @@ export function useSkinToneFanOpenState() {
|
|
|
129
137
|
return skinToneFanOpenState;
|
|
130
138
|
}
|
|
131
139
|
|
|
140
|
+
export function useDisallowedEmojisRef() {
|
|
141
|
+
const { disallowedEmojisRef } = React.useContext(PickerContext);
|
|
142
|
+
return disallowedEmojisRef;
|
|
143
|
+
}
|
|
144
|
+
|
|
132
145
|
export function useUpdateSuggested(): [number, () => void] {
|
|
133
146
|
const { suggestedUpdateState } = React.useContext(PickerContext);
|
|
134
147
|
|
|
@@ -137,7 +150,7 @@ export function useUpdateSuggested(): [number, () => void] {
|
|
|
137
150
|
suggestedUpdated,
|
|
138
151
|
function updateSuggested() {
|
|
139
152
|
setsuggestedUpdate(Date.now());
|
|
140
|
-
}
|
|
153
|
+
},
|
|
141
154
|
];
|
|
142
155
|
}
|
|
143
156
|
|
package/src/config/config.ts
CHANGED
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
EmojiStyle,
|
|
4
4
|
SkinTones,
|
|
5
5
|
SuggestionMode,
|
|
6
|
-
Theme
|
|
6
|
+
Theme,
|
|
7
7
|
} from '../types/exposedTypes';
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
CategoriesConfig,
|
|
11
11
|
baseCategoriesConfig,
|
|
12
|
-
mergeCategoriesConfig
|
|
12
|
+
mergeCategoriesConfig,
|
|
13
13
|
} from './categoryConfig';
|
|
14
14
|
|
|
15
15
|
export function mergeConfig(
|
|
@@ -24,13 +24,13 @@ export function mergeConfig(
|
|
|
24
24
|
const config = Object.assign(base, userConfig);
|
|
25
25
|
|
|
26
26
|
const categories = mergeCategoriesConfig(userConfig.categories, {
|
|
27
|
-
suggestionMode: config.suggestedEmojisMode
|
|
27
|
+
suggestionMode: config.suggestedEmojisMode,
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
31
|
...config,
|
|
32
32
|
categories,
|
|
33
|
-
previewConfig
|
|
33
|
+
previewConfig,
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -40,6 +40,7 @@ export function basePickerConfig(): PickerConfigInternal {
|
|
|
40
40
|
categories: baseCategoriesConfig(),
|
|
41
41
|
defaultSkinTone: SkinTones.NEUTRAL,
|
|
42
42
|
emojiStyle: EmojiStyle.APPLE,
|
|
43
|
+
emojiVersion: null,
|
|
43
44
|
height: 450,
|
|
44
45
|
lazyLoadEmojis: false,
|
|
45
46
|
onEmojiClick: function defaultOnClickHandler(
|
|
@@ -51,17 +52,18 @@ export function basePickerConfig(): PickerConfigInternal {
|
|
|
51
52
|
event: MouseEvent
|
|
52
53
|
) {},
|
|
53
54
|
previewConfig: {
|
|
54
|
-
...basePreviewConfig
|
|
55
|
+
...basePreviewConfig,
|
|
55
56
|
},
|
|
56
57
|
searchPlaceHolder: 'Search',
|
|
57
58
|
skinTonesDisabled: false,
|
|
58
59
|
suggestedEmojisMode: SuggestionMode.FREQUENT,
|
|
59
60
|
theme: Theme.LIGHT,
|
|
60
|
-
width: 350
|
|
61
|
+
width: 350,
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
export type PickerConfigInternal = {
|
|
66
|
+
emojiVersion: string | null;
|
|
65
67
|
searchPlaceHolder: string;
|
|
66
68
|
defaultSkinTone: SkinTones;
|
|
67
69
|
skinTonesDisabled: boolean;
|
|
@@ -86,7 +88,7 @@ export type PreviewConfig = {
|
|
|
86
88
|
const basePreviewConfig: PreviewConfig = {
|
|
87
89
|
defaultEmoji: '1f60a',
|
|
88
90
|
defaultCaption: "What's your mood?",
|
|
89
|
-
showPreview: true
|
|
91
|
+
showPreview: true,
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
type ConfigExternal = {
|
package/src/config/useConfig.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
EmojiStyle,
|
|
6
6
|
SkinTones,
|
|
7
7
|
SuggestionMode,
|
|
8
|
-
Theme
|
|
8
|
+
Theme,
|
|
9
9
|
} from '../types/exposedTypes';
|
|
10
10
|
|
|
11
11
|
import { CategoriesConfig } from './categoryConfig';
|
|
@@ -78,3 +78,8 @@ export function usePickerSizeConfig(): { height: number; width: number } {
|
|
|
78
78
|
const { height, width } = usePickerConfig();
|
|
79
79
|
return { height, width };
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
export function useEmojiVersionConfig(): string | null {
|
|
83
|
+
const { emojiVersion } = usePickerConfig();
|
|
84
|
+
return emojiVersion;
|
|
85
|
+
}
|