@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/main.js CHANGED
@@ -81,106 +81,6 @@ function $f7e14e656343df57$export$b0d6fa1ab32e3295(target) {
81
81
 
82
82
 
83
83
 
84
-
85
- function $625cf83917e112ad$export$60278871457622de(event) {
86
- // JAWS/NVDA with Firefox.
87
- if (event.mozInputSource === 0 && event.isTrusted) return true;
88
- return event.detail === 0 && !event.pointerType;
89
- }
90
- class $625cf83917e112ad$export$905e7fc544a71f36 {
91
- isDefaultPrevented() {
92
- return this.nativeEvent.defaultPrevented;
93
- }
94
- preventDefault() {
95
- this.defaultPrevented = true;
96
- this.nativeEvent.preventDefault();
97
- }
98
- stopPropagation() {
99
- this.nativeEvent.stopPropagation();
100
- this.isPropagationStopped = ()=>true
101
- ;
102
- }
103
- isPropagationStopped() {
104
- return false;
105
- }
106
- persist() {
107
- }
108
- constructor(type, nativeEvent){
109
- this.nativeEvent = nativeEvent;
110
- this.target = nativeEvent.target;
111
- this.currentTarget = nativeEvent.currentTarget;
112
- this.relatedTarget = nativeEvent.relatedTarget;
113
- this.bubbles = nativeEvent.bubbles;
114
- this.cancelable = nativeEvent.cancelable;
115
- this.defaultPrevented = nativeEvent.defaultPrevented;
116
- this.eventPhase = nativeEvent.eventPhase;
117
- this.isTrusted = nativeEvent.isTrusted;
118
- this.timeStamp = nativeEvent.timeStamp;
119
- this.type = type;
120
- }
121
- }
122
- function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
123
- let stateRef = $goTMa$react.useRef({
124
- isFocused: false,
125
- onBlur: onBlur,
126
- observer: null
127
- });
128
- stateRef.current.onBlur = onBlur;
129
- // Clean up MutationObserver on unmount. See below.
130
- // eslint-disable-next-line arrow-body-style
131
- $goTMa$reactariautils.useLayoutEffect(()=>{
132
- const state = stateRef.current;
133
- return ()=>{
134
- if (state.observer) {
135
- state.observer.disconnect();
136
- state.observer = null;
137
- }
138
- };
139
- }, []);
140
- // This function is called during a React onFocus event.
141
- return $goTMa$react.useCallback((e1)=>{
142
- // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
143
- // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
144
- // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
145
- // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
146
- if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
147
- stateRef.current.isFocused = true;
148
- let target = e1.target;
149
- let onBlurHandler = (e)=>{
150
- var // For backward compatibility, dispatch a (fake) React synthetic event.
151
- _current, ref;
152
- stateRef.current.isFocused = false;
153
- if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $625cf83917e112ad$export$905e7fc544a71f36('blur', e));
154
- // We no longer need the MutationObserver once the target is blurred.
155
- if (stateRef.current.observer) {
156
- stateRef.current.observer.disconnect();
157
- stateRef.current.observer = null;
158
- }
159
- };
160
- target.addEventListener('focusout', onBlurHandler, {
161
- once: true
162
- });
163
- stateRef.current.observer = new MutationObserver(()=>{
164
- if (stateRef.current.isFocused && target.disabled) {
165
- stateRef.current.observer.disconnect();
166
- target.dispatchEvent(new FocusEvent('blur'));
167
- target.dispatchEvent(new FocusEvent('focusout', {
168
- bubbles: true
169
- }));
170
- }
171
- });
172
- stateRef.current.observer.observe(target, {
173
- attributes: true,
174
- attributeFilter: [
175
- 'disabled'
176
- ]
177
- });
178
- }
179
- }, []);
180
- }
181
-
182
-
183
-
184
84
  const $01d3f539e91688c8$export$5165eccb35aaadb5 = ($parcel$interopDefault($goTMa$react)).createContext(null);
185
85
  $01d3f539e91688c8$export$5165eccb35aaadb5.displayName = 'PressResponderContext';
186
86
 
@@ -321,7 +221,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
321
221
  if (isDisabled1) e.preventDefault();
322
222
  // If triggered from a screen reader or by using element.click(),
323
223
  // trigger as if it were a keyboard click.
324
- if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $625cf83917e112ad$export$60278871457622de(e.nativeEvent))) {
224
+ if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && (state.pointerType === 'virtual' || $goTMa$reactariautils.isVirtualClick(e.nativeEvent))) {
325
225
  // Ensure the element receives focus (VoiceOver on iOS does not do this)
326
226
  if (!isDisabled1 && !preventFocusOnPress) $goTMa$reactariautils.focusWithoutScrolling(e.currentTarget);
327
227
  triggerPressStart(e, 'virtual');
@@ -354,7 +254,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
354
254
  // Ignore and let the onClick handler take care of it instead.
355
255
  // https://bugs.webkit.org/show_bug.cgi?id=222627
356
256
  // https://bugs.webkit.org/show_bug.cgi?id=223202
357
- if ($0294ea432cd92340$var$isVirtualPointerEvent(e.nativeEvent)) {
257
+ if ($goTMa$reactariautils.isVirtualPointerEvent(e.nativeEvent)) {
358
258
  state.pointerType = 'virtual';
359
259
  return;
360
260
  }
@@ -442,7 +342,7 @@ function $0294ea432cd92340$export$45712eceda6fad21(props) {
442
342
  state.isPressed = true;
443
343
  state.isOverTarget = true;
444
344
  state.target = e.currentTarget;
445
- state.pointerType = $625cf83917e112ad$export$60278871457622de(e.nativeEvent) ? 'virtual' : 'mouse';
345
+ state.pointerType = $goTMa$reactariautils.isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse';
446
346
  if (!isDisabled1 && !preventFocusOnPress) $goTMa$reactariautils.focusWithoutScrolling(e.currentTarget);
447
347
  triggerPressStart(e, state.pointerType);
448
348
  addGlobalListener(document, 'mouseup', onMouseUp, false);
@@ -652,15 +552,6 @@ function $0294ea432cd92340$var$isValidInputKey(target, key) {
652
552
  // Only space should toggle checkboxes and radios, not enter.
653
553
  return target.type === 'checkbox' || target.type === 'radio' ? key === ' ' : $0294ea432cd92340$var$nonTextInputTypes.has(target.type);
654
554
  }
655
- function $0294ea432cd92340$var$isVirtualPointerEvent(event) {
656
- // If the pointer size is zero, then we assume it's from a screen reader.
657
- // Android TalkBack double tap will sometimes return a event with width and height of 1
658
- // and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
659
- // Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
660
- // instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
661
- // Talkback double tap from Windows Firefox touch screen press
662
- return event.width === 0 && event.height === 0 || event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === 'mouse';
663
- }
664
555
 
665
556
 
666
557
 
@@ -707,6 +598,100 @@ const $3596bae48579386f$export$3351871ee4b288b8 = /*#__PURE__*/ ($parcel$interop
707
598
 
708
599
 
709
600
 
601
+
602
+ class $625cf83917e112ad$export$905e7fc544a71f36 {
603
+ isDefaultPrevented() {
604
+ return this.nativeEvent.defaultPrevented;
605
+ }
606
+ preventDefault() {
607
+ this.defaultPrevented = true;
608
+ this.nativeEvent.preventDefault();
609
+ }
610
+ stopPropagation() {
611
+ this.nativeEvent.stopPropagation();
612
+ this.isPropagationStopped = ()=>true
613
+ ;
614
+ }
615
+ isPropagationStopped() {
616
+ return false;
617
+ }
618
+ persist() {
619
+ }
620
+ constructor(type, nativeEvent){
621
+ this.nativeEvent = nativeEvent;
622
+ this.target = nativeEvent.target;
623
+ this.currentTarget = nativeEvent.currentTarget;
624
+ this.relatedTarget = nativeEvent.relatedTarget;
625
+ this.bubbles = nativeEvent.bubbles;
626
+ this.cancelable = nativeEvent.cancelable;
627
+ this.defaultPrevented = nativeEvent.defaultPrevented;
628
+ this.eventPhase = nativeEvent.eventPhase;
629
+ this.isTrusted = nativeEvent.isTrusted;
630
+ this.timeStamp = nativeEvent.timeStamp;
631
+ this.type = type;
632
+ }
633
+ }
634
+ function $625cf83917e112ad$export$715c682d09d639cc(onBlur) {
635
+ let stateRef = $goTMa$react.useRef({
636
+ isFocused: false,
637
+ onBlur: onBlur,
638
+ observer: null
639
+ });
640
+ stateRef.current.onBlur = onBlur;
641
+ // Clean up MutationObserver on unmount. See below.
642
+ // eslint-disable-next-line arrow-body-style
643
+ $goTMa$reactariautils.useLayoutEffect(()=>{
644
+ const state = stateRef.current;
645
+ return ()=>{
646
+ if (state.observer) {
647
+ state.observer.disconnect();
648
+ state.observer = null;
649
+ }
650
+ };
651
+ }, []);
652
+ // This function is called during a React onFocus event.
653
+ return $goTMa$react.useCallback((e1)=>{
654
+ // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142
655
+ // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a
656
+ // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.
657
+ // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.
658
+ if (e1.target instanceof HTMLButtonElement || e1.target instanceof HTMLInputElement || e1.target instanceof HTMLTextAreaElement || e1.target instanceof HTMLSelectElement) {
659
+ stateRef.current.isFocused = true;
660
+ let target = e1.target;
661
+ let onBlurHandler = (e)=>{
662
+ var // For backward compatibility, dispatch a (fake) React synthetic event.
663
+ _current, ref;
664
+ stateRef.current.isFocused = false;
665
+ if (target.disabled) (ref = (_current = stateRef.current).onBlur) === null || ref === void 0 ? void 0 : ref.call(_current, new $625cf83917e112ad$export$905e7fc544a71f36('blur', e));
666
+ // We no longer need the MutationObserver once the target is blurred.
667
+ if (stateRef.current.observer) {
668
+ stateRef.current.observer.disconnect();
669
+ stateRef.current.observer = null;
670
+ }
671
+ };
672
+ target.addEventListener('focusout', onBlurHandler, {
673
+ once: true
674
+ });
675
+ stateRef.current.observer = new MutationObserver(()=>{
676
+ if (stateRef.current.isFocused && target.disabled) {
677
+ stateRef.current.observer.disconnect();
678
+ target.dispatchEvent(new FocusEvent('blur'));
679
+ target.dispatchEvent(new FocusEvent('focusout', {
680
+ bubbles: true
681
+ }));
682
+ }
683
+ });
684
+ stateRef.current.observer.observe(target, {
685
+ attributes: true,
686
+ attributeFilter: [
687
+ 'disabled'
688
+ ]
689
+ });
690
+ }
691
+ }, []);
692
+ }
693
+
694
+
710
695
  function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
711
696
  let { isDisabled: isDisabled , onFocus: onFocusProp , onBlur: onBlurProp , onFocusChange: onFocusChange } = props;
712
697
  const onBlur = $goTMa$react.useCallback((e)=>{
@@ -742,7 +727,6 @@ function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
742
727
 
743
728
 
744
729
 
745
-
746
730
  let $e77252a287ef94ab$var$currentModality = null;
747
731
  let $e77252a287ef94ab$var$changeHandlers = new Set();
748
732
  let $e77252a287ef94ab$var$hasSetupGlobalListeners = false;
@@ -777,7 +761,7 @@ function $e77252a287ef94ab$var$handlePointerEvent(e) {
777
761
  }
778
762
  }
779
763
  function $e77252a287ef94ab$var$handleClickEvent(e) {
780
- if ($625cf83917e112ad$export$60278871457622de(e)) {
764
+ if ($goTMa$reactariautils.isVirtualClick(e)) {
781
765
  $e77252a287ef94ab$var$hasEventBeforeFocus = true;
782
766
  $e77252a287ef94ab$var$currentModality = 'virtual';
783
767
  }