@react-aria/interactions
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -8,2 +8,3 @@ var _babelRuntimeHelpersExtends = $parcel$interopDefault(require("@babel/runtime/helpers/extends")); | ||
var { | ||
useCallback, | ||
useContext, | ||
@@ -85,2 +86,15 @@ useEffect, | ||
}); | ||
let globalListeners = useRef(new Map()); | ||
let addGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
globalListeners.current.set(listener, { | ||
type, | ||
eventTarget, | ||
options | ||
}); | ||
eventTarget.addEventListener(type, listener, options); | ||
}, [globalListeners.current]); | ||
let removeGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
eventTarget.removeEventListener(type, listener, options); | ||
globalListeners.current.delete(listener); | ||
}, [globalListeners.current]); | ||
let pressProps = useMemo(() => { | ||
@@ -183,3 +197,3 @@ let state = ref.current; | ||
document.addEventListener('keyup', onKeyUp, false); | ||
addGlobalListener(document, 'keyup', onKeyUp, false); | ||
} | ||
@@ -229,3 +243,3 @@ } | ||
triggerPressEnd($ed8d760564e19d8c7d03a6a4$var$createEvent(state.target, e), 'keyboard', e.target === state.target); | ||
document.removeEventListener('keyup', onKeyUp, false); // If the target is a link, trigger the click method to open the URL, | ||
removeGlobalListener(document, 'keyup', onKeyUp, false); // If the target is a link, trigger the click method to open the URL, | ||
// but defer triggering pressEnd until onClick event handler. | ||
@@ -284,5 +298,5 @@ | ||
triggerPressStart(e, e.pointerType); | ||
document.addEventListener('pointermove', onPointerMove, false); | ||
document.addEventListener('pointerup', onPointerUp, false); | ||
document.addEventListener('pointercancel', onPointerCancel, false); | ||
addGlobalListener(document, 'pointermove', onPointerMove, false); | ||
addGlobalListener(document, 'pointerup', onPointerUp, false); | ||
addGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
} | ||
@@ -301,5 +315,5 @@ }; | ||
let unbindEvents = () => { | ||
document.removeEventListener('pointermove', onPointerMove, false); | ||
document.removeEventListener('pointerup', onPointerUp, false); | ||
document.removeEventListener('pointercancel', onPointerCancel, false); | ||
removeGlobalListener(document, 'pointermove', onPointerMove, false); | ||
removeGlobalListener(document, 'pointerup', onPointerUp, false); | ||
removeGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
}; | ||
@@ -389,3 +403,3 @@ | ||
triggerPressStart(e, $ed8d760564e19d8c7d03a6a4$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse'); | ||
document.addEventListener('mouseup', onMouseUp, false); | ||
addGlobalListener(document, 'mouseup', onMouseUp, false); | ||
}; | ||
@@ -424,3 +438,3 @@ | ||
state.isPressed = false; | ||
document.removeEventListener('mouseup', onMouseUp, false); | ||
removeGlobalListener(document, 'mouseup', onMouseUp, false); | ||
@@ -464,3 +478,3 @@ if (state.ignoreEmulatedMouseEvents) { | ||
triggerPressStart(e, 'touch'); | ||
window.addEventListener('scroll', onScroll, true); | ||
addGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -509,3 +523,3 @@ | ||
restoreTextSelection(); | ||
window.removeEventListener('scroll', onScroll, true); | ||
removeGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -546,3 +560,11 @@ | ||
return pressProps; | ||
}, [onPress, onPressStart, onPressEnd, onPressChange, onPressUp, isDisabled]); | ||
}, [onPress, onPressStart, onPressEnd, onPressChange, onPressUp, isDisabled]); // eslint-disable-next-line arrow-body-style | ||
useEffect(() => { | ||
return () => { | ||
globalListeners.current.forEach((value, key) => { | ||
removeGlobalListener(value.eventTarget, value.type, key, value.options); | ||
}); | ||
}; | ||
}, [globalListeners.current]); | ||
return { | ||
@@ -707,2 +729,11 @@ isPressed: isPressedProp || isPressed, | ||
return false; | ||
} // if the event target is no longer in the document | ||
if (event.target) { | ||
const ownerDocument = event.target.ownerDocument; | ||
if (!ownerDocument || !ownerDocument.body.contains(event.target)) { | ||
return false; | ||
} | ||
} | ||
@@ -709,0 +740,0 @@ |
import _babelRuntimeHelpersEsmExtends from "@babel/runtime/helpers/esm/extends"; | ||
import _react, { useContext, useEffect, useMemo, useRef, useState } from "react"; | ||
import _react, { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react"; | ||
import { focusWithoutScrolling, mergeProps } from "@react-aria/utils"; | ||
@@ -64,2 +64,15 @@ import _babelRuntimeHelpersEsmObjectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; | ||
}); | ||
let globalListeners = useRef(new Map()); | ||
let addGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
globalListeners.current.set(listener, { | ||
type, | ||
eventTarget, | ||
options | ||
}); | ||
eventTarget.addEventListener(type, listener, options); | ||
}, [globalListeners.current]); | ||
let removeGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
eventTarget.removeEventListener(type, listener, options); | ||
globalListeners.current.delete(listener); | ||
}, [globalListeners.current]); | ||
let pressProps = useMemo(() => { | ||
@@ -162,3 +175,3 @@ let state = ref.current; | ||
document.addEventListener('keyup', onKeyUp, false); | ||
addGlobalListener(document, 'keyup', onKeyUp, false); | ||
} | ||
@@ -208,3 +221,3 @@ } | ||
triggerPressEnd($ffc54430b1dbeee65879852feaaff07d$var$createEvent(state.target, e), 'keyboard', e.target === state.target); | ||
document.removeEventListener('keyup', onKeyUp, false); // If the target is a link, trigger the click method to open the URL, | ||
removeGlobalListener(document, 'keyup', onKeyUp, false); // If the target is a link, trigger the click method to open the URL, | ||
// but defer triggering pressEnd until onClick event handler. | ||
@@ -263,5 +276,5 @@ | ||
triggerPressStart(e, e.pointerType); | ||
document.addEventListener('pointermove', onPointerMove, false); | ||
document.addEventListener('pointerup', onPointerUp, false); | ||
document.addEventListener('pointercancel', onPointerCancel, false); | ||
addGlobalListener(document, 'pointermove', onPointerMove, false); | ||
addGlobalListener(document, 'pointerup', onPointerUp, false); | ||
addGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
} | ||
@@ -280,5 +293,5 @@ }; | ||
let unbindEvents = () => { | ||
document.removeEventListener('pointermove', onPointerMove, false); | ||
document.removeEventListener('pointerup', onPointerUp, false); | ||
document.removeEventListener('pointercancel', onPointerCancel, false); | ||
removeGlobalListener(document, 'pointermove', onPointerMove, false); | ||
removeGlobalListener(document, 'pointerup', onPointerUp, false); | ||
removeGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
}; | ||
@@ -368,3 +381,3 @@ | ||
triggerPressStart(e, $ffc54430b1dbeee65879852feaaff07d$var$isVirtualClick(e.nativeEvent) ? 'virtual' : 'mouse'); | ||
document.addEventListener('mouseup', onMouseUp, false); | ||
addGlobalListener(document, 'mouseup', onMouseUp, false); | ||
}; | ||
@@ -403,3 +416,3 @@ | ||
state.isPressed = false; | ||
document.removeEventListener('mouseup', onMouseUp, false); | ||
removeGlobalListener(document, 'mouseup', onMouseUp, false); | ||
@@ -443,3 +456,3 @@ if (state.ignoreEmulatedMouseEvents) { | ||
triggerPressStart(e, 'touch'); | ||
window.addEventListener('scroll', onScroll, true); | ||
addGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -488,3 +501,3 @@ | ||
restoreTextSelection(); | ||
window.removeEventListener('scroll', onScroll, true); | ||
removeGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -525,3 +538,11 @@ | ||
return pressProps; | ||
}, [onPress, onPressStart, onPressEnd, onPressChange, onPressUp, isDisabled]); | ||
}, [onPress, onPressStart, onPressEnd, onPressChange, onPressUp, isDisabled]); // eslint-disable-next-line arrow-body-style | ||
useEffect(() => { | ||
return () => { | ||
globalListeners.current.forEach((value, key) => { | ||
removeGlobalListener(value.eventTarget, value.type, key, value.options); | ||
}); | ||
}; | ||
}, [globalListeners.current]); | ||
return { | ||
@@ -682,2 +703,11 @@ isPressed: isPressedProp || isPressed, | ||
return false; | ||
} // if the event target is no longer in the document | ||
if (event.target) { | ||
const ownerDocument = event.target.ownerDocument; | ||
if (!ownerDocument || !ownerDocument.body.contains(event.target)) { | ||
return false; | ||
} | ||
} | ||
@@ -684,0 +714,0 @@ |
{ | ||
"name": "@react-aria/interactions", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Spectrum UI components in React", | ||
@@ -17,8 +17,8 @@ "license": "Apache-2.0", | ||
"type": "git", | ||
"url": "https://github.com/adobe-private/react-spectrum-v3" | ||
"url": "https://github.com/adobe/react-spectrum" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.6.2", | ||
"@react-aria/utils": "^3.0.0", | ||
"@react-types/shared": "^3.0.0" | ||
"@react-aria/utils": "^3.0.1", | ||
"@react-types/shared": "^3.0.1" | ||
}, | ||
@@ -31,3 +31,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "a32224fdf009d69cf594f32ad18ac86d7ebb8a52" | ||
"gitHead": "ac0b7a7ba0edccd1c9ab4f849022ad6d2ccd19ed" | ||
} |
# @react-aria/interactions | ||
This package is part of [react-spectrum](https://github.com/adobe-private/react-spectrum-v3). See the repo for more details. | ||
This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details. |
@@ -94,3 +94,11 @@ /* | ||
// if the event target is no longer in the document | ||
if (event.target) { | ||
const ownerDocument = event.target.ownerDocument; | ||
if (!ownerDocument || !ownerDocument.body.contains(event.target)) { | ||
return false; | ||
} | ||
} | ||
return ref.current && !ref.current.contains(event.target); | ||
} |
@@ -19,3 +19,3 @@ /* | ||
import {focusWithoutScrolling, mergeProps} from '@react-aria/utils'; | ||
import {HTMLAttributes, RefObject, useContext, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {HTMLAttributes, RefObject, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react'; | ||
import {PointerType, PressEvents} from '@react-types/shared'; | ||
@@ -111,2 +111,12 @@ import {PressResponderContext} from './context'; | ||
let globalListeners = useRef(new Map()); | ||
let addGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
globalListeners.current.set(listener, {type, eventTarget, options}); | ||
eventTarget.addEventListener(type, listener, options); | ||
}, [globalListeners.current]); | ||
let removeGlobalListener = useCallback((eventTarget, type, listener, options) => { | ||
eventTarget.removeEventListener(type, listener, options); | ||
globalListeners.current.delete(listener); | ||
}, [globalListeners.current]); | ||
let pressProps = useMemo(() => { | ||
@@ -207,3 +217,3 @@ let state = ref.current; | ||
// instead of the same element where the key down event occurred. | ||
document.addEventListener('keyup', onKeyUp, false); | ||
addGlobalListener(document, 'keyup', onKeyUp, false); | ||
} | ||
@@ -250,3 +260,3 @@ } | ||
triggerPressEnd(createEvent(state.target, e), 'keyboard', e.target === state.target); | ||
document.removeEventListener('keyup', onKeyUp, false); | ||
removeGlobalListener(document, 'keyup', onKeyUp, false); | ||
@@ -306,5 +316,5 @@ // If the target is a link, trigger the click method to open the URL, | ||
document.addEventListener('pointermove', onPointerMove, false); | ||
document.addEventListener('pointerup', onPointerUp, false); | ||
document.addEventListener('pointercancel', onPointerCancel, false); | ||
addGlobalListener(document, 'pointermove', onPointerMove, false); | ||
addGlobalListener(document, 'pointerup', onPointerUp, false); | ||
addGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
} | ||
@@ -323,5 +333,5 @@ }; | ||
let unbindEvents = () => { | ||
document.removeEventListener('pointermove', onPointerMove, false); | ||
document.removeEventListener('pointerup', onPointerUp, false); | ||
document.removeEventListener('pointercancel', onPointerCancel, false); | ||
removeGlobalListener(document, 'pointermove', onPointerMove, false); | ||
removeGlobalListener(document, 'pointerup', onPointerUp, false); | ||
removeGlobalListener(document, 'pointercancel', onPointerCancel, false); | ||
}; | ||
@@ -410,3 +420,3 @@ | ||
document.addEventListener('mouseup', onMouseUp, false); | ||
addGlobalListener(document, 'mouseup', onMouseUp, false); | ||
}; | ||
@@ -443,3 +453,3 @@ | ||
state.isPressed = false; | ||
document.removeEventListener('mouseup', onMouseUp, false); | ||
removeGlobalListener(document, 'mouseup', onMouseUp, false); | ||
@@ -482,3 +492,3 @@ if (state.ignoreEmulatedMouseEvents) { | ||
window.addEventListener('scroll', onScroll, true); | ||
addGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -523,3 +533,3 @@ | ||
restoreTextSelection(); | ||
window.removeEventListener('scroll', onScroll, true); | ||
removeGlobalListener(window, 'scroll', onScroll, true); | ||
}; | ||
@@ -561,2 +571,11 @@ | ||
// eslint-disable-next-line arrow-body-style | ||
useEffect(() => { | ||
return () => { | ||
globalListeners.current.forEach((value, key) => { | ||
removeGlobalListener(value.eventTarget, value.type, key, value.options); | ||
}); | ||
}; | ||
}, [globalListeners.current]); | ||
return { | ||
@@ -563,0 +582,0 @@ isPressed: isPressedProp || isPressed, |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315620
3423
Updated@react-aria/utils@^3.0.1
Updated@react-types/shared@^3.0.1