emoji-picker-react 4.4.3 → 4.4.5

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.
@@ -15,6 +15,7 @@ export declare enum ClassNames {
15
15
  emojiPicker = "EmojiPickerReact",
16
16
  open = "epr-open",
17
17
  vertical = "epr-vertical",
18
- horizontal = "epr-horizontal"
18
+ horizontal = "epr-horizontal",
19
+ variationPicker = "epr-emoji-variation-picker"
19
20
  }
20
21
  export declare function asSelectors(...classNames: ClassNames[]): string;
@@ -27,6 +27,7 @@ var ClassNames;
27
27
  ClassNames["open"] = "epr-open";
28
28
  ClassNames["vertical"] = "epr-vertical";
29
29
  ClassNames["horizontal"] = "epr-horizontal";
30
+ ClassNames["variationPicker"] = "epr-emoji-variation-picker";
30
31
  })(ClassNames || (ClassNames = {}));
31
32
 
32
33
  function asSelectors() {
@@ -39,6 +40,31 @@ function asSelectors() {
39
40
  }).join('');
40
41
  }
41
42
 
43
+ function focusElement(element) {
44
+ if (!element) {
45
+ return;
46
+ }
47
+
48
+ requestAnimationFrame(function () {
49
+ element.focus();
50
+ });
51
+ }
52
+ function focusPrevElementSibling(element) {
53
+ if (!element) return;
54
+ var prev = element.previousElementSibling;
55
+ focusElement(prev);
56
+ }
57
+ function focusNextElementSibling(element) {
58
+ if (!element) return;
59
+ var next = element.nextElementSibling;
60
+ focusElement(next);
61
+ }
62
+ function focusFirstElementChild(element) {
63
+ if (!element) return;
64
+ var first = element.firstElementChild;
65
+ focusElement(first);
66
+ }
67
+
42
68
  function ElementRefContextProvider(_ref) {
43
69
  var children = _ref.children;
44
70
  var PickerMainRef = React.useRef(null);
@@ -83,6 +109,10 @@ function useAnchoredEmojiRef() {
83
109
  function useSetAnchoredEmojiRef() {
84
110
  var AnchoredEmojiRef = useAnchoredEmojiRef();
85
111
  return function (target) {
112
+ if (target === null && AnchoredEmojiRef.current !== null) {
113
+ focusElement(AnchoredEmojiRef.current);
114
+ }
115
+
86
116
  AnchoredEmojiRef.current = target;
87
117
  };
88
118
  }
@@ -17630,198 +17660,12 @@ function useHasOpenToggles() {
17630
17660
  };
17631
17661
  }
17632
17662
 
17633
- function focusElement(element) {
17634
- if (!element) {
17635
- return;
17636
- }
17637
-
17638
- requestAnimationFrame(function () {
17639
- element.focus();
17640
- });
17641
- }
17642
- function focusPrevElementSibling(element) {
17643
- if (!element) return;
17644
- var prev = element.previousElementSibling;
17645
- focusElement(prev);
17646
- }
17647
- function focusNextElementSibling(element) {
17648
- if (!element) return;
17649
- var next = element.nextElementSibling;
17650
- focusElement(next);
17651
- }
17652
- function focusFirstElementChild(element) {
17653
- if (!element) return;
17654
- var first = element.firstElementChild;
17655
- focusElement(first);
17656
- }
17657
-
17658
- function scrollTo(root, top) {
17659
- if (top === void 0) {
17660
- top = 0;
17661
- }
17662
-
17663
- var $eprBody = queryScrollBody(root);
17664
-
17665
- if (!$eprBody) {
17666
- return;
17667
- }
17668
-
17669
- requestAnimationFrame(function () {
17670
- $eprBody.scrollTop = top + 1;
17671
- });
17672
- }
17673
- function scrollBy(root, by) {
17674
- var $eprBody = queryScrollBody(root);
17675
-
17676
- if (!$eprBody) {
17677
- return;
17678
- }
17679
-
17680
- requestAnimationFrame(function () {
17681
- $eprBody.scrollTop = $eprBody.scrollTop + by;
17682
- });
17683
- }
17684
- function useScrollTo() {
17685
- var BodyRef = useBodyRef();
17686
- return React.useCallback(function (top) {
17687
- requestAnimationFrame(function () {
17688
- if (BodyRef.current) {
17689
- BodyRef.current.scrollTop = top;
17690
- }
17691
- });
17692
- }, [BodyRef]);
17693
- }
17694
- function scrollEmojiAboveLabel(emoji) {
17695
- if (!isEmojiBehindLabel(emoji)) {
17696
- return;
17697
- }
17698
-
17699
- var scrollBody = closestScrollBody(emoji);
17700
- var by = emojiDistanceFromScrollTop(emoji);
17701
- scrollBy(scrollBody, -(categoryLabelHeight(closestCategory(emoji)) - by));
17702
- }
17703
-
17704
- function focusFirstVisibleEmoji(parent) {
17705
- var emoji = firstVisibleEmoji(parent);
17706
- focusElement(emoji);
17707
- scrollEmojiAboveLabel(emoji);
17708
- }
17709
- function focusAndClickFirstVisibleEmoji(parent) {
17710
- var firstEmoji = firstVisibleEmoji(parent);
17711
- focusElement(firstEmoji);
17712
- firstEmoji == null ? void 0 : firstEmoji.click();
17713
- }
17714
- function focusLastVisibleEmoji(parent) {
17715
- focusElement(lastVisibleEmoji(parent));
17716
- }
17717
- function focusNextVisibleEmoji(element) {
17718
- if (!element) {
17719
- return;
17720
- }
17721
-
17722
- var next = nextVisibleEmoji(element);
17723
-
17724
- if (!next) {
17725
- return focusFirstVisibleEmoji(nextCategory(element));
17726
- }
17727
-
17728
- focusElement(next);
17729
- scrollEmojiAboveLabel(next);
17730
- }
17731
- function focusPrevVisibleEmoji(element) {
17732
- if (!element) {
17733
- return;
17734
- }
17735
-
17736
- var prev = prevVisibleEmoji(element);
17737
-
17738
- if (!prev) {
17739
- return focusLastVisibleEmoji(prevCategory(element));
17740
- }
17741
-
17742
- focusElement(prev);
17743
- scrollEmojiAboveLabel(prev);
17744
- }
17745
- function focusVisibleEmojiOneRowUp(element, exitUp) {
17746
- if (!element) {
17747
- return;
17748
- }
17749
-
17750
- var prev = visibleEmojiOneRowUp(element);
17751
-
17752
- if (!prev) {
17753
- return exitUp();
17754
- }
17755
-
17756
- focusElement(prev);
17757
- scrollEmojiAboveLabel(prev);
17758
- }
17759
- function focusVisibleEmojiOneRowDown(element) {
17760
- if (!element) {
17761
- return;
17762
- }
17763
-
17764
- var next = visibleEmojiOneRowDown(element);
17765
- return focusElement(next);
17766
- }
17767
-
17768
- function visibleEmojiOneRowUp(element) {
17769
- if (!element) {
17770
- return null;
17771
- }
17772
-
17773
- var categoryContent = closestCategoryContent(element);
17774
- var category = closestCategory(categoryContent);
17775
- var indexInRow = elementIndexInRow(categoryContent, element);
17776
- var row = rowNumber(categoryContent, element);
17777
- var countInRow = elementCountInRow(categoryContent, element);
17778
-
17779
- if (row === 0) {
17780
- var prevVisibleCategory = prevCategory(category);
17781
-
17782
- if (!prevVisibleCategory) {
17783
- return null;
17784
- }
17785
-
17786
- return getElementInRow(allVisibleEmojis(prevVisibleCategory), -1, // last row
17787
- countInRow, indexInRow);
17788
- }
17789
-
17790
- return getElementInPrevRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
17791
- }
17792
-
17793
- function visibleEmojiOneRowDown(element) {
17794
- if (!element) {
17795
- return null;
17796
- }
17797
-
17798
- var categoryContent = closestCategoryContent(element);
17799
- var category = closestCategory(categoryContent);
17800
- var indexInRow = elementIndexInRow(categoryContent, element);
17801
- var row = rowNumber(categoryContent, element);
17802
- var countInRow = elementCountInRow(categoryContent, element);
17803
-
17804
- if (!hasNextRow(categoryContent, element)) {
17805
- var nextVisibleCategory = nextCategory(category);
17806
-
17807
- if (!nextVisibleCategory) {
17808
- return null;
17809
- }
17810
-
17811
- return getElementInRow(allVisibleEmojis(nextVisibleCategory), 0, countInRow, indexInRow);
17812
- }
17813
-
17814
- var itemInNextRow = getElementInNextRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
17815
- return itemInNextRow;
17816
- }
17817
-
17818
17663
  function useSetVariationPicker() {
17819
17664
  var setAnchoredEmojiRef = useSetAnchoredEmojiRef();
17820
17665
 
17821
17666
  var _useEmojiVariationPic = useEmojiVariationPickerState(),
17822
17667
  setEmojiVariationPicker = _useEmojiVariationPic[1];
17823
17668
 
17824
- var VariationPickerRef = useVariationPickerRef();
17825
17669
  return function setVariationPicker(element) {
17826
17670
  var _emojiFromElement = emojiFromElement(element),
17827
17671
  emoji = _emojiFromElement[0];
@@ -17832,9 +17676,6 @@ function useSetVariationPicker() {
17832
17676
 
17833
17677
  setAnchoredEmojiRef(element);
17834
17678
  setEmojiVariationPicker(emoji);
17835
- requestAnimationFrame(function () {
17836
- focusFirstVisibleEmoji(VariationPickerRef.current);
17837
- });
17838
17679
  };
17839
17680
  }
17840
17681
 
@@ -17984,6 +17825,56 @@ function useOnScroll(BodyRef) {
17984
17825
  }, [BodyRef, closeAllOpenToggles]);
17985
17826
  }
17986
17827
 
17828
+ function scrollTo(root, top) {
17829
+ if (top === void 0) {
17830
+ top = 0;
17831
+ }
17832
+
17833
+ var $eprBody = queryScrollBody(root);
17834
+
17835
+ if (!$eprBody) {
17836
+ return;
17837
+ }
17838
+
17839
+ requestAnimationFrame(function () {
17840
+ $eprBody.scrollTop = top + 1;
17841
+ });
17842
+ }
17843
+ function scrollBy(root, by) {
17844
+ var $eprBody = queryScrollBody(root);
17845
+
17846
+ if (!$eprBody) {
17847
+ return;
17848
+ }
17849
+
17850
+ requestAnimationFrame(function () {
17851
+ $eprBody.scrollTop = $eprBody.scrollTop + by;
17852
+ });
17853
+ }
17854
+ function useScrollTo() {
17855
+ var BodyRef = useBodyRef();
17856
+ return React.useCallback(function (top) {
17857
+ requestAnimationFrame(function () {
17858
+ if (BodyRef.current) {
17859
+ BodyRef.current.scrollTop = top;
17860
+ }
17861
+ });
17862
+ }, [BodyRef]);
17863
+ }
17864
+ function scrollEmojiAboveLabel(emoji) {
17865
+ if (!emoji || !isEmojiBehindLabel(emoji)) {
17866
+ return;
17867
+ }
17868
+
17869
+ if (emoji.closest(asSelectors(ClassNames.variationPicker))) {
17870
+ return;
17871
+ }
17872
+
17873
+ var scrollBody = closestScrollBody(emoji);
17874
+ var by = emojiDistanceFromScrollTop(emoji);
17875
+ scrollBy(scrollBody, -(categoryLabelHeight(closestCategory(emoji)) - by));
17876
+ }
17877
+
17987
17878
  function useFocusSearchInput() {
17988
17879
  var SearchInputRef = useSearchInputRef();
17989
17880
  return React.useCallback(function () {
@@ -18431,6 +18322,120 @@ function RenderCategory(_ref) {
18431
18322
  }, emojis);
18432
18323
  }
18433
18324
 
18325
+ function focusFirstVisibleEmoji(parent) {
18326
+ var emoji = firstVisibleEmoji(parent);
18327
+ focusElement(emoji);
18328
+ scrollEmojiAboveLabel(emoji);
18329
+ }
18330
+ function focusAndClickFirstVisibleEmoji(parent) {
18331
+ var firstEmoji = firstVisibleEmoji(parent);
18332
+ focusElement(firstEmoji);
18333
+ firstEmoji == null ? void 0 : firstEmoji.click();
18334
+ }
18335
+ function focusLastVisibleEmoji(parent) {
18336
+ focusElement(lastVisibleEmoji(parent));
18337
+ }
18338
+ function focusNextVisibleEmoji(element) {
18339
+ if (!element) {
18340
+ return;
18341
+ }
18342
+
18343
+ var next = nextVisibleEmoji(element);
18344
+
18345
+ if (!next) {
18346
+ return focusFirstVisibleEmoji(nextCategory(element));
18347
+ }
18348
+
18349
+ focusElement(next);
18350
+ scrollEmojiAboveLabel(next);
18351
+ }
18352
+ function focusPrevVisibleEmoji(element) {
18353
+ if (!element) {
18354
+ return;
18355
+ }
18356
+
18357
+ var prev = prevVisibleEmoji(element);
18358
+
18359
+ if (!prev) {
18360
+ return focusLastVisibleEmoji(prevCategory(element));
18361
+ }
18362
+
18363
+ focusElement(prev);
18364
+ scrollEmojiAboveLabel(prev);
18365
+ }
18366
+ function focusVisibleEmojiOneRowUp(element, exitUp) {
18367
+ if (!element) {
18368
+ return;
18369
+ }
18370
+
18371
+ var prev = visibleEmojiOneRowUp(element);
18372
+
18373
+ if (!prev) {
18374
+ return exitUp();
18375
+ }
18376
+
18377
+ focusElement(prev);
18378
+ scrollEmojiAboveLabel(prev);
18379
+ }
18380
+ function focusVisibleEmojiOneRowDown(element) {
18381
+ if (!element) {
18382
+ return;
18383
+ }
18384
+
18385
+ var next = visibleEmojiOneRowDown(element);
18386
+ return focusElement(next);
18387
+ }
18388
+
18389
+ function visibleEmojiOneRowUp(element) {
18390
+ if (!element) {
18391
+ return null;
18392
+ }
18393
+
18394
+ var categoryContent = closestCategoryContent(element);
18395
+ var category = closestCategory(categoryContent);
18396
+ var indexInRow = elementIndexInRow(categoryContent, element);
18397
+ var row = rowNumber(categoryContent, element);
18398
+ var countInRow = elementCountInRow(categoryContent, element);
18399
+
18400
+ if (row === 0) {
18401
+ var prevVisibleCategory = prevCategory(category);
18402
+
18403
+ if (!prevVisibleCategory) {
18404
+ return null;
18405
+ }
18406
+
18407
+ return getElementInRow(allVisibleEmojis(prevVisibleCategory), -1, // last row
18408
+ countInRow, indexInRow);
18409
+ }
18410
+
18411
+ return getElementInPrevRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
18412
+ }
18413
+
18414
+ function visibleEmojiOneRowDown(element) {
18415
+ if (!element) {
18416
+ return null;
18417
+ }
18418
+
18419
+ var categoryContent = closestCategoryContent(element);
18420
+ var category = closestCategory(categoryContent);
18421
+ var indexInRow = elementIndexInRow(categoryContent, element);
18422
+ var row = rowNumber(categoryContent, element);
18423
+ var countInRow = elementCountInRow(categoryContent, element);
18424
+
18425
+ if (!hasNextRow(categoryContent, element)) {
18426
+ var nextVisibleCategory = nextCategory(category);
18427
+
18428
+ if (!nextVisibleCategory) {
18429
+ return null;
18430
+ }
18431
+
18432
+ return getElementInRow(allVisibleEmojis(nextVisibleCategory), 0, countInRow, indexInRow);
18433
+ }
18434
+
18435
+ var itemInNextRow = getElementInNextRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
18436
+ return itemInNextRow;
18437
+ }
18438
+
18434
18439
  var Direction;
18435
18440
 
18436
18441
  (function (Direction) {
@@ -18456,10 +18461,16 @@ function EmojiVariationPicker() {
18456
18461
  var getEmojiUrl = useGetEmojiUrlConfig();
18457
18462
  var button = buttonFromTarget(AnchoredEmojiRef.current);
18458
18463
  var visible = emoji && button && emojiHasVariations(emoji) && button.classList.contains(ClassNames.emojiHasVariatios);
18464
+ React.useEffect(function () {
18465
+ if (!visible) {
18466
+ return;
18467
+ }
18468
+
18469
+ focusFirstVisibleEmoji(VariationPickerRef.current);
18470
+ }, [VariationPickerRef, visible, AnchoredEmojiRef]);
18459
18471
  var top, pointerStyle;
18460
18472
 
18461
18473
  if (!visible && AnchoredEmojiRef.current) {
18462
- focusElement(AnchoredEmojiRef.current);
18463
18474
  setAnchoredEmojiRef(null);
18464
18475
  } else {
18465
18476
  top = getTop();
@@ -18469,7 +18480,7 @@ function EmojiVariationPicker() {
18469
18480
  var safeEmoji = asEmoji(emoji);
18470
18481
  return React.createElement("div", {
18471
18482
  ref: VariationPickerRef,
18472
- className: clsx('epr-emoji-variation-picker', {
18483
+ className: clsx(ClassNames.variationPicker, {
18473
18484
  visible: visible,
18474
18485
  'pointing-up': getMenuDirection() === Direction.Down
18475
18486
  }),
@@ -19143,7 +19154,7 @@ function useSearchInputKeyboardEvents() {
19143
19154
  break;
19144
19155
  }
19145
19156
  };
19146
- }, [focusSkinTonePicker, goDownFromSearchInput, setSkinToneFanOpenState, BodyRef]);
19157
+ }, [focusSkinTonePicker, goDownFromSearchInput, setSkinToneFanOpenState, BodyRef, isSkinToneInSearch]);
19147
19158
  React.useEffect(function () {
19148
19159
  var current = SearchInputRef.current;
19149
19160