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.
@@ -0,0 +1,2 @@
1
+ import { NullableElement } from './selectors';
2
+ export declare function detectEmojyPartiallyBelowFold(button: HTMLButtonElement, bodyRef: NullableElement): number;
@@ -0,0 +1,2 @@
1
+ import { PickerConfig } from './config';
2
+ export declare function compareConfig(prev: PickerConfig, next: PickerConfig): boolean;
@@ -187,6 +187,14 @@ function darkMode(key, value) {
187
187
  };
188
188
  }
189
189
 
190
+ // eslint-disable-next-line complexity
191
+ function compareConfig(prev, next) {
192
+ var _prev$customEmojis, _next$customEmojis;
193
+ var prevCustomEmojis = (_prev$customEmojis = prev.customEmojis) != null ? _prev$customEmojis : [];
194
+ var nextCustomEmojis = (_next$customEmojis = next.customEmojis) != null ? _next$customEmojis : [];
195
+ return prev.open === next.open && prev.emojiVersion === next.emojiVersion && prev.reactionsDefaultOpen === next.reactionsDefaultOpen && prev.searchPlaceHolder === next.searchPlaceHolder && prev.searchPlaceholder === next.searchPlaceholder && prev.defaultSkinTone === next.defaultSkinTone && prev.skinTonesDisabled === next.skinTonesDisabled && prev.autoFocusSearch === next.autoFocusSearch && prev.emojiStyle === next.emojiStyle && prev.theme === next.theme && prev.suggestedEmojisMode === next.suggestedEmojisMode && prev.lazyLoadEmojis === next.lazyLoadEmojis && prev.className === next.className && prev.height === next.height && prev.width === next.width && prev.style === next.style && prev.searchDisabled === next.searchDisabled && prev.skinTonePickerLocation === next.skinTonePickerLocation && prevCustomEmojis.length === nextCustomEmojis.length;
196
+ }
197
+
190
198
  var DEFAULT_REACTIONS = ['1f44d', '2764-fe0f', '1f603', '1f622', '1f64f', '1f44e', '1f621' // 😡
191
199
  ];
192
200
 
@@ -16863,22 +16871,18 @@ function useSetConfig(config) {
16863
16871
  mergedConfig = _React$useState[0],
16864
16872
  setMergedConfig = _React$useState[1];
16865
16873
  React.useEffect(function () {
16866
- if (avoidRefresh(config, mergedConfig)) {
16874
+ if (compareConfig(mergedConfig, config)) {
16867
16875
  return;
16868
16876
  }
16869
16877
  setMergedConfig(mergeConfig(config));
16870
16878
  // not gonna...
16871
16879
  // eslint-disable-next-line react-hooks/exhaustive-deps
16872
- }, [(_config$customEmojis = config.customEmojis) == null ? void 0 : _config$customEmojis.length, config.open]);
16880
+ }, [(_config$customEmojis = config.customEmojis) == null ? void 0 : _config$customEmojis.length, config.open, config.emojiVersion, config.reactionsDefaultOpen, config.searchPlaceHolder, config.searchPlaceholder, config.defaultSkinTone, config.skinTonesDisabled, config.autoFocusSearch, config.emojiStyle, config.theme, config.suggestedEmojisMode, config.lazyLoadEmojis, config.className, config.height, config.width, config.searchDisabled, config.skinTonePickerLocation]);
16873
16881
  return mergedConfig;
16874
16882
  }
16875
16883
  function usePickerConfig() {
16876
16884
  return React.useContext(ConfigContext);
16877
16885
  }
16878
- function avoidRefresh(prev, next) {
16879
- var _prev$customEmojis, _next$customEmojis;
16880
- return ((_prev$customEmojis = prev.customEmojis) == null ? void 0 : _prev$customEmojis.length) === ((_next$customEmojis = next.customEmojis) == null ? void 0 : _next$customEmojis.length) && prev.open === next.open;
16881
- }
16882
16886
 
16883
16887
  var MutableConfigContext = /*#__PURE__*/React__default.createContext({});
16884
16888
  function useMutableConfig() {
@@ -18928,6 +18932,16 @@ var styles$9 = /*#__PURE__*/stylesheet.create({
18928
18932
  }
18929
18933
  });
18930
18934
 
18935
+ function detectEmojyPartiallyBelowFold(button, bodyRef) {
18936
+ if (!button || !bodyRef) {
18937
+ return 0;
18938
+ }
18939
+ var buttonRect = button.getBoundingClientRect();
18940
+ var bodyRect = bodyRef.getBoundingClientRect();
18941
+ // If the element is obscured by at least half of its size
18942
+ return bodyRect.height - (buttonRect.y - bodyRect.y);
18943
+ }
18944
+
18931
18945
  function useEmojiPreviewEvents(allow, setPreviewEmoji) {
18932
18946
  var BodyRef = useBodyRef();
18933
18947
  var isMouseDisallowed = useIsMouseDisallowed();
@@ -18981,6 +18995,18 @@ function useEmojiPreviewEvents(allow, setPreviewEmoji) {
18981
18995
  }
18982
18996
  var button = buttonFromTarget(e.target);
18983
18997
  if (button) {
18998
+ var belowFoldByPx = detectEmojyPartiallyBelowFold(button, bodyRef);
18999
+ var buttonHeight = button.getBoundingClientRect().height;
19000
+ if (belowFoldByPx < buttonHeight / 2) {
19001
+ return;
19002
+ }
19003
+ if (belowFoldByPx < buttonHeight) {
19004
+ button.scrollIntoView({
19005
+ behavior: 'smooth',
19006
+ block: 'end'
19007
+ });
19008
+ return;
19009
+ }
18984
19010
  focusElement(button);
18985
19011
  }
18986
19012
  }
@@ -20380,12 +20406,7 @@ function ContentControl() {
20380
20406
  return React.createElement(PickerMain, null, React.createElement(Reactions, null), renderAll ? React.createElement(React.Fragment, null, React.createElement(Header, null), React.createElement(Body, null), React.createElement(Preview, null)) : null);
20381
20407
  }
20382
20408
  // eslint-disable-next-line complexity
20383
- var EmojiPickerReact = /*#__PURE__*/React.memo(EmojiPicker, function (prev, next) {
20384
- var _prev$customEmojis, _next$customEmojis;
20385
- var prevCustomEmojis = (_prev$customEmojis = prev.customEmojis) != null ? _prev$customEmojis : [];
20386
- var nextCustomEmojis = (_next$customEmojis = next.customEmojis) != null ? _next$customEmojis : [];
20387
- return prev.open === next.open && prev.emojiVersion === next.emojiVersion && prev.reactionsDefaultOpen === next.reactionsDefaultOpen && prev.searchPlaceHolder === next.searchPlaceHolder && prev.searchPlaceholder === next.searchPlaceholder && prev.defaultSkinTone === next.defaultSkinTone && prev.skinTonesDisabled === next.skinTonesDisabled && prev.autoFocusSearch === next.autoFocusSearch && prev.emojiStyle === next.emojiStyle && prev.theme === next.theme && prev.suggestedEmojisMode === next.suggestedEmojisMode && prev.lazyLoadEmojis === next.lazyLoadEmojis && prev.className === next.className && prev.height === next.height && prev.width === next.width && prev.style === next.style && prev.searchDisabled === next.searchDisabled && prev.skinTonePickerLocation === next.skinTonePickerLocation && prevCustomEmojis.length === nextCustomEmojis.length;
20388
- });
20409
+ var EmojiPickerReact = /*#__PURE__*/React.memo(EmojiPicker, compareConfig);
20389
20410
 
20390
20411
  var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
20391
20412
  _inheritsLoose(ErrorBoundary, _React$Component);