react-cool-onclickoutside
Advanced tools
Comparing version 1.6.0 to 1.6.1
@@ -50,8 +50,6 @@ import { useRef, useState, useEffect, useCallback } from 'react'; | ||
refsOpt = _ref.refs, | ||
_ref$disabled = _ref.disabled, | ||
disabled = _ref$disabled === void 0 ? false : _ref$disabled, | ||
disabled = _ref.disabled, | ||
_ref$eventTypes = _ref.eventTypes, | ||
eventTypes = _ref$eventTypes === void 0 ? ["mousedown", "touchstart"] : _ref$eventTypes, | ||
_ref$excludeScrollbar = _ref.excludeScrollbar, | ||
excludeScrollbar = _ref$excludeScrollbar === void 0 ? false : _ref$excludeScrollbar, | ||
excludeScrollbar = _ref.excludeScrollbar, | ||
_ref$ignoreClass = _ref.ignoreClass, | ||
@@ -80,10 +78,14 @@ ignoreClass = _ref$ignoreClass === void 0 ? DEFAULT_IGNORE_CLASS : _ref$ignoreClass, | ||
if (!(refsOpt != null && refsOpt.length) && !refsState.length) return; | ||
var els = []; | ||
(refsOpt || refsState).forEach(function (_ref2) { | ||
var current = _ref2.current; | ||
return current && els.push(current); | ||
}); | ||
var getEls = function getEls() { | ||
var els = []; | ||
(refsOpt || refsState).forEach(function (_ref2) { | ||
var current = _ref2.current; | ||
return current && els.push(current); | ||
}); | ||
return els; | ||
}; | ||
var handler = function handler(e) { | ||
if (!hasIgnoreClass(e, ignoreClass) && !(excludeScrollbar && clickedOnScrollbar(e)) && els.every(function (el) { | ||
if (!hasIgnoreClass(e, ignoreClass) && !(excludeScrollbar && clickedOnScrollbar(e)) && getEls().every(function (el) { | ||
return !el.contains(e.target); | ||
@@ -98,3 +100,3 @@ })) callbackRef.current(e); | ||
activeElement = _document.activeElement; | ||
if ((activeElement == null ? void 0 : activeElement.tagName) === "IFRAME" && !hasIgnoreClass(activeElement, ignoreClass) && !els.includes(activeElement)) callbackRef.current(e); | ||
if ((activeElement == null ? void 0 : activeElement.tagName) === "IFRAME" && !hasIgnoreClass(activeElement, ignoreClass) && !getEls().includes(activeElement)) callbackRef.current(e); | ||
}, 0) | ||
@@ -101,0 +103,0 @@ ); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),n=function(e,n){for(var t=e.target||e;t;){var r;if(null!=(r=t.classList)&&r.contains(n))return!0;t=t.parentElement}return!1},t=function(e){return!(!e.includes("touch")||!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}())&&{passive:!0}};exports.DEFAULT_IGNORE_CLASS="ignore-onclickoutside",exports.default=function(r,u){var i=void 0===u?{}:u,o=i.refs,c=i.disabled,d=void 0!==c&&c,s=i.eventTypes,f=void 0===s?["mousedown","touchstart"]:s,a=i.excludeScrollbar,l=void 0!==a&&a,v=i.ignoreClass,E=void 0===v?"ignore-onclickoutside":v,m=i.detectIFrame,w=void 0===m||m,p=e.useRef(r),g=e.useState([]),h=g[0],L=g[1];e.useEffect((function(){p.current=r}),[r]);var b=e.useCallback((function(e){return L((function(n){return[].concat(n,[{current:e}])}))}),[]);return e.useEffect((function(){if(null!=o&&o.length||h.length){var e=[];(o||h).forEach((function(n){var t=n.current;return t&&e.push(t)}));var r=function(t){n(t,E)||l&&function(e){return document.documentElement.clientWidth<=e.clientX||document.documentElement.clientHeight<=e.clientY}(t)||!e.every((function(e){return!e.contains(t.target)}))||p.current(t)},u=function(t){return setTimeout((function(){var r=document.activeElement;"IFRAME"!==(null==r?void 0:r.tagName)||n(r,E)||e.includes(r)||p.current(t)}),0)},i=function(){f.forEach((function(e){return document.removeEventListener(e,r,t(e))})),w&&window.removeEventListener("blur",u)};if(!d)return f.forEach((function(e){return document.addEventListener(e,r,t(e))})),w&&window.addEventListener("blur",u),function(){return i()};i()}}),[h,E,l,d,w,JSON.stringify(f)]),b}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),n=function(e,n){for(var t=e.target||e;t;){var r;if(null!=(r=t.classList)&&r.contains(n))return!0;t=t.parentElement}return!1},t=function(e){return!(!e.includes("touch")||!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}())&&{passive:!0}};exports.DEFAULT_IGNORE_CLASS="ignore-onclickoutside",exports.default=function(r,u){var i=void 0===u?{}:u,o=i.refs,c=i.disabled,f=i.eventTypes,s=void 0===f?["mousedown","touchstart"]:f,d=i.excludeScrollbar,a=i.ignoreClass,l=void 0===a?"ignore-onclickoutside":a,v=i.detectIFrame,E=void 0===v||v,m=e.useRef(r),w=e.useState([]),p=w[0],g=w[1];e.useEffect((function(){m.current=r}),[r]);var h=e.useCallback((function(e){return g((function(n){return[].concat(n,[{current:e}])}))}),[]);return e.useEffect((function(){if(null!=o&&o.length||p.length){var e=function(){var e=[];return(o||p).forEach((function(n){var t=n.current;return t&&e.push(t)})),e},r=function(t){n(t,l)||d&&function(e){return document.documentElement.clientWidth<=e.clientX||document.documentElement.clientHeight<=e.clientY}(t)||!e().every((function(e){return!e.contains(t.target)}))||m.current(t)},u=function(t){return setTimeout((function(){var r=document.activeElement;"IFRAME"!==(null==r?void 0:r.tagName)||n(r,l)||e().includes(r)||m.current(t)}),0)},i=function(){s.forEach((function(e){return document.removeEventListener(e,r,t(e))})),E&&window.removeEventListener("blur",u)};if(!c)return s.forEach((function(e){return document.addEventListener(e,r,t(e))})),E&&window.addEventListener("blur",u),function(){return i()};i()}}),[p,l,d,c,E,JSON.stringify(s)]),h}; |
{ | ||
"name": "react-cool-onclickoutside", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "React hook to listen for clicks outside of the component(s).", | ||
@@ -54,10 +54,7 @@ "license": "MIT", | ||
"clean:cov": "rimraf coverage", | ||
"clean": "run-p clean:*" | ||
"clean": "run-p clean:*", | ||
"_postinstall": "husky install", | ||
"prepublishOnly": "pinst --disable", | ||
"postpublish": "pinst --enable" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged", | ||
"pre-push": "yarn test" | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -69,21 +66,21 @@ "*.{js,ts,tsx}": "eslint --fix", | ||
"devDependencies": { | ||
"@babel/core": "^7.12.13", | ||
"@babel/preset-env": "^7.12.13", | ||
"@babel/core": "^7.13.8", | ||
"@babel/preset-env": "^7.13.9", | ||
"@babel/preset-react": "^7.12.13", | ||
"@babel/preset-typescript": "^7.12.13", | ||
"@emotion/babel-plugin": "^11.1.2", | ||
"@babel/preset-typescript": "^7.13.0", | ||
"@emotion/babel-plugin": "^11.2.0", | ||
"@emotion/react": "^11.1.5", | ||
"@rollup/plugin-babel": "^5.2.3", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^17.1.0", | ||
"@rollup/plugin-html": "^0.2.2", | ||
"@rollup/plugin-node-resolve": "^11.1.1", | ||
"@rollup/plugin-replace": "^2.3.4", | ||
"@rollup/plugin-html": "^0.2.3", | ||
"@rollup/plugin-node-resolve": "^11.2.0", | ||
"@rollup/plugin-replace": "^2.4.1", | ||
"@rollup/plugin-url": "^6.0.0", | ||
"@testing-library/react": "^11.2.5", | ||
"@types/jest": "^26.0.20", | ||
"@types/react": "^17.0.1", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/react": "^17.0.3", | ||
"@types/react-dom": "^17.0.1", | ||
"eslint": "^7.2.0", | ||
"eslint-config-welly": "^1.8.11", | ||
"husky": "^4.3.8", | ||
"eslint-config-welly": "^1.8.15", | ||
"husky": "^5.1.3", | ||
"jest": "^26.6.3", | ||
@@ -93,3 +90,4 @@ "lint-staged": "^10.5.4", | ||
"npm-run-all": "^4.1.5", | ||
"postcss": "^8.2.5", | ||
"pinst": "^2.1.6", | ||
"postcss": "^8.2.7", | ||
"prettier": "^2.2.1", | ||
@@ -100,4 +98,4 @@ "react": "^17.0.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.38.5", | ||
"rollup-plugin-copy": "^3.3.0", | ||
"rollup": "^2.40.0", | ||
"rollup-plugin-copy": "^3.4.0", | ||
"rollup-plugin-livereload": "^2.0.0", | ||
@@ -108,7 +106,7 @@ "rollup-plugin-postcss": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"stylelint": "^13.9.0", | ||
"stylelint": "^13.12.0", | ||
"stylelint-config-prettier": "^8.0.2", | ||
"stylelint-config-standard": "^20.0.0", | ||
"ts-jest": "^26.5.0", | ||
"typescript": "^4.1.3" | ||
"stylelint-config-standard": "^21.0.0", | ||
"ts-jest": "^26.5.3", | ||
"typescript": "^4.2.3" | ||
}, | ||
@@ -115,0 +113,0 @@ "peerDependencies": { |
137
23760
42