react-cool-onclickoutside
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -1,1 +0,1 @@ | ||
import{useRef,useState,useEffect,useCallback}from"react";function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _iterableToArrayLimit(e,r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var t=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return t}}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var canUsePassiveEvents=function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var e=!1,r=Object.defineProperty({},"passive",{get:function(){e=!0}}),t=function(){return null};return window.addEventListener("test",t,r),window.removeEventListener("test",t,r),e},DEFAULT_IGNORE_CLASS="ignore-onclickoutside",hasIgnoreClass=function(e,r){for(var t=e.target;t;){if(t.classList.contains(r))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){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.refs,n=r.disabled,o=void 0!==n&&n,a=r.eventTypes,i=void 0===a?["mousedown","touchstart"]:a,u=r.excludeScrollbar,c=void 0!==u&&u,s=r.ignoreClass,l=void 0===s?DEFAULT_IGNORE_CLASS:s,f=useRef(e),d=useState([]),y=_slicedToArray(d,2),v=y[0],b=y[1];useEffect((function(){f.current=e}),[e]);var m=useCallback((function(e){b((function(r){return[].concat(_toConsumableArray(r),[{current:e}])}))}),[]);return useEffect((function(){if((null==t?void 0:t.length)||v.length){var e=function(e){if(!hasIgnoreClass(e,l)){var r=[];(t||v).forEach((function(e){var t=e.current;t&&r.push(t)})),c&&clickedOnScrollbar(e)||r.length&&r.every((function(r){return!r.contains(e.target)}))&&f.current(e)}},r=function(){i.forEach((function(r){document.removeEventListener(r,e,getEventOptions(r))}))};if(!o)return i.forEach((function(r){document.addEventListener(r,e,getEventOptions(r))})),function(){r()};r()}}),[v,l,c,o,JSON.stringify(i)]),m};export default useOnclickOutside;export{DEFAULT_IGNORE_CLASS}; | ||
import{useRef,useState,useEffect,useCallback}from"react";function _slicedToArray(e,r){return _arrayWithHoles(e)||_iterableToArrayLimit(e,r)||_unsupportedIterableToArray(e,r)||_nonIterableRest()}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _iterableToArray(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}function _iterableToArrayLimit(e,r){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var t=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(t.push(i.value),!r||t.length!==r);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return t}}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var canUsePassiveEvents=function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var e=!1,r=Object.defineProperty({},"passive",{get:function(){e=!0}}),t=function(){return null};return window.addEventListener("test",t,r),window.removeEventListener("test",t,r),e},DEFAULT_IGNORE_CLASS="ignore-onclickoutside",hasIgnoreClass=function(e,r){for(var t=e.target;t;){var n;if(null===(n=t)||void 0===n?void 0:n.classList.contains(r))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){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},t=r.refs,n=r.disabled,o=void 0!==n&&n,a=r.eventTypes,i=void 0===a?["mousedown","touchstart"]:a,u=r.excludeScrollbar,c=void 0!==u&&u,l=r.ignoreClass,s=void 0===l?DEFAULT_IGNORE_CLASS:l,f=useRef(e),d=useState([]),y=_slicedToArray(d,2),v=y[0],b=y[1];useEffect((function(){f.current=e}),[e]);var m=useCallback((function(e){b((function(r){return[].concat(_toConsumableArray(r),[{current:e}])}))}),[]);return useEffect((function(){if((null==t?void 0:t.length)||v.length){var e=function(e){if(!hasIgnoreClass(e,s)){var r=[];(t||v).forEach((function(e){var t=e.current;t&&r.push(t)})),c&&clickedOnScrollbar(e)||r.length&&r.every((function(r){return!r.contains(e.target)}))&&f.current(e)}},r=function(){i.forEach((function(r){document.removeEventListener(r,e,getEventOptions(r))}))};if(!o)return i.forEach((function(r){document.addEventListener(r,e,getEventOptions(r))})),function(){r()};r()}}),[v,s,c,o,JSON.stringify(i)]),m};export default useOnclickOutside;export{DEFAULT_IGNORE_CLASS}; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(r=(u=c.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return n}(t,e)||r(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=function(t,e){for(var n=t.target;n;){if(n.classList.contains(e))return!0;n=n.parentElement}return!1},u=function(t){return document.documentElement.clientWidth<=t.clientX||document.documentElement.clientHeight<=t.clientY},c=function(t){return!(!t.includes("touch")||!function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var t=!1,e=Object.defineProperty({},"passive",{get:function(){t=!0}}),n=function(){return null};return window.addEventListener("test",n,e),window.removeEventListener("test",n,e),t}())&&{passive:!0}};exports.DEFAULT_IGNORE_CLASS="ignore-onclickoutside",exports.default=function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=o.refs,f=o.disabled,l=void 0!==f&&f,s=o.eventTypes,d=void 0===s?["mousedown","touchstart"]:s,v=o.excludeScrollbar,y=void 0!==v&&v,m=o.ignoreClass,p=void 0===m?"ignore-onclickoutside":m,b=t.useRef(r),h=t.useState([]),g=e(h,2),E=g[0],w=g[1];t.useEffect((function(){b.current=r}),[r]);var S=t.useCallback((function(t){w((function(e){return[].concat(n(e),[{current:t}])}))}),[]);return t.useEffect((function(){if((null==a?void 0:a.length)||E.length){var t=function(t){if(!i(t,p)){var e=[];(a||E).forEach((function(t){var n=t.current;n&&e.push(n)})),y&&u(t)||e.length&&e.every((function(e){return!e.contains(t.target)}))&&b.current(t)}},e=function(){d.forEach((function(e){document.removeEventListener(e,t,c(e))}))};if(!l)return d.forEach((function(e){document.addEventListener(e,t,c(e))})),function(){e()};e()}}),[E,p,y,l,JSON.stringify(d)]),S}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var n=[],r=!0,o=!1,i=void 0;try{for(var u,c=t[Symbol.iterator]();!(r=(u=c.next()).done)&&(n.push(u.value),!e||n.length!==e);r=!0);}catch(t){o=!0,i=t}finally{try{r||null==c.return||c.return()}finally{if(o)throw i}}return n}(t,e)||r(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(t){return function(t){if(Array.isArray(t))return o(t)}(t)||function(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}(t)||r(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}var i=function(t,e){for(var n=t.target;n;){var r;if(null===(r=n)||void 0===r?void 0:r.classList.contains(e))return!0;n=n.parentElement}return!1},u=function(t){return document.documentElement.clientWidth<=t.clientX||document.documentElement.clientHeight<=t.clientY},c=function(t){return!(!t.includes("touch")||!function(){if("undefined"==typeof window||"function"!=typeof window.addEventListener)return!1;var t=!1,e=Object.defineProperty({},"passive",{get:function(){t=!0}}),n=function(){return null};return window.addEventListener("test",n,e),window.removeEventListener("test",n,e),t}())&&{passive:!0}};exports.DEFAULT_IGNORE_CLASS="ignore-onclickoutside",exports.default=function(r){var o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=o.refs,f=o.disabled,l=void 0!==f&&f,s=o.eventTypes,d=void 0===s?["mousedown","touchstart"]:s,v=o.excludeScrollbar,y=void 0!==v&&v,m=o.ignoreClass,p=void 0===m?"ignore-onclickoutside":m,b=t.useRef(r),h=t.useState([]),g=e(h,2),E=g[0],w=g[1];t.useEffect((function(){b.current=r}),[r]);var S=t.useCallback((function(t){w((function(e){return[].concat(n(e),[{current:t}])}))}),[]);return t.useEffect((function(){if((null==a?void 0:a.length)||E.length){var t=function(t){if(!i(t,p)){var e=[];(a||E).forEach((function(t){var n=t.current;n&&e.push(n)})),y&&u(t)||e.length&&e.every((function(e){return!e.contains(t.target)}))&&b.current(t)}},e=function(){d.forEach((function(e){document.removeEventListener(e,t,c(e))}))};if(!l)return d.forEach((function(e){document.addEventListener(e,t,c(e))})),function(){e()};e()}}),[E,p,y,l,JSON.stringify(d)]),S}; |
{ | ||
"name": "react-cool-onclickoutside", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "React hook to listen for clicks outside of the component(s).", | ||
@@ -137,11 +137,11 @@ "license": "MIT", | ||
"@emotion/core": "^10.0.28", | ||
"@rollup/plugin-babel": "^5.0.3", | ||
"@rollup/plugin-babel": "^5.0.4", | ||
"@rollup/plugin-commonjs": "^13.0.0", | ||
"@rollup/plugin-html": "^0.2.0", | ||
"@rollup/plugin-node-resolve": "^8.0.1", | ||
"@rollup/plugin-node-resolve": "^8.1.0", | ||
"@rollup/plugin-replace": "^2.3.3", | ||
"@rollup/plugin-url": "^5.0.1", | ||
"@testing-library/react": "^10.3.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/react": "^16.9.38", | ||
"@testing-library/react": "^10.4.3", | ||
"@types/jest": "^26.0.3", | ||
"@types/react": "^16.9.41", | ||
"@types/react-dom": "^16.9.8", | ||
@@ -152,3 +152,3 @@ "babel-plugin-emotion": "^10.0.33", | ||
"husky": "^4.2.5", | ||
"jest": "^26.0.1", | ||
"jest": "^26.1.0", | ||
"lint-staged": "^10.2.11", | ||
@@ -162,3 +162,3 @@ "normalize.css": "^8.0.1", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.17.1", | ||
"rollup": "^2.18.1", | ||
"rollup-plugin-copy": "^3.3.0", | ||
@@ -174,3 +174,3 @@ "rollup-plugin-livereload": "^1.3.0", | ||
"stylelint-prettier": "^1.1.2", | ||
"ts-jest": "^26.1.0", | ||
"ts-jest": "^26.1.1", | ||
"typescript": "^3.9.5" | ||
@@ -177,0 +177,0 @@ }, |
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
23772