emoji-picker-react 4.20.0 → 4.20.2

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.
@@ -1,4 +1,4 @@
1
- import React__default, { memo, createElement, useState, useEffect, useContext, createContext, useRef, useMemo, createRef, useCallback, Fragment, useLayoutEffect, Suspense, Component } from 'react';
1
+ import React__default, { memo, createElement, useState, useEffect, useContext, createContext, useRef, useMemo, createRef, useCallback, Fragment, useLayoutEffect, Component } from 'react';
2
2
  import { createSheet, cx } from 'flairup';
3
3
 
4
4
  function _arrayLikeToArray(r, a) {
@@ -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,67 +26743,7 @@ var defaultEmojiData = {
26744
26743
  emojis: emojis
26745
26744
  };
26746
26745
 
26747
- var SUGGESTED_LS_KEY = 'epr_suggested';
26748
- function getSuggested(mode) {
26749
- try {
26750
- var _window, _window$localStorage$, _window2;
26751
- if (!((_window = window) != null && _window.localStorage)) {
26752
- return [];
26753
- }
26754
- var recent = JSON.parse((_window$localStorage$ = (_window2 = window) == null ? void 0 : _window2.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26755
- if (mode === SuggestionMode.FREQUENT) {
26756
- return recent.sort(function (a, b) {
26757
- return b.count - a.count;
26758
- });
26759
- }
26760
- return recent;
26761
- } catch (_unused) {
26762
- return [];
26763
- }
26764
- }
26765
- function setSuggested(emoji, skinTone) {
26766
- var recent = getSuggested();
26767
- var unified = emojiUnified$1(emoji, skinTone);
26768
- var originalUnified = emojiUnified$1(emoji);
26769
- var existing = recent.find(function (_ref) {
26770
- var u = _ref.unified;
26771
- return u === unified;
26772
- });
26773
- var nextList;
26774
- if (existing) {
26775
- nextList = [existing].concat(recent.filter(function (i) {
26776
- return i !== existing;
26777
- }));
26778
- } else {
26779
- existing = {
26780
- unified: unified,
26781
- original: originalUnified,
26782
- count: 0
26783
- };
26784
- nextList = [existing].concat(recent);
26785
- }
26786
- existing.count++;
26787
- nextList.length = Math.min(nextList.length, 14);
26788
- try {
26789
- var _window3;
26790
- (_window3 = window) == null ? void 0 : _window3.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26791
- // Prevents the change from being seen immediately.
26792
- } catch (_unused2) {
26793
- // ignore
26794
- }
26795
- }
26796
-
26797
- function emojiNames$1(emoji) {
26798
- var _emoji$EmojiPropertie;
26799
- return (_emoji$EmojiPropertie = emoji[EmojiProperties.name]) != null ? _emoji$EmojiPropertie : [];
26800
- }
26801
- function emojiName$1(emoji) {
26802
- if (!emoji) {
26803
- return '';
26804
- }
26805
- var names = emojiNames$1(emoji);
26806
- return names[names.length - 1];
26807
- }
26746
+ // Pure data helpers plus the legacy global registry. This module intentionally
26808
26747
  function unifiedWithoutSkinTone$1(unified) {
26809
26748
  var splat = unified.split('-');
26810
26749
  var _splat$splice = splat.splice(1, 1),
@@ -26822,28 +26761,6 @@ function emojiUnified$1(emoji, skinTone) {
26822
26761
  }
26823
26762
  return (_emojiVariationUnifie = emojiVariationUnified$1(emoji, skinTone)) != null ? _emojiVariationUnifie : unified;
26824
26763
  }
26825
- function useGetEmojisByCategory() {
26826
- var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26827
- var _useUpdateSuggested = useUpdateSuggested(),
26828
- suggestedUpdated = _useUpdateSuggested[0];
26829
- var suggested = React__default.useMemo(function () {
26830
- var _getSuggested;
26831
- var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26832
- return suggested.map(function (s) {
26833
- return emojiByUnified(s.unified);
26834
- }).filter(Boolean);
26835
- },
26836
- // eslint-disable-next-line react-hooks/exhaustive-deps
26837
- [suggestedUpdated, suggestedEmojisModeConfig]);
26838
- return function getEmojisByCategory(category) {
26839
- var _emojis$emojis$catego;
26840
- if (category === Categories.SUGGESTED) {
26841
- return suggested;
26842
- }
26843
- // @ts-ignore
26844
- return (_emojis$emojis$catego = defaultEmojiData.emojis[category]) != null ? _emojis$emojis$catego : [];
26845
- };
26846
- }
26847
26764
  function emojiVariations$1(emoji) {
26848
26765
  var _emoji$EmojiPropertie2;
26849
26766
  return (_emoji$EmojiPropertie2 = emoji[EmojiProperties.variations]) != null ? _emoji$EmojiPropertie2 : [];
@@ -26877,10 +26794,67 @@ allEmojis.reduce(function (allEmojis, Emoji) {
26877
26794
  }
26878
26795
  return allEmojis;
26879
26796
  }, allEmojisByUnified);
26880
- function activeVariationFromUnified$1(unified) {
26881
- var _unified$split = unified.split('-'),
26882
- suspectedSkinTone = _unified$split[1];
26883
- return skinToneVariations.includes(suspectedSkinTone) ? suspectedSkinTone : null;
26797
+
26798
+ var SUGGESTED_LS_KEY = 'epr_suggested';
26799
+ function getSuggested(mode) {
26800
+ try {
26801
+ var _window$localStorage$;
26802
+ if (typeof window === 'undefined' || !window.localStorage) {
26803
+ return [];
26804
+ }
26805
+ var recent = JSON.parse((_window$localStorage$ = window.localStorage.getItem(SUGGESTED_LS_KEY)) != null ? _window$localStorage$ : '[]');
26806
+ if (mode === SuggestionMode.FREQUENT) {
26807
+ return recent.sort(function (a, b) {
26808
+ return b.count - a.count;
26809
+ });
26810
+ }
26811
+ return recent;
26812
+ } catch (_unused) {
26813
+ return [];
26814
+ }
26815
+ }
26816
+ function setSuggested(emoji, skinTone) {
26817
+ var recent = getSuggested();
26818
+ var unified = emojiUnified(emoji, skinTone);
26819
+ var originalUnified = emojiUnified(emoji);
26820
+ var existing = recent.find(function (_ref) {
26821
+ var u = _ref.unified;
26822
+ return u === unified;
26823
+ });
26824
+ var nextList;
26825
+ if (existing) {
26826
+ nextList = [existing].concat(recent.filter(function (i) {
26827
+ return i !== existing;
26828
+ }));
26829
+ } else {
26830
+ existing = {
26831
+ unified: unified,
26832
+ original: originalUnified,
26833
+ count: 0
26834
+ };
26835
+ nextList = [existing].concat(recent);
26836
+ }
26837
+ existing.count++;
26838
+ nextList.length = Math.min(nextList.length, 14);
26839
+ try {
26840
+ if (typeof window === 'undefined') {
26841
+ return;
26842
+ }
26843
+ window.localStorage.setItem(SUGGESTED_LS_KEY, JSON.stringify(nextList));
26844
+ // Prevents the change from being seen immediately.
26845
+ } catch (_unused2) {
26846
+ // ignore
26847
+ }
26848
+ }
26849
+
26850
+ function useIsMounted() {
26851
+ var _React$useState = useState(false),
26852
+ isMounted = _React$useState[0],
26853
+ setIsMounted = _React$useState[1];
26854
+ useEffect(function () {
26855
+ setIsMounted(true);
26856
+ }, []);
26857
+ return isMounted;
26884
26858
  }
26885
26859
 
26886
26860
  var PickerDataContext = /*#__PURE__*/React__default.createContext({
@@ -26950,15 +26924,21 @@ function PickerDataProvider(_ref) {
26950
26924
  function usePickerDataContext() {
26951
26925
  return React__default.useContext(PickerDataContext);
26952
26926
  }
26953
- function useGetEmojisByCategory$1() {
26927
+ function useGetEmojisByCategory() {
26954
26928
  var _usePickerDataContext = usePickerDataContext(),
26955
26929
  emojiData = _usePickerDataContext.emojiData,
26956
26930
  emojiByUnified = _usePickerDataContext.emojiByUnified;
26957
26931
  var suggestedEmojisModeConfig = useSuggestedEmojisModeConfig();
26958
26932
  var _useUpdateSuggested = useUpdateSuggested(),
26959
26933
  suggestedUpdated = _useUpdateSuggested[0];
26934
+ // Suggestions come from localStorage, which doesn't exist during SSR.
26935
+ // Read them only after mount so the first client render matches the server.
26936
+ var isMounted = useIsMounted();
26960
26937
  var suggested = React__default.useMemo(function () {
26961
26938
  var _getSuggested;
26939
+ if (!isMounted) {
26940
+ return [];
26941
+ }
26962
26942
  var suggested = (_getSuggested = getSuggested(suggestedEmojisModeConfig)) != null ? _getSuggested : [];
26963
26943
  return suggested.map(function (s) {
26964
26944
  var _extends2;
@@ -26967,7 +26947,7 @@ function useGetEmojisByCategory$1() {
26967
26947
  return _extends({}, emoji, (_extends2 = {}, _extends2[EmojiProperties.unified] = s.unified, _extends2));
26968
26948
  }).filter(Boolean);
26969
26949
  // eslint-disable-next-line react-hooks/exhaustive-deps
26970
- }, [suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26950
+ }, [isMounted, suggestedUpdated, suggestedEmojisModeConfig, emojiByUnified]);
26971
26951
  return function getEmojisByCategory(category) {
26972
26952
  var _emojiData$emojis$cat, _emojiData$emojis;
26973
26953
  if (category === Categories.SUGGESTED) {
@@ -28316,7 +28296,7 @@ function useOnFocus() {
28316
28296
  if (!emoji) {
28317
28297
  return;
28318
28298
  }
28319
- if (emojiHasVariations$1(emoji)) {
28299
+ if (emojiHasVariations(emoji)) {
28320
28300
  preloadEmoji(getEmojiUrl, emoji, emojiStyle);
28321
28301
  }
28322
28302
  }
@@ -28793,22 +28773,21 @@ function useMouseDownHandlers(ContainerRef, mouseEventSource) {
28793
28773
  if (!emoji || !unified) {
28794
28774
  return;
28795
28775
  }
28796
- var skinToneToUse = activeVariationFromUnified$1(unified) || activeSkinTone;
28776
+ var skinToneToUse = activeVariationFromUnified(unified) || activeSkinTone;
28797
28777
  updateSuggested();
28798
28778
  setSuggested(emoji, skinToneToUse);
28799
28779
  onEmojiClick(emojiClickOutput(emoji, skinToneToUse, activeEmojiStyle, getEmojiUrl), event);
28800
28780
  }, [activeSkinTone, closeAllOpenToggles, disallowClickRef, emojiByUnified, onEmojiClick, updateSuggested, getEmojiUrl, activeEmojiStyle]);
28801
28781
  var onMouseDown = useCallback(function onMouseDown(event) {
28802
- var _window;
28803
28782
  if (mouseDownTimerRef.current) {
28804
28783
  clearTimeout(mouseDownTimerRef.current);
28805
28784
  }
28806
28785
  var _emojiFromEvent2 = emojiFromEvent(event, emojiByUnified),
28807
28786
  emoji = _emojiFromEvent2[0];
28808
- if (!emoji || !emojiHasVariations$1(emoji)) {
28787
+ if (!emoji || !emojiHasVariations(emoji)) {
28809
28788
  return;
28810
28789
  }
28811
- mouseDownTimerRef.current = (_window = window) == null ? void 0 : _window.setTimeout(function () {
28790
+ mouseDownTimerRef.current = setTimeout(function () {
28812
28791
  disallowClickRef.current = true;
28813
28792
  mouseDownTimerRef.current = undefined;
28814
28793
  closeAllOpenToggles();
@@ -28871,9 +28850,9 @@ function emojiFromEvent(event, lookupEmojiByUnified) {
28871
28850
  return [emoji, unified != null ? unified : resolvedUnified];
28872
28851
  }
28873
28852
  function emojiClickOutput(emoji, activeSkinTone, activeEmojiStyle, getEmojiUrl) {
28874
- var names = emojiNames$1(emoji);
28853
+ var names = emojiNames(emoji);
28875
28854
  if (isCustomEmoji(emoji)) {
28876
- var _unified = emojiUnified$1(emoji);
28855
+ var _unified = emojiUnified(emoji);
28877
28856
  return {
28878
28857
  activeSkinTone: activeSkinTone,
28879
28858
  emoji: _unified,
@@ -28887,7 +28866,7 @@ function emojiClickOutput(emoji, activeSkinTone, activeEmojiStyle, getEmojiUrl)
28887
28866
  unifiedWithoutSkinTone: _unified
28888
28867
  };
28889
28868
  }
28890
- var unified = emojiUnified$1(emoji, activeSkinTone);
28869
+ var unified = emojiUnified(emoji, activeSkinTone);
28891
28870
  return {
28892
28871
  activeSkinTone: activeSkinTone,
28893
28872
  emoji: parseNativeEmoji(unified),
@@ -28901,7 +28880,7 @@ function emojiClickOutput(emoji, activeSkinTone, activeEmojiStyle, getEmojiUrl)
28901
28880
  isCustom: false,
28902
28881
  names: names,
28903
28882
  unified: unified,
28904
- unifiedWithoutSkinTone: emojiUnified$1(emoji)
28883
+ unifiedWithoutSkinTone: emojiUnified(emoji)
28905
28884
  };
28906
28885
  }
28907
28886
 
@@ -29143,13 +29122,13 @@ function ClickableEmoji(_ref) {
29143
29122
  _ref$noBackground = _ref.noBackground,
29144
29123
  noBackground = _ref$noBackground === void 0 ? false : _ref$noBackground,
29145
29124
  style = _ref.style;
29146
- var hasVariations = emojiHasVariations$1(emoji);
29125
+ var hasVariations = emojiHasVariations(emoji);
29147
29126
  return createElement(ClickableEmojiButton, {
29148
29127
  hasVariations: hasVariations,
29149
29128
  showVariations: showVariations,
29150
29129
  hidden: hidden,
29151
29130
  hiddenOnSearch: hiddenOnSearch,
29152
- emojiNames: emojiNames$1(emoji),
29131
+ emojiNames: emojiNames(emoji),
29153
29132
  unified: unified,
29154
29133
  noBackground: noBackground,
29155
29134
  style: style
@@ -29546,6 +29525,10 @@ var styles$7 = /*#__PURE__*/stylesheet.create({
29546
29525
  }
29547
29526
  });
29548
29527
 
29528
+ // `useLayoutEffect` warns during SSR since it never runs on the server.
29529
+ // Fall back to `useEffect` there: measurement only matters on the client.
29530
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
29531
+
29549
29532
  function MeasureEmoji() {
29550
29533
  var categories = useCategoriesConfig();
29551
29534
  var getEmojisByCategory = useGetEmojisByCategory();
@@ -29558,7 +29541,7 @@ function MeasureEmoji() {
29558
29541
  emojiSize = _useEmojiSizeState[0],
29559
29542
  setEmojiSize = _useEmojiSizeState[1];
29560
29543
  var ref = useRef(null);
29561
- useLayoutEffect(function () {
29544
+ useIsomorphicLayoutEffect(function () {
29562
29545
  if (ref.current) {
29563
29546
  setEmojiSize(ref.current.clientHeight);
29564
29547
  }
@@ -29568,7 +29551,7 @@ function MeasureEmoji() {
29568
29551
  }
29569
29552
  var firstCategory = categories[0];
29570
29553
  var dummyEmoji = getEmojisByCategory(categoryFromCategoryConfig(firstCategory))[0];
29571
- var unified = dummyEmoji ? emojiUnified$1(dummyEmoji, activeSkinTone) : '';
29554
+ var unified = dummyEmoji ? emojiUnified(dummyEmoji, activeSkinTone) : '';
29572
29555
  if (!dummyEmoji) {
29573
29556
  return null;
29574
29557
  }
@@ -29602,7 +29585,7 @@ function EmojiList(_ref) {
29602
29585
  categoryHeights = _React$useState[0],
29603
29586
  setCategoryHeights = _React$useState[1];
29604
29587
  var EmojiListRef = useEmojiListRef();
29605
- var getEmojisByCategory = useGetEmojisByCategory$1();
29588
+ var getEmojisByCategory = useGetEmojisByCategory();
29606
29589
  var labelHeight = getLabelHeight(EmojiListRef.current);
29607
29590
  var topOffset = 0;
29608
29591
  return createElement("ul", {
@@ -29615,9 +29598,8 @@ function EmojiList(_ref) {
29615
29598
  if (categoryHeight) {
29616
29599
  topOffset += categoryHeight + labelHeight;
29617
29600
  }
29618
- return createElement(Suspense, {
29619
- key: category
29620
- }, createElement(RenderCategory, {
29601
+ return createElement(RenderCategory, {
29602
+ key: category,
29621
29603
  categoryEmojis: getEmojisByCategory(category),
29622
29604
  categoryConfig: categoryConfig,
29623
29605
  topOffset: currentOffset,
@@ -29630,7 +29612,7 @@ function EmojiList(_ref) {
29630
29612
  }
29631
29613
  },
29632
29614
  scrollTop: scrollTop
29633
- }));
29615
+ });
29634
29616
  }));
29635
29617
  }
29636
29618
  function RenderCategory(_ref2) {
@@ -29689,7 +29671,7 @@ function EmojiVariationPicker() {
29689
29671
  var getPointerStyle = usePointerStyle(VariationPickerRef);
29690
29672
  var getEmojiUrl = useGetEmojiUrlConfig();
29691
29673
  var button = buttonFromTarget(AnchoredEmojiRef.current);
29692
- var visible = Boolean(emoji && button && emojiHasVariations$1(emoji) && button.classList.contains(ClassNames.emojiHasVariations));
29674
+ var visible = Boolean(emoji && button && emojiHasVariations(emoji) && button.classList.contains(ClassNames.emojiHasVariations));
29693
29675
  useEffect(function () {
29694
29676
  if (!visible) {
29695
29677
  return;
@@ -29709,7 +29691,7 @@ function EmojiVariationPicker() {
29709
29691
  style: {
29710
29692
  top: top
29711
29693
  }
29712
- }, visible && emoji ? [emojiUnified$1(emoji)].concat(emojiVariations$1(emoji)).slice(0, 6).map(function (unified) {
29694
+ }, visible && emoji ? [emojiUnified(emoji)].concat(emojiVariations(emoji)).slice(0, 6).map(function (unified) {
29713
29695
  return createElement(ClickableEmoji, {
29714
29696
  key: unified,
29715
29697
  emoji: emoji,
@@ -30225,7 +30207,7 @@ function PreviewBody() {
30225
30207
  if (!defaultEmoji) {
30226
30208
  return null;
30227
30209
  }
30228
- var defaultText = variationPickerEmoji ? emojiName$1(variationPickerEmoji) : previewConfig.defaultCaption;
30210
+ var defaultText = variationPickerEmoji ? emojiName(variationPickerEmoji) : previewConfig.defaultCaption;
30229
30211
  return createElement(Fragment, null, createElement("div", null, show ? createElement(ViewOnlyEmoji, {
30230
30212
  unified: previewEmoji == null ? void 0 : previewEmoji.unified,
30231
30213
  emoji: emoji,
@@ -30234,7 +30216,7 @@ function PreviewBody() {
30234
30216
  getEmojiUrl: getEmojiUrl,
30235
30217
  className: cx(styles$e.emoji)
30236
30218
  }) : defaultEmoji ? createElement(ViewOnlyEmoji, {
30237
- unified: emojiUnified$1(defaultEmoji),
30219
+ unified: emojiUnified(defaultEmoji),
30238
30220
  emoji: defaultEmoji,
30239
30221
  emojiStyle: emojiStyle,
30240
30222
  size: 45,
@@ -30242,7 +30224,7 @@ function PreviewBody() {
30242
30224
  className: cx(styles$e.emoji)
30243
30225
  }) : null), createElement("div", {
30244
30226
  className: cx(styles$e.label)
30245
- }, show ? emojiName$1(emoji) : defaultText));
30227
+ }, show ? emojiName(emoji) : defaultText));
30246
30228
  }
30247
30229
  }
30248
30230
  var styles$e = /*#__PURE__*/stylesheet.create({