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.
@@ -21,6 +21,7 @@ var ClassNames;
21
21
  ClassNames["open"] = "epr-open";
22
22
  ClassNames["vertical"] = "epr-vertical";
23
23
  ClassNames["horizontal"] = "epr-horizontal";
24
+ ClassNames["variationPicker"] = "epr-emoji-variation-picker";
24
25
  })(ClassNames || (ClassNames = {}));
25
26
 
26
27
  function asSelectors() {
@@ -33,6 +34,31 @@ function asSelectors() {
33
34
  }).join('');
34
35
  }
35
36
 
37
+ function focusElement(element) {
38
+ if (!element) {
39
+ return;
40
+ }
41
+
42
+ requestAnimationFrame(function () {
43
+ element.focus();
44
+ });
45
+ }
46
+ function focusPrevElementSibling(element) {
47
+ if (!element) return;
48
+ var prev = element.previousElementSibling;
49
+ focusElement(prev);
50
+ }
51
+ function focusNextElementSibling(element) {
52
+ if (!element) return;
53
+ var next = element.nextElementSibling;
54
+ focusElement(next);
55
+ }
56
+ function focusFirstElementChild(element) {
57
+ if (!element) return;
58
+ var first = element.firstElementChild;
59
+ focusElement(first);
60
+ }
61
+
36
62
  function ElementRefContextProvider(_ref) {
37
63
  var children = _ref.children;
38
64
  var PickerMainRef = useRef(null);
@@ -77,6 +103,10 @@ function useAnchoredEmojiRef() {
77
103
  function useSetAnchoredEmojiRef() {
78
104
  var AnchoredEmojiRef = useAnchoredEmojiRef();
79
105
  return function (target) {
106
+ if (target === null && AnchoredEmojiRef.current !== null) {
107
+ focusElement(AnchoredEmojiRef.current);
108
+ }
109
+
80
110
  AnchoredEmojiRef.current = target;
81
111
  };
82
112
  }
@@ -17636,198 +17666,12 @@ function useHasOpenToggles() {
17636
17666
  };
17637
17667
  }
17638
17668
 
17639
- function focusElement(element) {
17640
- if (!element) {
17641
- return;
17642
- }
17643
-
17644
- requestAnimationFrame(function () {
17645
- element.focus();
17646
- });
17647
- }
17648
- function focusPrevElementSibling(element) {
17649
- if (!element) return;
17650
- var prev = element.previousElementSibling;
17651
- focusElement(prev);
17652
- }
17653
- function focusNextElementSibling(element) {
17654
- if (!element) return;
17655
- var next = element.nextElementSibling;
17656
- focusElement(next);
17657
- }
17658
- function focusFirstElementChild(element) {
17659
- if (!element) return;
17660
- var first = element.firstElementChild;
17661
- focusElement(first);
17662
- }
17663
-
17664
- function scrollTo(root, top) {
17665
- if (top === void 0) {
17666
- top = 0;
17667
- }
17668
-
17669
- var $eprBody = queryScrollBody(root);
17670
-
17671
- if (!$eprBody) {
17672
- return;
17673
- }
17674
-
17675
- requestAnimationFrame(function () {
17676
- $eprBody.scrollTop = top + 1;
17677
- });
17678
- }
17679
- function scrollBy(root, by) {
17680
- var $eprBody = queryScrollBody(root);
17681
-
17682
- if (!$eprBody) {
17683
- return;
17684
- }
17685
-
17686
- requestAnimationFrame(function () {
17687
- $eprBody.scrollTop = $eprBody.scrollTop + by;
17688
- });
17689
- }
17690
- function useScrollTo() {
17691
- var BodyRef = useBodyRef();
17692
- return useCallback(function (top) {
17693
- requestAnimationFrame(function () {
17694
- if (BodyRef.current) {
17695
- BodyRef.current.scrollTop = top;
17696
- }
17697
- });
17698
- }, [BodyRef]);
17699
- }
17700
- function scrollEmojiAboveLabel(emoji) {
17701
- if (!isEmojiBehindLabel(emoji)) {
17702
- return;
17703
- }
17704
-
17705
- var scrollBody = closestScrollBody(emoji);
17706
- var by = emojiDistanceFromScrollTop(emoji);
17707
- scrollBy(scrollBody, -(categoryLabelHeight(closestCategory(emoji)) - by));
17708
- }
17709
-
17710
- function focusFirstVisibleEmoji(parent) {
17711
- var emoji = firstVisibleEmoji(parent);
17712
- focusElement(emoji);
17713
- scrollEmojiAboveLabel(emoji);
17714
- }
17715
- function focusAndClickFirstVisibleEmoji(parent) {
17716
- var firstEmoji = firstVisibleEmoji(parent);
17717
- focusElement(firstEmoji);
17718
- firstEmoji == null ? void 0 : firstEmoji.click();
17719
- }
17720
- function focusLastVisibleEmoji(parent) {
17721
- focusElement(lastVisibleEmoji(parent));
17722
- }
17723
- function focusNextVisibleEmoji(element) {
17724
- if (!element) {
17725
- return;
17726
- }
17727
-
17728
- var next = nextVisibleEmoji(element);
17729
-
17730
- if (!next) {
17731
- return focusFirstVisibleEmoji(nextCategory(element));
17732
- }
17733
-
17734
- focusElement(next);
17735
- scrollEmojiAboveLabel(next);
17736
- }
17737
- function focusPrevVisibleEmoji(element) {
17738
- if (!element) {
17739
- return;
17740
- }
17741
-
17742
- var prev = prevVisibleEmoji(element);
17743
-
17744
- if (!prev) {
17745
- return focusLastVisibleEmoji(prevCategory(element));
17746
- }
17747
-
17748
- focusElement(prev);
17749
- scrollEmojiAboveLabel(prev);
17750
- }
17751
- function focusVisibleEmojiOneRowUp(element, exitUp) {
17752
- if (!element) {
17753
- return;
17754
- }
17755
-
17756
- var prev = visibleEmojiOneRowUp(element);
17757
-
17758
- if (!prev) {
17759
- return exitUp();
17760
- }
17761
-
17762
- focusElement(prev);
17763
- scrollEmojiAboveLabel(prev);
17764
- }
17765
- function focusVisibleEmojiOneRowDown(element) {
17766
- if (!element) {
17767
- return;
17768
- }
17769
-
17770
- var next = visibleEmojiOneRowDown(element);
17771
- return focusElement(next);
17772
- }
17773
-
17774
- function visibleEmojiOneRowUp(element) {
17775
- if (!element) {
17776
- return null;
17777
- }
17778
-
17779
- var categoryContent = closestCategoryContent(element);
17780
- var category = closestCategory(categoryContent);
17781
- var indexInRow = elementIndexInRow(categoryContent, element);
17782
- var row = rowNumber(categoryContent, element);
17783
- var countInRow = elementCountInRow(categoryContent, element);
17784
-
17785
- if (row === 0) {
17786
- var prevVisibleCategory = prevCategory(category);
17787
-
17788
- if (!prevVisibleCategory) {
17789
- return null;
17790
- }
17791
-
17792
- return getElementInRow(allVisibleEmojis(prevVisibleCategory), -1, // last row
17793
- countInRow, indexInRow);
17794
- }
17795
-
17796
- return getElementInPrevRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
17797
- }
17798
-
17799
- function visibleEmojiOneRowDown(element) {
17800
- if (!element) {
17801
- return null;
17802
- }
17803
-
17804
- var categoryContent = closestCategoryContent(element);
17805
- var category = closestCategory(categoryContent);
17806
- var indexInRow = elementIndexInRow(categoryContent, element);
17807
- var row = rowNumber(categoryContent, element);
17808
- var countInRow = elementCountInRow(categoryContent, element);
17809
-
17810
- if (!hasNextRow(categoryContent, element)) {
17811
- var nextVisibleCategory = nextCategory(category);
17812
-
17813
- if (!nextVisibleCategory) {
17814
- return null;
17815
- }
17816
-
17817
- return getElementInRow(allVisibleEmojis(nextVisibleCategory), 0, countInRow, indexInRow);
17818
- }
17819
-
17820
- var itemInNextRow = getElementInNextRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
17821
- return itemInNextRow;
17822
- }
17823
-
17824
17669
  function useSetVariationPicker() {
17825
17670
  var setAnchoredEmojiRef = useSetAnchoredEmojiRef();
17826
17671
 
17827
17672
  var _useEmojiVariationPic = useEmojiVariationPickerState(),
17828
17673
  setEmojiVariationPicker = _useEmojiVariationPic[1];
17829
17674
 
17830
- var VariationPickerRef = useVariationPickerRef();
17831
17675
  return function setVariationPicker(element) {
17832
17676
  var _emojiFromElement = emojiFromElement(element),
17833
17677
  emoji = _emojiFromElement[0];
@@ -17838,9 +17682,6 @@ function useSetVariationPicker() {
17838
17682
 
17839
17683
  setAnchoredEmojiRef(element);
17840
17684
  setEmojiVariationPicker(emoji);
17841
- requestAnimationFrame(function () {
17842
- focusFirstVisibleEmoji(VariationPickerRef.current);
17843
- });
17844
17685
  };
17845
17686
  }
17846
17687
 
@@ -17990,6 +17831,56 @@ function useOnScroll(BodyRef) {
17990
17831
  }, [BodyRef, closeAllOpenToggles]);
17991
17832
  }
17992
17833
 
17834
+ function scrollTo(root, top) {
17835
+ if (top === void 0) {
17836
+ top = 0;
17837
+ }
17838
+
17839
+ var $eprBody = queryScrollBody(root);
17840
+
17841
+ if (!$eprBody) {
17842
+ return;
17843
+ }
17844
+
17845
+ requestAnimationFrame(function () {
17846
+ $eprBody.scrollTop = top + 1;
17847
+ });
17848
+ }
17849
+ function scrollBy(root, by) {
17850
+ var $eprBody = queryScrollBody(root);
17851
+
17852
+ if (!$eprBody) {
17853
+ return;
17854
+ }
17855
+
17856
+ requestAnimationFrame(function () {
17857
+ $eprBody.scrollTop = $eprBody.scrollTop + by;
17858
+ });
17859
+ }
17860
+ function useScrollTo() {
17861
+ var BodyRef = useBodyRef();
17862
+ return useCallback(function (top) {
17863
+ requestAnimationFrame(function () {
17864
+ if (BodyRef.current) {
17865
+ BodyRef.current.scrollTop = top;
17866
+ }
17867
+ });
17868
+ }, [BodyRef]);
17869
+ }
17870
+ function scrollEmojiAboveLabel(emoji) {
17871
+ if (!emoji || !isEmojiBehindLabel(emoji)) {
17872
+ return;
17873
+ }
17874
+
17875
+ if (emoji.closest(asSelectors(ClassNames.variationPicker))) {
17876
+ return;
17877
+ }
17878
+
17879
+ var scrollBody = closestScrollBody(emoji);
17880
+ var by = emojiDistanceFromScrollTop(emoji);
17881
+ scrollBy(scrollBody, -(categoryLabelHeight(closestCategory(emoji)) - by));
17882
+ }
17883
+
17993
17884
  function useFocusSearchInput() {
17994
17885
  var SearchInputRef = useSearchInputRef();
17995
17886
  return useCallback(function () {
@@ -18473,6 +18364,120 @@ function RenderCategory(_ref) {
18473
18364
  }, emojis);
18474
18365
  }
18475
18366
 
18367
+ function focusFirstVisibleEmoji(parent) {
18368
+ var emoji = firstVisibleEmoji(parent);
18369
+ focusElement(emoji);
18370
+ scrollEmojiAboveLabel(emoji);
18371
+ }
18372
+ function focusAndClickFirstVisibleEmoji(parent) {
18373
+ var firstEmoji = firstVisibleEmoji(parent);
18374
+ focusElement(firstEmoji);
18375
+ firstEmoji == null ? void 0 : firstEmoji.click();
18376
+ }
18377
+ function focusLastVisibleEmoji(parent) {
18378
+ focusElement(lastVisibleEmoji(parent));
18379
+ }
18380
+ function focusNextVisibleEmoji(element) {
18381
+ if (!element) {
18382
+ return;
18383
+ }
18384
+
18385
+ var next = nextVisibleEmoji(element);
18386
+
18387
+ if (!next) {
18388
+ return focusFirstVisibleEmoji(nextCategory(element));
18389
+ }
18390
+
18391
+ focusElement(next);
18392
+ scrollEmojiAboveLabel(next);
18393
+ }
18394
+ function focusPrevVisibleEmoji(element) {
18395
+ if (!element) {
18396
+ return;
18397
+ }
18398
+
18399
+ var prev = prevVisibleEmoji(element);
18400
+
18401
+ if (!prev) {
18402
+ return focusLastVisibleEmoji(prevCategory(element));
18403
+ }
18404
+
18405
+ focusElement(prev);
18406
+ scrollEmojiAboveLabel(prev);
18407
+ }
18408
+ function focusVisibleEmojiOneRowUp(element, exitUp) {
18409
+ if (!element) {
18410
+ return;
18411
+ }
18412
+
18413
+ var prev = visibleEmojiOneRowUp(element);
18414
+
18415
+ if (!prev) {
18416
+ return exitUp();
18417
+ }
18418
+
18419
+ focusElement(prev);
18420
+ scrollEmojiAboveLabel(prev);
18421
+ }
18422
+ function focusVisibleEmojiOneRowDown(element) {
18423
+ if (!element) {
18424
+ return;
18425
+ }
18426
+
18427
+ var next = visibleEmojiOneRowDown(element);
18428
+ return focusElement(next);
18429
+ }
18430
+
18431
+ function visibleEmojiOneRowUp(element) {
18432
+ if (!element) {
18433
+ return null;
18434
+ }
18435
+
18436
+ var categoryContent = closestCategoryContent(element);
18437
+ var category = closestCategory(categoryContent);
18438
+ var indexInRow = elementIndexInRow(categoryContent, element);
18439
+ var row = rowNumber(categoryContent, element);
18440
+ var countInRow = elementCountInRow(categoryContent, element);
18441
+
18442
+ if (row === 0) {
18443
+ var prevVisibleCategory = prevCategory(category);
18444
+
18445
+ if (!prevVisibleCategory) {
18446
+ return null;
18447
+ }
18448
+
18449
+ return getElementInRow(allVisibleEmojis(prevVisibleCategory), -1, // last row
18450
+ countInRow, indexInRow);
18451
+ }
18452
+
18453
+ return getElementInPrevRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
18454
+ }
18455
+
18456
+ function visibleEmojiOneRowDown(element) {
18457
+ if (!element) {
18458
+ return null;
18459
+ }
18460
+
18461
+ var categoryContent = closestCategoryContent(element);
18462
+ var category = closestCategory(categoryContent);
18463
+ var indexInRow = elementIndexInRow(categoryContent, element);
18464
+ var row = rowNumber(categoryContent, element);
18465
+ var countInRow = elementCountInRow(categoryContent, element);
18466
+
18467
+ if (!hasNextRow(categoryContent, element)) {
18468
+ var nextVisibleCategory = nextCategory(category);
18469
+
18470
+ if (!nextVisibleCategory) {
18471
+ return null;
18472
+ }
18473
+
18474
+ return getElementInRow(allVisibleEmojis(nextVisibleCategory), 0, countInRow, indexInRow);
18475
+ }
18476
+
18477
+ var itemInNextRow = getElementInNextRow(allVisibleEmojis(categoryContent), row, countInRow, indexInRow);
18478
+ return itemInNextRow;
18479
+ }
18480
+
18476
18481
  var css_248z$3 = ".EmojiPickerReact .epr-emoji-variation-picker{align-items:center;background:var(--epr-emoji-variation-picker-bg-color);border:1px solid var(--epr-picker-border-color);border-radius:3px;box-shadow:0 2px 5px rgba(0,0,0,.2);display:flex;height:0;height:var(--epr-emoji-variation-picker-height);justify-content:space-around;left:15px;opacity:0;padding:5px;pointer-events:none;position:absolute;right:15px;top:0;top:-100%;transform:scale(.9);transition:transform .1s ease-out,opacity .2s ease-out;visibility:hidden;z-index:var(--epr-skin-variation-picker-z-index)}.EmojiPickerReact .epr-emoji-variation-picker.pointing-up{transform:scale(.9);transform-origin:center 0}.EmojiPickerReact .epr-emoji-variation-picker.visible{opacity:1;pointer-events:all;transform:scale(1);visibility:visible}.EmojiPickerReact .epr-emoji-variation-picker .EmojiPickerReact .epr-emoji-variation-picker button.epr-emoji:hover{background:none}.EmojiPickerReact .epr-emoji-variation-picker .epr-emoji-pointer{background-image:url(\"data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='50' height='15' xml:space='preserve'%3E%3Cg stroke-miterlimit='10'%3E%3Cpath fill='%23FFF' stroke='%23E8E7E7' d='m1.86-.43 9.83 11.53c.59.69 1.56.69 2.14 0L23.66-.43'/%3E%3Cpath fill='%23010202' stroke='%23151617' d='m26.86-.43 9.83 11.53c.59.69 1.56.69 2.14 0L48.66-.43'/%3E%3C/g%3E%3C/svg%3E\");background-position:0 0;background-repeat:no-repeat;background-size:50px 15px;content:\"\";height:15px;position:absolute;top:-10px;width:25px}.EmojiPickerReact.epr-dark-theme .epr-emoji-variation-picker .epr-emoji-pointer{background-position:-25px 0}.EmojiPickerReact .epr-emoji-variation-picker .epr-emoji-pointer{top:100%;transform:translateX(-18px)}.EmojiPickerReact .epr-emoji-variation-picker.pointing-up .epr-emoji-pointer{top:0;transform:rotate(180deg) translateY(100%) translateX(18px)}";
18477
18482
  styleInject(css_248z$3);
18478
18483
 
@@ -18501,10 +18506,16 @@ function EmojiVariationPicker() {
18501
18506
  var getEmojiUrl = useGetEmojiUrlConfig();
18502
18507
  var button = buttonFromTarget(AnchoredEmojiRef.current);
18503
18508
  var visible = emoji && button && emojiHasVariations(emoji) && button.classList.contains(ClassNames.emojiHasVariatios);
18509
+ useEffect(function () {
18510
+ if (!visible) {
18511
+ return;
18512
+ }
18513
+
18514
+ focusFirstVisibleEmoji(VariationPickerRef.current);
18515
+ }, [VariationPickerRef, visible, AnchoredEmojiRef]);
18504
18516
  var top, pointerStyle;
18505
18517
 
18506
18518
  if (!visible && AnchoredEmojiRef.current) {
18507
- focusElement(AnchoredEmojiRef.current);
18508
18519
  setAnchoredEmojiRef(null);
18509
18520
  } else {
18510
18521
  top = getTop();
@@ -18514,7 +18525,7 @@ function EmojiVariationPicker() {
18514
18525
  var safeEmoji = asEmoji(emoji);
18515
18526
  return createElement("div", {
18516
18527
  ref: VariationPickerRef,
18517
- className: clsx('epr-emoji-variation-picker', {
18528
+ className: clsx(ClassNames.variationPicker, {
18518
18529
  visible: visible,
18519
18530
  'pointing-up': getMenuDirection() === Direction.Down
18520
18531
  }),
@@ -19209,7 +19220,7 @@ function useSearchInputKeyboardEvents() {
19209
19220
  break;
19210
19221
  }
19211
19222
  };
19212
- }, [focusSkinTonePicker, goDownFromSearchInput, setSkinToneFanOpenState, BodyRef]);
19223
+ }, [focusSkinTonePicker, goDownFromSearchInput, setSkinToneFanOpenState, BodyRef, isSkinToneInSearch]);
19213
19224
  useEffect(function () {
19214
19225
  var current = SearchInputRef.current;
19215
19226