emoji-picker-react 4.7.12 → 4.7.13

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.7.12",
2
+ "version": "4.7.13",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1,16 @@
1
+ import { NullableElement } from './selectors';
2
+
3
+ export function detectEmojyPartiallyBelowFold(
4
+ button: HTMLButtonElement,
5
+ bodyRef: NullableElement
6
+ ): number {
7
+ if (!button || !bodyRef) {
8
+ return 0;
9
+ }
10
+
11
+ const buttonRect = button.getBoundingClientRect();
12
+ const bodyRect = bodyRef.getBoundingClientRect();
13
+
14
+ // If the element is obscured by at least half of its size
15
+ return bodyRect.height - (buttonRect.y - bodyRect.y);
16
+ }
@@ -9,6 +9,7 @@ import { useReactionsModeState } from './components/context/PickerContext';
9
9
  import { Preview } from './components/footer/Preview';
10
10
  import { Header } from './components/header/Header';
11
11
  import PickerMain from './components/main/PickerMain';
12
+ import { compareConfig } from './config/compareConfig';
12
13
  import { useOpenConfig } from './config/useConfig';
13
14
 
14
15
  import { PickerProps } from './index';
@@ -54,28 +55,4 @@ function ContentControl() {
54
55
  }
55
56
 
56
57
  // eslint-disable-next-line complexity
57
- export default React.memo(EmojiPicker, (prev, next) => {
58
- const prevCustomEmojis = prev.customEmojis ?? [];
59
- const nextCustomEmojis = next.customEmojis ?? [];
60
- return (
61
- prev.open === next.open &&
62
- prev.emojiVersion === next.emojiVersion &&
63
- prev.reactionsDefaultOpen === next.reactionsDefaultOpen &&
64
- prev.searchPlaceHolder === next.searchPlaceHolder &&
65
- prev.searchPlaceholder === next.searchPlaceholder &&
66
- prev.defaultSkinTone === next.defaultSkinTone &&
67
- prev.skinTonesDisabled === next.skinTonesDisabled &&
68
- prev.autoFocusSearch === next.autoFocusSearch &&
69
- prev.emojiStyle === next.emojiStyle &&
70
- prev.theme === next.theme &&
71
- prev.suggestedEmojisMode === next.suggestedEmojisMode &&
72
- prev.lazyLoadEmojis === next.lazyLoadEmojis &&
73
- prev.className === next.className &&
74
- prev.height === next.height &&
75
- prev.width === next.width &&
76
- prev.style === next.style &&
77
- prev.searchDisabled === next.searchDisabled &&
78
- prev.skinTonePickerLocation === next.skinTonePickerLocation &&
79
- prevCustomEmojis.length === nextCustomEmojis.length
80
- );
81
- });
58
+ export default React.memo(EmojiPicker, compareConfig);
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
 
3
+ import { compareConfig } from '../../config/compareConfig';
3
4
  import {
4
5
  basePickerConfig,
5
6
  mergeConfig,
@@ -32,13 +33,32 @@ export function useSetConfig(config: PickerConfig) {
32
33
  );
33
34
 
34
35
  React.useEffect(() => {
35
- if (avoidRefresh(config as Props, (mergedConfig as unknown) as Props)) {
36
+ if (compareConfig(mergedConfig, config)) {
36
37
  return;
37
38
  }
38
39
  setMergedConfig(mergeConfig(config));
39
40
  // not gonna...
40
41
  // eslint-disable-next-line react-hooks/exhaustive-deps
41
- }, [config.customEmojis?.length, config.open]);
42
+ }, [
43
+ config.customEmojis?.length,
44
+ config.open,
45
+ config.emojiVersion,
46
+ config.reactionsDefaultOpen,
47
+ config.searchPlaceHolder,
48
+ config.searchPlaceholder,
49
+ config.defaultSkinTone,
50
+ config.skinTonesDisabled,
51
+ config.autoFocusSearch,
52
+ config.emojiStyle,
53
+ config.theme,
54
+ config.suggestedEmojisMode,
55
+ config.lazyLoadEmojis,
56
+ config.className,
57
+ config.height,
58
+ config.width,
59
+ config.searchDisabled,
60
+ config.skinTonePickerLocation
61
+ ]);
42
62
 
43
63
  return mergedConfig;
44
64
  }
@@ -46,10 +66,3 @@ export function useSetConfig(config: PickerConfig) {
46
66
  export function usePickerConfig() {
47
67
  return React.useContext(ConfigContext);
48
68
  }
49
-
50
- function avoidRefresh(prev: Props, next: Props) {
51
- return (
52
- prev.customEmojis?.length === next.customEmojis?.length &&
53
- prev.open === next.open
54
- );
55
- }
@@ -0,0 +1,28 @@
1
+ import { PickerConfig } from './config';
2
+
3
+ // eslint-disable-next-line complexity
4
+ export function compareConfig(prev: PickerConfig, next: PickerConfig) {
5
+ const prevCustomEmojis = prev.customEmojis ?? [];
6
+ const nextCustomEmojis = next.customEmojis ?? [];
7
+ return (
8
+ prev.open === next.open &&
9
+ prev.emojiVersion === next.emojiVersion &&
10
+ prev.reactionsDefaultOpen === next.reactionsDefaultOpen &&
11
+ prev.searchPlaceHolder === next.searchPlaceHolder &&
12
+ prev.searchPlaceholder === next.searchPlaceholder &&
13
+ prev.defaultSkinTone === next.defaultSkinTone &&
14
+ prev.skinTonesDisabled === next.skinTonesDisabled &&
15
+ prev.autoFocusSearch === next.autoFocusSearch &&
16
+ prev.emojiStyle === next.emojiStyle &&
17
+ prev.theme === next.theme &&
18
+ prev.suggestedEmojisMode === next.suggestedEmojisMode &&
19
+ prev.lazyLoadEmojis === next.lazyLoadEmojis &&
20
+ prev.className === next.className &&
21
+ prev.height === next.height &&
22
+ prev.width === next.width &&
23
+ prev.style === next.style &&
24
+ prev.searchDisabled === next.searchDisabled &&
25
+ prev.skinTonePickerLocation === next.skinTonePickerLocation &&
26
+ prevCustomEmojis.length === nextCustomEmojis.length
27
+ );
28
+ }
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { useEffect } from 'react';
3
3
 
4
+ import { detectEmojyPartiallyBelowFold } from '../DomUtils/detectEmojyPartiallyBelowFold';
4
5
  import { focusElement } from '../DomUtils/focusElement';
5
6
  import {
6
7
  buttonFromTarget,
@@ -86,6 +87,16 @@ export function useEmojiPreviewEvents(
86
87
  const button = buttonFromTarget(e.target as HTMLElement);
87
88
 
88
89
  if (button) {
90
+ const belowFoldByPx = detectEmojyPartiallyBelowFold(button, bodyRef);
91
+ const buttonHeight = button.getBoundingClientRect().height;
92
+ if (belowFoldByPx < buttonHeight / 2) {
93
+ return;
94
+ }
95
+ if (belowFoldByPx < buttonHeight) {
96
+ button.scrollIntoView({ behavior: 'smooth', block: 'end' });
97
+ return;
98
+ }
99
+
89
100
  focusElement(button);
90
101
  }
91
102
  }