@semcore/outside-click
Advanced tools
Comparing version 3.0.0-beta.0 to 3.0.0-beta.1
@@ -26,14 +26,15 @@ "use strict"; | ||
var handleRef = (0, _ref.useForkRef)(children ? children.ref : null, nodeRef, forwardRef); | ||
var handleOutsideClick = (0, _useEventCallback["default"])(function (e) { | ||
var handleOutsideClick = (0, _useEventCallback["default"])(function (event) { | ||
var isTargetEvent = [].concat((0, _toConsumableArray2["default"])(excludeRefs), [nodeRef]).filter(function (node) { | ||
return (0, _ref.getNodeByRef)(node); | ||
}).some(function (node) { | ||
return (0, _ref.getNodeByRef)(node).contains(targetRef.current || e.target); | ||
var _getNodeByRef; | ||
return (_getNodeByRef = (0, _ref.getNodeByRef)(node)) === null || _getNodeByRef === void 0 ? void 0 : _getNodeByRef.contains(targetRef.current || event.target); | ||
}); | ||
if (!isTargetEvent) { | ||
onOutsideClick(e); | ||
onOutsideClick === null || onOutsideClick === void 0 ? void 0 : onOutsideClick(event); | ||
} | ||
}); | ||
var handleMouseDown = (0, _useEventCallback["default"])(function (e) { | ||
targetRef.current = e.target; | ||
var handleMouseDown = (0, _useEventCallback["default"])(function (event) { | ||
targetRef.current = event.target; | ||
}); | ||
@@ -44,7 +45,7 @@ (0, _react.useEffect)(function () { | ||
// Using capture to handle event faster than OutsideClick handler | ||
outsideRoot.addEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot.addEventListener('mousedown', handleMouseDown, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.addEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.addEventListener('mousedown', handleMouseDown, true); | ||
return function () { | ||
outsideRoot.removeEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot.removeEventListener('mousedown', handleMouseDown, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.removeEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.removeEventListener('mousedown', handleMouseDown, true); | ||
}; | ||
@@ -51,0 +52,0 @@ }, [root]); |
@@ -21,14 +21,15 @@ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray"; | ||
var handleRef = useForkRef(children ? children.ref : null, nodeRef, forwardRef); | ||
var handleOutsideClick = useEventCallback(function (e) { | ||
var handleOutsideClick = useEventCallback(function (event) { | ||
var isTargetEvent = [].concat(_toConsumableArray(excludeRefs), [nodeRef]).filter(function (node) { | ||
return getNodeByRef(node); | ||
}).some(function (node) { | ||
return getNodeByRef(node).contains(targetRef.current || e.target); | ||
var _getNodeByRef; | ||
return (_getNodeByRef = getNodeByRef(node)) === null || _getNodeByRef === void 0 ? void 0 : _getNodeByRef.contains(targetRef.current || event.target); | ||
}); | ||
if (!isTargetEvent) { | ||
onOutsideClick(e); | ||
onOutsideClick === null || onOutsideClick === void 0 ? void 0 : onOutsideClick(event); | ||
} | ||
}); | ||
var handleMouseDown = useEventCallback(function (e) { | ||
targetRef.current = e.target; | ||
var handleMouseDown = useEventCallback(function (event) { | ||
targetRef.current = event.target; | ||
}); | ||
@@ -39,7 +40,7 @@ useEffect(function () { | ||
// Using capture to handle event faster than OutsideClick handler | ||
outsideRoot.addEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot.addEventListener('mousedown', handleMouseDown, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.addEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.addEventListener('mousedown', handleMouseDown, true); | ||
return function () { | ||
outsideRoot.removeEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot.removeEventListener('mousedown', handleMouseDown, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.removeEventListener('mouseup', handleOutsideClick, true); | ||
outsideRoot === null || outsideRoot === void 0 ? void 0 : outsideRoot.removeEventListener('mousedown', handleMouseDown, true); | ||
}; | ||
@@ -46,0 +47,0 @@ }, [root]); |
@@ -7,3 +7,3 @@ import React from 'react'; | ||
} | ||
export declare type OutsideClickProps = { | ||
export type OutsideClickProps = { | ||
/** | ||
@@ -10,0 +10,0 @@ * Function called on click outside the component from excludeRefs |
{ | ||
"name": "@semcore/outside-click", | ||
"description": "Semrush OutsideClick Component", | ||
"version": "3.0.0-beta.0", | ||
"version": "3.0.0-beta.1", | ||
"main": "lib/cjs/index.js", | ||
@@ -12,6 +12,6 @@ "module": "lib/es6/index.js", | ||
"dependencies": { | ||
"@semcore/utils": "4.0.0-beta.0" | ||
"@semcore/utils": "4.0.0-beta.1" | ||
}, | ||
"peerDependencies": { | ||
"@semcore/core": "2.0.0-beta.0", | ||
"@semcore/core": "2.0.0-beta.1", | ||
"react": "16.8 - 18", | ||
@@ -18,0 +18,0 @@ "react-dom": "16.8 - 18" |
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
29053
163
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@phytonmk/nano-css@5.3.7(transitive)
+ Added@semcore/core@2.0.0-beta.1(transitive)
+ Added@semcore/utils@4.0.0-beta.1(transitive)
- Removed@semcore/core@2.0.0-beta.0(transitive)
- Removed@semcore/utils@4.0.0-beta.0(transitive)
- Removednano-css@5.3.4(transitive)
- Removedsourcemap-codec@1.4.8(transitive)
Updated@semcore/utils@4.0.0-beta.1