@react-aria/interactions 3.11.0 → 3.12.0

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.
package/dist/module.js CHANGED
@@ -1,4 +1,4 @@
1
- import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
1
+ import {mergeProps as $bx7SL$mergeProps, useSyncRef as $bx7SL$useSyncRef, useGlobalListeners as $bx7SL$useGlobalListeners, isVirtualClick as $bx7SL$isVirtualClick, focusWithoutScrolling as $bx7SL$focusWithoutScrolling, isVirtualPointerEvent as $bx7SL$isVirtualPointerEvent, isIOS as $bx7SL$isIOS, runAfterTransition as $bx7SL$runAfterTransition, useLayoutEffect as $bx7SL$useLayoutEffect, isMac as $bx7SL$isMac, useEvent as $bx7SL$useEvent, useDescription as $bx7SL$useDescription} from "@react-aria/utils";
2
2
  import $bx7SL$react, {useRef as $bx7SL$useRef, useContext as $bx7SL$useContext, useState as $bx7SL$useState, useMemo as $bx7SL$useMemo, useEffect as $bx7SL$useEffect, useCallback as $bx7SL$useCallback} from "react";
3
3
 
4
4
 
@@ -57,106 +57,6 @@ function $14c0b72509d70225$export$b0d6fa1ab32e3295(target) {
57
57
 
58
58
 
59
59
 
60
-
61
- function $8a9cb279dc87e130$export$60278871457622de(event) {
62
- // JAWS/NVDA with Firefox.
63
- if (event.mozInputSource === 0 && event.isTrusted) return true;
64
- return event.detail === 0 && !event.pointerType;
65
- }
66
- class $8a9cb279dc87e130$export$905e7fc544a71f36 {
67
- isDefaultPrevented() {
68
- return this.nativeEvent.defaultPrevented;
69
- }
70
- preventDefault() {
71
- this.defaultPrevented = true;
72
- this.nativeEvent.preventDefault();
73
- }
74
- stopPropagation() {
75
- this.nativeEvent.stopPropagation();
76
- this.isPropagationStopped = ()=>true
77
- ;
78
- }
79
- isPropagationStopped() {
80
- return false;
81
- }
82
- persist() {
83
- }
84
- constructor(type, nativeEvent){
85
- this.nativeEvent = nativeEvent;
86
- this.target = nativeEvent.target;
87
- this.currentTarget = nativeEvent.currentTarget;
88
- this.relatedTarget = nativeEvent.relatedTarget;
89
- this.bubbles = nativeEvent.bubbles;
90
- this.cancelable = nativeEvent.cancelable;
91
- this.defaultPrevented = nativeEvent.defaultPrevented;
92
- this.eventPhase = nativeEvent.eventPhase;
93
- this.isTrusted = nativeEvent.isTrusted;
94
- this.timeStamp = nativeEvent.timeStamp;
95
- this.type = type;
96
- }
97
- }
98
- function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
99
- let stateRef = $bx7SL$useRef({
100
- isFocused: false,
101
- onBlur: onBlur,
102
- observer: null
103
- });
104
- stateRef.current.onBlur = onBlur;
105
- // Clean up MutationObserver on unmount. See below.
106
- // eslint-disable-next-line arrow-body-style
107
- $bx7SL$useLayoutEffect(()=>{
108
- const state = stateRef.current;
109
- return ()=>{
110
- if (state.observer) {
111
- state.observer.disconnect();
112
- state.observer = null;
113
- }
114
- };
115
- }, []);
116
- // This function is called during a React onFocus event.
117
- return $bx7SL$useCallback((e1)=>{
118
- // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
119
- // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
120
- // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
121
- // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
122
- if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
123
- stateRef.current.isFocused = true;
124
- let target = e1.target;
125
- let onBlurHandler = (e)=>{
126
- var // For backward compatibility, dispatch a (fake) React synthetic event.
127
- _current, ref;
128
- stateRef.current.isFocused = false;
129
- if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
130
- // We no longer need the MutationObserver once the target is blurred.
131
- if (stateRef.current.observer) {
132
- stateRef.current.observer.disconnect();
133
- stateRef.current.observer = null;
134
- }
135
- };
136
- target.addEventListener('focusout', onBlurHandler, {
137
- once: true
138
- });
139
- stateRef.current.observer = new MutationObserver(()=>{
140
- if (stateRef.current.isFocused && target.disabled) {
141
- stateRef.current.observer.disconnect();
142
- target.dispatchEvent(new FocusEvent('blur'));
143
- target.dispatchEvent(new FocusEvent('focusout', {
144
- bubbles: true
145
- }));
146
- }
147
- });
148
- stateRef.current.observer.observe(target, {
149
- attributes: true,
150
- attributeFilter: [
151
- 'disabled'
152
- ]
153
- });
154
- }
155
- }, []);
156
- }
157
-
158
-
159
-
160
60
  const $ae1eeba8b9eafd08$export$5165eccb35aaadb5 = $bx7SL$react.createContext(null);
161
61
  $ae1eeba8b9eafd08$export$5165eccb35aaadb5.displayName = 'PressResponderContext';
162
62
 
@@ -297,7 +197,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
297
197
  if (isDisabled1) e.preventDefault();
298
198
  // If triggered from a screen reader or by using element.click(),
299
199
  // trigger as if it were a keyboard click.
300
- if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $8a9cb279dc87e130$export$60278871457622de(e.nativeEvent))) {
200
+ if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $bx7SL$isVirtualClick(e.nativeEvent))) {
301
201
  // Ensure the element receives focus (VoiceOver on iOS does not do this)
302
202
  if (!isDisabled1 && !preventFocusOnPress) $bx7SL$focusWithoutScrolling(e.currentTarget);
303
203
  triggerPressStart(e, 'virtual');
@@ -330,7 +230,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
330
230
  // Ignore and let the onClick handler take care of it instead.
331
231
  // https://bugs.webkit.org/show_bug.cgi?id=222627
332
232
  // https://bugs.webkit.org/show_bug.cgi?id=223202
333
- if ($f6c31cce2adf654f$var$isVirtualPointerEvent(e.nativeEvent)) {
233
+ if ($bx7SL$isVirtualPointerEvent(e.nativeEvent)) {
334
234
  state.pointerType = 'virtual';
335
235
  return;
336
236
  }
@@ -418,7 +318,7 @@ function $f6c31cce2adf654f$export$45712eceda6fad21(props) {
418
318
  state.isPressed = true;
419
319
  state.isOverTarget = true;
420
320
  state.target = e.currentTarget;
421
- state.pointerType = $8a9cb279dc87e130$export$60278871457622de(e.nativeEvent) ? 'virtual' : 'mouse';
321
+ state.pointerType = $bx7SL$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse';
422
322
  if (!isDisabled1 && !preventFocusOnPress) $bx7SL$focusWithoutScrolling(e.currentTarget);
423
323
  triggerPressStart(e, state.pointerType);
424
324
  addGlobalListener(document, 'mouseup', onMouseUp, false);
@@ -628,15 +528,6 @@ function $f6c31cce2adf654f$var$isValidInputKey(target, key) {
628
528
  // Only space should toggle checkboxes and radios, not enter.
629
529
  return target.type === 'checkbox' || target.type === 'radio' ? key === ' ' : $f6c31cce2adf654f$var$nonTextInputTypes.has(target.type);
630
530
  }
631
- function $f6c31cce2adf654f$var$isVirtualPointerEvent(event) {
632
- // If the pointer size is zero, then we assume it's from a screen reader.
633
- // Android TalkBack double tap will sometimes return a event with width and height of 1
634
- // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
635
- // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
636
- // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
637
- // Talkback double tap from Windows Firefox touch screen press
638
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse';
639
- }
640
531
 
641
532
 
642
533
 
@@ -683,6 +574,100 @@ const $f1ab8c75478c6f73$export$3351871ee4b288b8 = /*#__PURE__*/ $bx7SL$react.for
683
574
 
684
575
 
685
576
 
577
+
578
+ class $8a9cb279dc87e130$export$905e7fc544a71f36 {
579
+ isDefaultPrevented() {
580
+ return this.nativeEvent.defaultPrevented;
581
+ }
582
+ preventDefault() {
583
+ this.defaultPrevented = true;
584
+ this.nativeEvent.preventDefault();
585
+ }
586
+ stopPropagation() {
587
+ this.nativeEvent.stopPropagation();
588
+ this.isPropagationStopped = ()=>true
589
+ ;
590
+ }
591
+ isPropagationStopped() {
592
+ return false;
593
+ }
594
+ persist() {
595
+ }
596
+ constructor(type, nativeEvent){
597
+ this.nativeEvent = nativeEvent;
598
+ this.target = nativeEvent.target;
599
+ this.currentTarget = nativeEvent.currentTarget;
600
+ this.relatedTarget = nativeEvent.relatedTarget;
601
+ this.bubbles = nativeEvent.bubbles;
602
+ this.cancelable = nativeEvent.cancelable;
603
+ this.defaultPrevented = nativeEvent.defaultPrevented;
604
+ this.eventPhase = nativeEvent.eventPhase;
605
+ this.isTrusted = nativeEvent.isTrusted;
606
+ this.timeStamp = nativeEvent.timeStamp;
607
+ this.type = type;
608
+ }
609
+ }
610
+ function $8a9cb279dc87e130$export$715c682d09d639cc(onBlur) {
611
+ let stateRef = $bx7SL$useRef({
612
+ isFocused: false,
613
+ onBlur: onBlur,
614
+ observer: null
615
+ });
616
+ stateRef.current.onBlur = onBlur;
617
+ // Clean up MutationObserver on unmount. See below.
618
+ // eslint-disable-next-line arrow-body-style
619
+ $bx7SL$useLayoutEffect(()=>{
620
+ const state = stateRef.current;
621
+ return ()=>{
622
+ if (state.observer) {
623
+ state.observer.disconnect();
624
+ state.observer = null;
625
+ }
626
+ };
627
+ }, []);
628
+ // This function is called during a React onFocus event.
629
+ return $bx7SL$useCallback((e1)=>{
630
+ // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
631
+ // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
632
+ // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
633
+ // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
634
+ if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
635
+ stateRef.current.isFocused = true;
636
+ let target = e1.target;
637
+ let onBlurHandler = (e)=>{
638
+ var // For backward compatibility, dispatch a (fake) React synthetic event.
639
+ _current, ref;
640
+ stateRef.current.isFocused = false;
641
+ if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $8a9cb279dc87e130$export$905e7fc544a71f36('blur', e));
642
+ // We no longer need the MutationObserver once the target is blurred.
643
+ if (stateRef.current.observer) {
644
+ stateRef.current.observer.disconnect();
645
+ stateRef.current.observer = null;
646
+ }
647
+ };
648
+ target.addEventListener('focusout', onBlurHandler, {
649
+ once: true
650
+ });
651
+ stateRef.current.observer = new MutationObserver(()=>{
652
+ if (stateRef.current.isFocused && target.disabled) {
653
+ stateRef.current.observer.disconnect();
654
+ target.dispatchEvent(new FocusEvent('blur'));
655
+ target.dispatchEvent(new FocusEvent('focusout', {
656
+ bubbles: true
657
+ }));
658
+ }
659
+ });
660
+ stateRef.current.observer.observe(target, {
661
+ attributes: true,
662
+ attributeFilter: [
663
+ 'disabled'
664
+ ]
665
+ });
666
+ }
667
+ }, []);
668
+ }
669
+
670
+
686
671
  function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
687
672
  let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
688
673
  const onBlur = $bx7SL$useCallback((e)=>{
@@ -718,7 +703,6 @@ function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
718
703
 
719
704
 
720
705
 
721
-
722
706
  let $507fabe10e71c6fb$var$currentModality = null;
723
707
  let $507fabe10e71c6fb$var$changeHandlers = new Set();
724
708
  let $507fabe10e71c6fb$var$hasSetupGlobalListeners = false;
@@ -753,7 +737,7 @@ function $507fabe10e71c6fb$var$handlePointerEvent(e) {
753
737
  }
754
738
  }
755
739
  function $507fabe10e71c6fb$var$handleClickEvent(e) {
756
- if ($8a9cb279dc87e130$export$60278871457622de(e)) {
740
+ if ($bx7SL$isVirtualClick(e)) {
757
741
  $507fabe10e71c6fb$var$hasEventBeforeFocus = true;
758
742
  $507fabe10e71c6fb$var$currentModality = 'virtual';
759
743
  }