react-cool-onclickoutside
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -1,1 +0,1 @@ | ||
import{useRef as n,useEffect as e}from"react";var t="ignore-onclickoutside",r=function(n,e){for(var t=n.target;t;){if(t.classList.contains(e))return!0;t=t.parentElement}return!1},i=function(n){return document.documentElement.clientWidth<=n.clientX||document.documentElement.clientHeight<=n.clientY},o=function(n){return!(!n.includes("touch")||!function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var n=!1,e=Object.defineProperty({},"passive",{get:function(){n=!0}}),t=function(){return null};return window.addEventListener("test",t,e),window.removeEventListener("test",t,e),n}())&&{passive:!0}};export default function(t,c){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},d=u.disabled,f=void 0!==d&&d,a=u.eventTypes,s=void 0===a?["mousedown","touchstart"]:a,v=u.excludeScrollbar,l=void 0!==v&&v,m=u.ignoreClass,p=void 0===m?"ignore-onclickoutside":m,E=n(c);e((function(){E.current=c}),[c]),e((function(){if(t){var n=function(n){if(!r(n,p)){var e=Array.isArray(t)?t:[t],o=[];e.forEach((function(n){var e=n.current;e&&o.push(e)})),l&&i(n)||o.length&&o.every((function(e){return!e.contains(n.target)}))&&E.current(n)}},e=function(){s.forEach((function(e){document.removeEventListener(e,n,o(e))}))};if(!f)return s.forEach((function(e){document.addEventListener(e,n,o(e))})),function(){e()};e()}}),[t,p,l,f,s])}export{t as DEFAULT_IGNORE_CLASS}; | ||
import{useRef,useEffect}from"react";var canUsePassiveEvents=function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var e=!1,n=Object.defineProperty({},"passive",{get:function(){e=!0}}),t=function(){return null};return window.addEventListener("test",t,n),window.removeEventListener("test",t,n),e},DEFAULT_IGNORE_CLASS="ignore-onclickoutside",hasIgnoreClass=function(e,n){for(var t=e.target;t;){if(t.classList.contains(n))return!0;t=t.parentElement}return!1},clickedOnScrollbar=function(e){return document.documentElement.clientWidth<=e.clientX||document.documentElement.clientHeight<=e.clientY},getEventOptions=function(e){return!(!e.includes("touch")||!canUsePassiveEvents())&&{passive:!0}},useOnclickOutside=function(e,n){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=t.disabled,r=void 0!==i&&i,o=t.eventTypes,c=void 0===o?["mousedown","touchstart"]:o,u=t.excludeScrollbar,s=void 0!==u&&u,f=t.ignoreClass,a=void 0===f?DEFAULT_IGNORE_CLASS:f,d=useRef(n);useEffect((function(){d.current=n}),[n]),useEffect((function(){if(e){var n=function(n){if(!hasIgnoreClass(n,a)){var t=Array.isArray(e)?e:[e],i=[];t.forEach((function(e){var n=e.current;n&&i.push(n)})),s&&clickedOnScrollbar(n)||i.length&&i.every((function(e){return!e.contains(n.target)}))&&d.current(n)}},t=function(){c.forEach((function(e){document.removeEventListener(e,n,getEventOptions(e))}))};if(!r)return c.forEach((function(e){document.addEventListener(e,n,getEventOptions(e))})),function(){t()};t()}}),[e,a,s,r,c])};export default useOnclickOutside;export{DEFAULT_IGNORE_CLASS}; |
{ | ||
"name": "react-cool-onclickoutside", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "React hook to listen for clicks outside of the component(s).", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
21587
32