emoji-picker-react 4.19.4 → 4.20.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.
@@ -520,11 +520,10 @@ function useDebouncedState(initialValue, delay) {
520
520
  var timer = useRef(null);
521
521
  function debouncedSetState(value) {
522
522
  return new Promise(function (resolve) {
523
- var _window;
524
523
  if (timer.current) {
525
524
  clearTimeout(timer.current);
526
525
  }
527
- timer.current = (_window = window) == null ? void 0 : _window.setTimeout(function () {
526
+ timer.current = setTimeout(function () {
528
527
  setState(value);
529
528
  resolve(value);
530
529
  }, delay);
@@ -26744,14 +26743,24 @@ var defaultEmojiData = {
26744
26743
  emojis: emojis
26745
26744
  };
26746
26745
 
26746
+ function useIsMounted() {
26747
+ var _React$useState = useState(false),
26748
+ isMounted = _React$useState[0],
26749
+ setIsMounted = _React$useState[1];
26750
+ useEffect(function () {
26751
+ setIsMounted(true);
26752
+ }, []);
26753
+ return isMounted;
26754
+ }
26755
+
26747
26756
  var SUGGESTED_LS_KEY = 'epr_suggested';
26748
26757
  function getSuggested(mode) {
26749
26758
  try {
26750
- var _window, _window$localStorage$, _window2;
26751
- if (!((_window = window) != null && _window.localStorage)) {
26759
+ var _window$localStorage$;
26760
+ if (typeof window === 'undefined' || !window.localStorage) {
26752
26761
  return [];
26753
26762
  }
26754
- var recent = JSON.parse((_window$localStorage$ = (_window2 = window) == null ? void 0 : _window2.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26763
+ var recent = JSON.parse((_window$localStorage$ = window.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26755
26764
  if (mode === SuggestionMode.FREQUENT) {
26756
26765
  return recent.sort(function (a, b) {
26757
26766
  return b.count - a.count;
@@ -26786,8 +26795,10 @@ function setSuggested(emoji, skinTone) {
26786
26795
  existing.count++;
26787
26796
  nextList.length = Math.min(nextList.length, 14);
26788
26797
  try {
26789
- var _window3;
26790
- (_window3 = window) == null ? void 0 : _window3.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26798
+ if (typeof window === 'undefined') {
26799
+ return;
26800
+ }
26801
+ window.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26791
26802
  // Prevents the change from being seen immediately.
26792
26803
  } catch (_unused2) {
26793
26804
  // ignore
@@ -26826,15 +26837,21 @@ function useGetEmojisByCategory() {
26826
26837
  var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26827
26838
  var _useUpdateSuggested = useUpdateSuggested(),
26828
26839
  suggestedUpdated = _useUpdateSuggested[0];
26840
+ // Suggestions come from localStorage, which doesn't exist during SSR.
26841
+ // Read them only after mount so the first client render matches the server.
26842
+ var isMounted = useIsMounted();
26829
26843
  var suggested = React__default.useMemo(function () {
26830
26844
  var _getSuggested;
26845
+ if (!isMounted) {
26846
+ return [];
26847
+ }
26831
26848
  var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26832
26849
  return suggested.map(function (s) {
26833
26850
  return emojiByUnified(s.unified);
26834
26851
  }).filter(Boolean);
26835
26852
  },
26836
26853
  // eslint-disable-next-line react-hooks/exhaustive-deps
26837
- [suggestedUpdated, suggestedEmojisModeConfig]);
26854
+ [isMounted, suggestedUpdated, suggestedEmojisModeConfig]);
26838
26855
  return function getEmojisByCategory(category) {
26839
26856
  var _emojis$emojis$catego;
26840
26857
  if (category === Categories.SUGGESTED) {
@@ -26957,8 +26974,14 @@ function useGetEmojisByCategory$1() {
26957
26974
  var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26958
26975
  var _useUpdateSuggested = useUpdateSuggested(),
26959
26976
  suggestedUpdated = _useUpdateSuggested[0];
26977
+ // Suggestions come from localStorage, which doesn't exist during SSR.
26978
+ // Read them only after mount so the first client render matches the server.
26979
+ var isMounted = useIsMounted();
26960
26980
  var suggested = React__default.useMemo(function () {
26961
26981
  var _getSuggested;
26982
+ if (!isMounted) {
26983
+ return [];
26984
+ }
26962
26985
  var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26963
26986
  return suggested.map(function (s) {
26964
26987
  var _extends2;
@@ -26967,7 +26990,7 @@ function useGetEmojisByCategory$1() {
26967
26990
  return _extends({}, emoji, (_extends2 = {}, _extends2[EmojiProperties.unified] = s.unified, _extends2));
26968
26991
  }).filter(Boolean);
26969
26992
  // eslint-disable-next-line react-hooks/exhaustive-deps
26970
- }, [suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26993
+ }, [isMounted, suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26971
26994
  return function getEmojisByCategory(category) {
26972
26995
  var _emojiData$emojis$cat, _emojiData$emojis;
26973
26996
  if (category === Categories.SUGGESTED) {
@@ -28799,7 +28822,6 @@ function useMouseDownHandlers(ContainerRef, mouseEventSource) {
28799
28822
  onEmojiClick(emojiClickOutput(emoji, skinToneToUse, activeEmojiStyle, getEmojiUrl), event);
28800
28823
  }, [activeSkinTone, closeAllOpenToggles, disallowClickRef, emojiByUnified, onEmojiClick, updateSuggested, getEmojiUrl, activeEmojiStyle]);
28801
28824
  var onMouseDown = useCallback(function onMouseDown(event) {
28802
- var _window;
28803
28825
  if (mouseDownTimerRef.current) {
28804
28826
  clearTimeout(mouseDownTimerRef.current);
28805
28827
  }
@@ -28808,7 +28830,7 @@ function useMouseDownHandlers(ContainerRef, mouseEventSource) {
28808
28830
  if (!emoji || !emojiHasVariations$1(emoji)) {
28809
28831
  return;
28810
28832
  }
28811
- mouseDownTimerRef.current = (_window = window) == null ? void 0 : _window.setTimeout(function () {
28833
+ mouseDownTimerRef.current = setTimeout(function () {
28812
28834
  disallowClickRef.current = true;
28813
28835
  mouseDownTimerRef.current = undefined;
28814
28836
  closeAllOpenToggles();
@@ -28917,7 +28939,12 @@ var styles$1 = /*#__PURE__*/stylesheet.create({
28917
28939
  '.': 'epr-btn',
28918
28940
  cursor: 'pointer',
28919
28941
  border: '0',
28920
- background: 'none',
28942
+ // Longhand, not `background: 'none'`: a shorthand reset shares its
28943
+ // conflict keys with every background longhand, so cx() would drop
28944
+ // this whole class wherever a later class sets background-image
28945
+ // (e.g. the category nav sprite) and the native button face would
28946
+ // show through.
28947
+ backgroundColor: 'transparent',
28921
28948
  outline: 'none'
28922
28949
  }
28923
28950
  });
@@ -29047,7 +29074,11 @@ function NativeEmoji(_ref) {
29047
29074
  style = _ref.style,
29048
29075
  className = _ref.className;
29049
29076
  return createElement("span", {
29050
- className: cx(styles$4.nativeEmoji, emojiStyles.common, emojiStyles.external, className),
29077
+ className: cx(
29078
+ // Order matters: cx() lets the later class win same-property
29079
+ // conflicts, so the zeroing reset must come first and the real
29080
+ // font-size last — otherwise the emoji renders at 0px.
29081
+ emojiStyles.external, emojiStyles.common, styles$4.nativeEmoji, className),
29051
29082
  "data-unified": unified,
29052
29083
  style: style
29053
29084
  }, parseNativeEmoji(unified));
@@ -29537,6 +29568,10 @@ var styles$7 = /*#__PURE__*/stylesheet.create({
29537
29568
  }
29538
29569
  });
29539
29570
 
29571
+ // `useLayoutEffect` warns during SSR since it never runs on the server.
29572
+ // Fall back to `useEffect` there: measurement only matters on the client.
29573
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
29574
+
29540
29575
  function MeasureEmoji() {
29541
29576
  var categories = useCategoriesConfig();
29542
29577
  var getEmojisByCategory = useGetEmojisByCategory();
@@ -29549,7 +29584,7 @@ function MeasureEmoji() {
29549
29584
  emojiSize = _useEmojiSizeState[0],
29550
29585
  setEmojiSize = _useEmojiSizeState[1];
29551
29586
  var ref = useRef(null);
29552
- useLayoutEffect(function () {
29587
+ useIsomorphicLayoutEffect(function () {
29553
29588
  if (ref.current) {
29554
29589
  setEmojiSize(ref.current.clientHeight);
29555
29590
  }