Socket
Socket
Sign inDemoInstall

@react-aria/interactions

Package Overview
Dependencies
Maintainers
1
Versions
766
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/interactions - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

src/utils.ts

113

dist/main.js

@@ -18,3 +18,4 @@ var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends"));

focusWithoutScrolling,
mergeProps
mergeProps,
runAfterTransition
} = require("@react-aria/utils");

@@ -28,2 +29,31 @@

/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
// Original licensing for the following method can be found in the
// NOTICE file in the root directory of this source tree.
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
// click event. This is a method of inferring such clicks. Every browser except
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
// the quirk that it produces click events that are of type PointerEvent, and
// where only the "virtual" click lacks a pointerType field.
function $eda9c464f45e6c61a293990c493$export$isVirtualClick(event) {
// JAWS/NVDA with Firefox.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
return event.detail === 0 && !event.pointerType;
}
const $c6b6d42ec461c27a6a09002bf49a250e$export$PressResponderContext = _react.createContext(null);

@@ -218,3 +248,3 @@

if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(e.nativeEvent)) {
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && $eda9c464f45e6c61a293990c493$export$isVirtualClick(e.nativeEvent)) {
// Ensure the element receives focus (VoiceOver on iOS does not do this)

@@ -265,7 +295,11 @@ if (!isDisabled) {

setTimeout(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
// Wait for any CSS transitions to complete so we don't recompute style
// for the whole page in the middle of the animation and cause jank.
runAfterTransition(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
});
}, 300);

@@ -400,3 +434,3 @@ };

triggerPressStart(e, $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
triggerPressStart(e, $eda9c464f45e6c61a293990c493$export$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
addGlobalListener(document, 'mouseup', onMouseUp, false);

@@ -425,3 +459,3 @@ };

if (!state.ignoreEmulatedMouseEvents && e.button === 0) {
triggerPressUp(e, $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
triggerPressUp(e, $eda9c464f45e6c61a293990c493$export$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
}

@@ -444,3 +478,3 @@ };

let pointerType = $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(e) ? 'virtual' : 'mouse';
let pointerType = $eda9c464f45e6c61a293990c493$export$isVirtualClick(e) ? 'virtual' : 'mouse';

@@ -595,20 +629,2 @@ if ($ed8d760564e19d8c7d03a6a4$var$isOverTarget(e, state.target)) {

!(role === 'link' && key !== 'Enter');
} // Original licensing for the following method can be found in the
// NOTICE file in the root directory of this source tree.
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
// click event. This is a method of inferring such clicks. Every browser except
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
// the quirk that it produces click events that are of type PointerEvent, and
// where only the "virtual" click lacks a pointerType field.
function $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(event) {
// JAWS/NVDA with Firefox.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
return event.detail === 0 && !event.pointerType;
}

@@ -799,14 +815,2 @@

/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/**

@@ -863,4 +867,2 @@ * This function wraps a React event handler to make stopPropagation the default, and support continuePropagation instead.

// Portions of the code in this file are based on code from react.
// Original licensing for the following can be found in the
// NOTICE file in the root directory of this source tree.

@@ -1017,2 +1019,9 @@ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions

function $b83372066b2b4e1d9257843b2455c$var$handleClickEvent(e) {
if ($eda9c464f45e6c61a293990c493$export$isVirtualClick(e)) {
$b83372066b2b4e1d9257843b2455c$var$hasEventBeforeFocus = true;
$b83372066b2b4e1d9257843b2455c$var$currentModality = 'virtual';
}
}
function $b83372066b2b4e1d9257843b2455c$var$handleFocusEvent(e) {

@@ -1063,3 +1072,4 @@ // Firefox fires two extra focus events when the user first clicks into an iframe:

document.addEventListener('keydown', $b83372066b2b4e1d9257843b2455c$var$handleKeyboardEvent, true);
document.addEventListener('keyup', $b83372066b2b4e1d9257843b2455c$var$handleKeyboardEvent, true); // Register focus events on the window so they are sure to happen
document.addEventListener('keyup', $b83372066b2b4e1d9257843b2455c$var$handleKeyboardEvent, true);
document.addEventListener('click', $b83372066b2b4e1d9257843b2455c$var$handleClickEvent, true); // Register focus events on the window so they are sure to happen
// before React's event listeners (registered on the document).

@@ -1090,2 +1100,15 @@

}
exports.isFocusVisible = isFocusVisible;
function getInteractionModality() {
return $b83372066b2b4e1d9257843b2455c$var$currentModality;
}
exports.getInteractionModality = getInteractionModality;
function setInteractionModality(modality) {
$b83372066b2b4e1d9257843b2455c$var$currentModality = modality;
$b83372066b2b4e1d9257843b2455c$var$triggerChangeHandlers(modality, null);
}
/**

@@ -1096,3 +1119,3 @@ * Keeps state of the current modality.

exports.isFocusVisible = isFocusVisible;
exports.setInteractionModality = setInteractionModality;

@@ -1136,3 +1159,3 @@ function useInteractionModality() {

// typing except for when the Tab and Escape keys are pressed.
if (isTextInput && modality === 'keyboard' && !$b83372066b2b4e1d9257843b2455c$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
if (isTextInput && modality === 'keyboard' && e instanceof KeyboardEvent && !$b83372066b2b4e1d9257843b2455c$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
return;

@@ -1139,0 +1162,0 @@ }

import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends";
import _react, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
import { focusWithoutScrolling, mergeProps } from "@react-aria/utils";
import { focusWithoutScrolling, mergeProps, runAfterTransition } from "@react-aria/utils";
import _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
// Original licensing for the following method can be found in the
// NOTICE file in the root directory of this source tree.
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
// click event. This is a method of inferring such clicks. Every browser except
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
// the quirk that it produces click events that are of type PointerEvent, and
// where only the "virtual" click lacks a pointerType field.
function $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(event) {
// JAWS/NVDA with Firefox.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
return event.detail === 0 && !event.pointerType;
}
const $a3ff51240de6f955c79cf17a88e349$export$PressResponderContext = _react.createContext(null);

@@ -195,3 +224,3 @@

if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(e.nativeEvent)) {
if (!state.ignoreClickAfterPress && !state.ignoreEmulatedMouseEvents && $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e.nativeEvent)) {
// Ensure the element receives focus (VoiceOver on iOS does not do this)

@@ -242,7 +271,11 @@ if (!isDisabled) {

setTimeout(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
// Wait for any CSS transitions to complete so we don't recompute style
// for the whole page in the middle of the animation and cause jank.
runAfterTransition(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
});
}, 300);

@@ -377,3 +410,3 @@ };

triggerPressStart(e, $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
triggerPressStart(e, $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
addGlobalListener(document, 'mouseup', onMouseUp, false);

@@ -402,3 +435,3 @@ };

if (!state.ignoreEmulatedMouseEvents && e.button === 0) {
triggerPressUp(e, $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
triggerPressUp(e, $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse');
}

@@ -421,3 +454,3 @@ };

let pointerType = $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(e) ? 'virtual' : 'mouse';
let pointerType = $f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e) ? 'virtual' : 'mouse';

@@ -570,20 +603,2 @@ if ($ffc54430b1dbeee65879852feaaff07d$var$isOverTarget(e, state.target)) {

!(role === 'link' && key !== 'Enter');
} // Original licensing for the following method can be found in the
// NOTICE file in the root directory of this source tree.
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
// click event. This is a method of inferring such clicks. Every browser except
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
// the quirk that it produces click events that are of type PointerEvent, and
// where only the "virtual" click lacks a pointerType field.
function $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(event) {
// JAWS/NVDA with Firefox.
if (event.mozInputSource === 0 && event.isTrusted) {
return true;
}
return event.detail === 0 && !event.pointerType;
}

@@ -767,14 +782,2 @@

/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/**

@@ -828,4 +831,2 @@ * This function wraps a React event handler to make stopPropagation the default, and support continuePropagation instead.

}
// Portions of the code in this file are based on code from react.
// Original licensing for the following can be found in the
// NOTICE file in the root directory of this source tree.

@@ -978,2 +979,9 @@ // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions

function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleClickEvent(e) {
if ($f67ef9f1b8ed09b4b00fd0840cd8b94b$export$isVirtualClick(e)) {
$d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;
$d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = 'virtual';
}
}
function $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleFocusEvent(e) {

@@ -1024,3 +1032,4 @@ // Firefox fires two extra focus events when the user first clicks into an iframe:

document.addEventListener('keydown', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent, true);
document.addEventListener('keyup', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent, true); // Register focus events on the window so they are sure to happen
document.addEventListener('keyup', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleKeyboardEvent, true);
document.addEventListener('click', $d01f69bb2ab5f70dfd0005370a2a2cbc$var$handleClickEvent, true); // Register focus events on the window so they are sure to happen
// before React's event listeners (registered on the document).

@@ -1051,2 +1060,9 @@

}
export function getInteractionModality() {
return $d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality;
}
export function setInteractionModality(modality) {
$d01f69bb2ab5f70dfd0005370a2a2cbc$var$currentModality = modality;
$d01f69bb2ab5f70dfd0005370a2a2cbc$var$triggerChangeHandlers(modality, null);
}
/**

@@ -1090,3 +1106,3 @@ * Keeps state of the current modality.

// typing except for when the Tab and Escape keys are pressed.
if (isTextInput && modality === 'keyboard' && !$d01f69bb2ab5f70dfd0005370a2a2cbc$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
if (isTextInput && modality === 'keyboard' && e instanceof KeyboardEvent && !$d01f69bb2ab5f70dfd0005370a2a2cbc$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
return;

@@ -1093,0 +1109,0 @@ }

@@ -85,3 +85,3 @@ import React, { HTMLAttributes, RefObject, SyntheticEvent, ReactElement, ReactNode, FocusEvent } from "react";

export function useFocusWithin(props: FocusWithinProps): FocusWithinResult;
type Modality = 'keyboard' | 'pointer';
type Modality = 'keyboard' | 'pointer' | 'virtual';
interface FocusVisibleProps {

@@ -101,2 +101,4 @@ /** Whether the element is a text input. */

export function isFocusVisible(): boolean;
export function getInteractionModality(): Modality;
export function setInteractionModality(modality: Modality): void;
/**

@@ -103,0 +105,0 @@ * Keeps state of the current modality.

{
"name": "@react-aria/interactions",
"version": "3.1.0",
"version": "3.2.0",
"description": "Spectrum UI components in React",

@@ -21,4 +21,4 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-aria/utils": "^3.1.0",
"@react-types/shared": "^3.1.0"
"@react-aria/utils": "^3.2.0",
"@react-types/shared": "^3.2.0"
},

@@ -31,3 +31,3 @@ "peerDependencies": {

},
"gitHead": "211099972fe75ee581892efd01a7f89dfb9cdf69"
"gitHead": "661f0f2e3b8648a75aae83043267954700059fe0"
}

@@ -18,5 +18,6 @@ /*

import {isVirtualClick} from './utils';
import {useEffect, useState} from 'react';
type Modality = 'keyboard' | 'pointer';
type Modality = 'keyboard' | 'pointer' | 'virtual';
type HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent;

@@ -81,2 +82,9 @@ type Handler = (modality: Modality, e: HandlerEvent) => void;

function handleClickEvent(e: MouseEvent) {
if (isVirtualClick(e)) {
hasEventBeforeFocus = true;
currentModality = 'virtual';
}
}
function handleFocusEvent(e: FocusEvent) {

@@ -126,2 +134,3 @@ // Firefox fires two extra focus events when the user first clicks into an iframe:

document.addEventListener('keyup', handleKeyboardEvent, true);
document.addEventListener('click', handleClickEvent, true);

@@ -153,2 +162,11 @@ // Register focus events on the window so they are sure to happen

export function getInteractionModality(): Modality {
return currentModality;
}
export function setInteractionModality(modality: Modality) {
currentModality = modality;
triggerChangeHandlers(modality, null);
}
/**

@@ -184,6 +202,6 @@ * Keeps state of the current modality.

useEffect(() => {
let handler = (modality, e) => {
let handler = (modality: Modality, e: HandlerEvent) => {
// If this is a text input component, don't update the focus visible style when
// typing except for when the Tab and Escape keys are pressed.
if (isTextInput && modality === 'keyboard' && !FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
if (isTextInput && modality === 'keyboard' && e instanceof KeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]) {
return;

@@ -190,0 +208,0 @@ }

@@ -18,4 +18,5 @@ /*

import {focusWithoutScrolling, mergeProps} from '@react-aria/utils';
import {focusWithoutScrolling, mergeProps, runAfterTransition} from '@react-aria/utils';
import {HTMLAttributes, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {isVirtualClick} from './utils';
import {PointerType, PressEvents} from '@react-types/shared';

@@ -281,7 +282,11 @@ import {PressResponderContext} from './context';

setTimeout(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
// Wait for any CSS transitions to complete so we don't recompute style
// for the whole page in the middle of the animation and cause jank.
runAfterTransition(() => {
// Avoid race conditions
if (!state.isPressed && document.documentElement.style.webkitUserSelect === 'none') {
document.documentElement.style.webkitUserSelect = state.userSelect || '';
state.userSelect = null;
}
});
}, 300);

@@ -602,22 +607,2 @@ };

// Original licensing for the following method can be found in the
// NOTICE file in the root directory of this source tree.
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
// click event. This is a method of inferring such clicks. Every browser except
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
// the quirk that it produces click events that are of type PointerEvent, and
// where only the "virtual" click lacks a pointerType field.
function isVirtualClick(event: MouseEvent | PointerEvent): boolean {
// JAWS/NVDA with Firefox.
if ((event as any).mozInputSource === 0 && event.isTrusted) {
return true;
}
return event.detail === 0 && !(event as PointerEvent).pointerType;
}
function getTouchFromEvent(event: TouchEvent): Touch | null {

@@ -624,0 +609,0 @@ const {targetTouches} = event;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc