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