emoji-picker-react 4.5.0 → 4.5.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.
@@ -4,7 +4,9 @@ export declare type EmojiClickData = {
4
4
  unifiedWithoutSkinTone: string;
5
5
  emoji: string;
6
6
  names: string[];
7
- getImageUrl: (emojiStyle: EmojiStyle) => string;
7
+ imageUrl: string;
8
+ getImageUrl: (emojiStyle?: EmojiStyle) => string;
9
+ isCustom: boolean;
8
10
  };
9
11
  export declare enum SuggestionMode {
10
12
  RECENT = "recent",
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.5.0",
2
+ "version": "4.5.1",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -10,15 +10,17 @@ export function ExportedEmoji({
10
10
  size = 32,
11
11
  emojiStyle = EmojiStyle.APPLE,
12
12
  lazyLoad = false,
13
- getEmojiUrl
13
+ getEmojiUrl,
14
+ emojiUrl
14
15
  }: {
15
16
  unified: string;
16
17
  emojiStyle?: EmojiStyle;
17
18
  size?: number;
18
19
  lazyLoad?: boolean;
19
20
  getEmojiUrl?: GetEmojiUrl;
21
+ emojiUrl?: string;
20
22
  }) {
21
- if (!unified) {
23
+ if (!unified && !emojiUrl && !getEmojiUrl) {
22
24
  return null;
23
25
  }
24
26
 
@@ -28,7 +30,7 @@ export function ExportedEmoji({
28
30
  size={size}
29
31
  emojiStyle={emojiStyle}
30
32
  lazyLoad={lazyLoad}
31
- getEmojiUrl={getEmojiUrl}
33
+ getEmojiUrl={emojiUrl ? () => emojiUrl : getEmojiUrl}
32
34
  />
33
35
  );
34
36
  }
@@ -39,7 +39,7 @@ export function ViewOnlyEmoji({
39
39
  <EmojiImg
40
40
  style={style}
41
41
  emojiName={unified}
42
- emojiStyle={emojiStyle}
42
+ emojiStyle={EmojiStyle.NATIVE}
43
43
  lazyLoad={lazyLoad}
44
44
  imgUrl={emojiToRender.imgUrl}
45
45
  onError={onError}
@@ -4,32 +4,34 @@ import { useEffect, useRef } from 'react';
4
4
  import {
5
5
  emojiFromElement,
6
6
  isEmojiElement,
7
- NullableElement,
7
+ NullableElement
8
8
  } from '../DomUtils/selectors';
9
9
  import {
10
10
  useActiveSkinToneState,
11
11
  useDisallowClickRef,
12
12
  useEmojiVariationPickerState,
13
- useUpdateSuggested,
13
+ useUpdateSuggested
14
14
  } from '../components/context/PickerContext';
15
+ import { GetEmojiUrl } from '../components/emoji/BaseEmojiProps';
15
16
  import {
17
+ useEmojiStyleConfig,
16
18
  useGetEmojiUrlConfig,
17
- useOnEmojiClickConfig,
19
+ useOnEmojiClickConfig
18
20
  } from '../config/useConfig';
19
21
  import { DataEmoji } from '../dataUtils/DataTypes';
20
22
  import {
21
23
  activeVariationFromUnified,
22
24
  emojiHasVariations,
23
25
  emojiNames,
24
- emojiUnified,
26
+ emojiUnified
25
27
  } from '../dataUtils/emojiSelectors';
26
28
  import { parseNativeEmoji } from '../dataUtils/parseNativeEmoji';
27
29
  import { setSuggested } from '../dataUtils/suggested';
28
- import { EmojiClickData, EmojiStyle, SkinTones } from '../types/exposedTypes';
30
+ import { isCustomEmoji } from '../typeRefinements/typeRefinements';
31
+ import { EmojiClickData, SkinTones, EmojiStyle } from '../types/exposedTypes';
29
32
 
30
33
  import { useCloseAllOpenToggles } from './useCloseAllOpenToggles';
31
34
  import useSetVariationPicker from './useSetVariationPicker';
32
- import { GetEmojiUrl } from '../components/emoji/BaseEmojiProps';
33
35
 
34
36
  export function useMouseDownHandlers(
35
37
  BodyRef: React.MutableRefObject<NullableElement>
@@ -43,6 +45,7 @@ export function useMouseDownHandlers(
43
45
  const onEmojiClick = useOnEmojiClickConfig();
44
46
  const [, updateSuggested] = useUpdateSuggested();
45
47
  const getEmojiUrl = useGetEmojiUrlConfig();
48
+ const activeEmojiStyle = useEmojiStyleConfig();
46
49
 
47
50
  const onClick = React.useCallback(
48
51
  function onClick(event: MouseEvent) {
@@ -63,7 +66,10 @@ export function useMouseDownHandlers(
63
66
 
64
67
  updateSuggested();
65
68
  setSuggested(emoji, skinToneToUse);
66
- onEmojiClick(emojiClickOutput(emoji, skinToneToUse, getEmojiUrl), event);
69
+ onEmojiClick(
70
+ emojiClickOutput(emoji, skinToneToUse, activeEmojiStyle, getEmojiUrl),
71
+ event
72
+ );
67
73
  },
68
74
  [
69
75
  activeSkinTone,
@@ -72,6 +78,7 @@ export function useMouseDownHandlers(
72
78
  onEmojiClick,
73
79
  updateSuggested,
74
80
  getEmojiUrl,
81
+ activeEmojiStyle
75
82
  ]
76
83
  );
77
84
 
@@ -99,7 +106,7 @@ export function useMouseDownHandlers(
99
106
  disallowClickRef,
100
107
  closeAllOpenToggles,
101
108
  setVariationPicker,
102
- setEmojiVariationPicker,
109
+ setEmojiVariationPicker
103
110
  ]
104
111
  );
105
112
  const onMouseUp = React.useCallback(
@@ -128,14 +135,14 @@ export function useMouseDownHandlers(
128
135
  }
129
136
  const bodyRef = BodyRef.current;
130
137
  bodyRef.addEventListener('click', onClick, {
131
- passive: true,
138
+ passive: true
132
139
  });
133
140
 
134
141
  bodyRef.addEventListener('mousedown', onMouseDown, {
135
- passive: true,
142
+ passive: true
136
143
  });
137
144
  bodyRef.addEventListener('mouseup', onMouseUp, {
138
- passive: true,
145
+ passive: true
139
146
  });
140
147
 
141
148
  return () => {
@@ -158,17 +165,38 @@ function emojiFromEvent(event: MouseEvent): [DataEmoji, string] | [] {
158
165
  function emojiClickOutput(
159
166
  emoji: DataEmoji,
160
167
  activeSkinTone: SkinTones,
168
+ activeEmojiStyle: EmojiStyle,
161
169
  getEmojiUrl: GetEmojiUrl
162
170
  ): EmojiClickData {
171
+ const names = emojiNames(emoji);
172
+
173
+ if (isCustomEmoji(emoji)) {
174
+ const unified = emojiUnified(emoji);
175
+ return {
176
+ activeSkinTone,
177
+ emoji: unified,
178
+ getImageUrl() {
179
+ return emoji.imgUrl;
180
+ },
181
+ imageUrl: emoji.imgUrl,
182
+ isCustom: true,
183
+ names,
184
+ unified,
185
+ unifiedWithoutSkinTone: unified
186
+ };
187
+ }
163
188
  const unified = emojiUnified(emoji, activeSkinTone);
189
+
164
190
  return {
165
191
  activeSkinTone,
166
192
  emoji: parseNativeEmoji(unified),
167
- getImageUrl(emojiStyle: EmojiStyle) {
193
+ getImageUrl(emojiStyle: EmojiStyle = activeEmojiStyle ?? EmojiStyle.APPLE) {
168
194
  return getEmojiUrl(unified, emojiStyle);
169
195
  },
170
- names: emojiNames(emoji),
196
+ imageUrl: getEmojiUrl(unified, activeEmojiStyle ?? EmojiStyle.APPLE),
197
+ isCustom: false,
198
+ names,
171
199
  unified,
172
- unifiedWithoutSkinTone: emojiUnified(emoji),
200
+ unifiedWithoutSkinTone: emojiUnified(emoji)
173
201
  };
174
202
  }
@@ -4,7 +4,9 @@ export type EmojiClickData = {
4
4
  unifiedWithoutSkinTone: string;
5
5
  emoji: string;
6
6
  names: string[];
7
- getImageUrl: (emojiStyle: EmojiStyle) => string;
7
+ imageUrl: string;
8
+ getImageUrl: (emojiStyle?: EmojiStyle) => string;
9
+ isCustom: boolean;
8
10
  };
9
11
 
10
12
  export enum SuggestionMode {