react-outer-click
Advanced tools
Comparing version 3.5.0 to 3.6.0
# Changelog | ||
## v3.6.0 - 2021-04-27 | ||
### Added | ||
- Added [tiny-invariant](https://www.npmjs.com/package/tiny-invariant) dependency. | ||
### Changed | ||
- Changed type checking in `useOuterClick` hook to use `invariant` function. | ||
- Updated [@babel/runtime](https://www.npmjs.com/package/@babel/runtime) dependency to v7.13.17. | ||
- Updated devDependencies. | ||
## v3.5.0 - 2020-11-19 | ||
@@ -4,0 +16,0 @@ |
@@ -10,2 +10,3 @@ 'use strict'; | ||
var useComposedRef = require('use-composed-ref'); | ||
var invariant = require('tiny-invariant'); | ||
var useLatest = require('use-latest'); | ||
@@ -15,6 +16,28 @@ | ||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(function (k) { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: function () { | ||
return e[k]; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
n['default'] = e; | ||
return Object.freeze(n); | ||
} | ||
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends); | ||
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose); | ||
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); | ||
var React__namespace = /*#__PURE__*/_interopNamespace(React); | ||
var useComposedRef__default = /*#__PURE__*/_interopDefaultLegacy(useComposedRef); | ||
var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant); | ||
var useLatest__default = /*#__PURE__*/_interopDefaultLegacy(useLatest); | ||
@@ -27,18 +50,11 @@ | ||
var useOuterClick = function useOuterClick(refs, handler) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (Array.isArray(refs)) { | ||
refs.forEach(function (ref, i) { | ||
if (typeof ref !== 'object' || ref === null) { | ||
throw new TypeError("Expected `refs[" + i + "]` to be of type `object`, but received type `" + typeof ref + "`"); | ||
} | ||
}); | ||
} else if (typeof refs !== 'object' || refs === null) { | ||
throw new TypeError("Expected `refs` to be of type `array` or `object`, but received type `" + typeof refs + "`"); | ||
} | ||
!(Array.isArray(refs) || typeof refs === 'object' && refs !== null) ? process.env.NODE_ENV !== "production" ? invariant__default['default'](false, 'Expected `refs` to be an array or object') : invariant__default['default'](false) : void 0; | ||
if (typeof handler !== 'function' && handler != null) { | ||
throw new TypeError("Expected `handler` to be of type `function`, but received type `" + typeof handler + "`"); | ||
} | ||
if (Array.isArray(refs)) { | ||
refs.forEach(function (ref, i) { | ||
!(typeof ref === 'object' && ref !== null) ? process.env.NODE_ENV !== "production" ? invariant__default['default'](false, "Expected `refs[" + i + "]` to be an object") : invariant__default['default'](false) : void 0; | ||
}); | ||
} | ||
!(typeof handler === 'function' || handler == null) ? process.env.NODE_ENV !== "production" ? invariant__default['default'](false, 'Expected `handler` to be a function') : invariant__default['default'](false) : void 0; | ||
var refsRef = useLatest__default['default'](refs); | ||
@@ -50,4 +66,4 @@ var handerRef = useLatest__default['default'](handler); | ||
return ref.current && ref.current !== event.target && !ref.current.contains(event.target); | ||
}) && handerRef.current != null) { | ||
handerRef.current(event); | ||
})) { | ||
handerRef.current == null ? void 0 : handerRef.current(event); | ||
} | ||
@@ -65,3 +81,3 @@ }; | ||
var OuterClick = /*#__PURE__*/React.forwardRef(function OuterClick(_ref, userRef) { | ||
var OuterClick = /*#__PURE__*/React__namespace.forwardRef(function OuterClick(_ref, userRef) { | ||
var _ref$as = _ref.as, | ||
@@ -78,3 +94,3 @@ Element = _ref$as === void 0 ? 'div' : _ref$as, | ||
useOuterClick(libRef, onOuterClick); | ||
return /*#__PURE__*/React.createElement(Element, _extends__default['default']({}, rest, { | ||
return /*#__PURE__*/React__namespace.createElement(Element, _extends__default['default']({}, rest, { | ||
ref: ref | ||
@@ -81,0 +97,0 @@ }), children); |
import _extends from '@babel/runtime/helpers/extends'; | ||
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose'; | ||
import PropTypes from 'prop-types'; | ||
import { useEffect, forwardRef, useRef, createElement } from 'react'; | ||
import * as React from 'react'; | ||
import { useEffect, useRef } from 'react'; | ||
import useComposedRef from 'use-composed-ref'; | ||
import invariant from 'tiny-invariant'; | ||
import useLatest from 'use-latest'; | ||
@@ -13,18 +15,11 @@ | ||
var useOuterClick = function useOuterClick(refs, handler) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (Array.isArray(refs)) { | ||
refs.forEach(function (ref, i) { | ||
if (typeof ref !== 'object' || ref === null) { | ||
throw new TypeError("Expected `refs[" + i + "]` to be of type `object`, but received type `" + typeof ref + "`"); | ||
} | ||
}); | ||
} else if (typeof refs !== 'object' || refs === null) { | ||
throw new TypeError("Expected `refs` to be of type `array` or `object`, but received type `" + typeof refs + "`"); | ||
} | ||
!(Array.isArray(refs) || typeof refs === 'object' && refs !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected `refs` to be an array or object') : invariant(false) : void 0; | ||
if (typeof handler !== 'function' && handler != null) { | ||
throw new TypeError("Expected `handler` to be of type `function`, but received type `" + typeof handler + "`"); | ||
} | ||
if (Array.isArray(refs)) { | ||
refs.forEach(function (ref, i) { | ||
!(typeof ref === 'object' && ref !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Expected `refs[" + i + "]` to be an object") : invariant(false) : void 0; | ||
}); | ||
} | ||
!(typeof handler === 'function' || handler == null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected `handler` to be a function') : invariant(false) : void 0; | ||
var refsRef = useLatest(refs); | ||
@@ -36,4 +31,4 @@ var handerRef = useLatest(handler); | ||
return ref.current && ref.current !== event.target && !ref.current.contains(event.target); | ||
}) && handerRef.current != null) { | ||
handerRef.current(event); | ||
})) { | ||
handerRef.current == null ? void 0 : handerRef.current(event); | ||
} | ||
@@ -51,3 +46,3 @@ }; | ||
var OuterClick = /*#__PURE__*/forwardRef(function OuterClick(_ref, userRef) { | ||
var OuterClick = /*#__PURE__*/React.forwardRef(function OuterClick(_ref, userRef) { | ||
var _ref$as = _ref.as, | ||
@@ -64,3 +59,3 @@ Element = _ref$as === void 0 ? 'div' : _ref$as, | ||
useOuterClick(libRef, onOuterClick); | ||
return /*#__PURE__*/createElement(Element, _extends({}, rest, { | ||
return /*#__PURE__*/React.createElement(Element, _extends({}, rest, { | ||
ref: ref | ||
@@ -67,0 +62,0 @@ }), children); |
{ | ||
"name": "react-outer-click", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "React component and hook which detect mouse clicks outside of itself.", | ||
@@ -38,4 +38,5 @@ "main": "lib/index.cjs.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.5", | ||
"@babel/runtime": "^7.13.17", | ||
"prop-types": "^15.7.2", | ||
"tiny-invariant": "^1.1.0", | ||
"use-composed-ref": "^1.1.0", | ||
@@ -45,24 +46,25 @@ "use-latest": "^1.2.0" | ||
"devDependencies": { | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-transform-runtime": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/preset-react": "^7.12.5", | ||
"@rollup/plugin-babel": "^5.2.1", | ||
"@testing-library/jest-dom": "^5.11.6", | ||
"@testing-library/react": "^11.2.0", | ||
"@babel/core": "^7.13.16", | ||
"@babel/plugin-transform-runtime": "^7.13.15", | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/preset-react": "^7.13.13", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@testing-library/jest-dom": "^5.12.0", | ||
"@testing-library/react": "^11.2.6", | ||
"babel-eslint": "^10.1.0", | ||
"babel-plugin-dev-expression": "^0.2.2", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24", | ||
"eslint": "^7.13.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-jest": "^24.1.3", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"eslint-plugin-react": "^7.21.5", | ||
"eslint": "^7.25.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-jest": "^24.3.6", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint-plugin-react": "^7.23.2", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"husky": "^4.3.0", | ||
"husky": "^6.0.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"prettier": "^2.1.2", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"rollup": "^2.33.3" | ||
"lint-staged": "^10.5.4", | ||
"prettier": "^2.2.1", | ||
"react": "17.0.2", | ||
"react-dom": "^17.0.2", | ||
"rollup": "^2.45.2" | ||
}, | ||
@@ -69,0 +71,0 @@ "peerDependencies": { |
@@ -26,3 +26,4 @@ # react-outer-click | ||
useOuterClick(el, () => { | ||
useOuterClick(el, (event) => { | ||
event.preventDefault(); | ||
console.log('Clicked outside'); | ||
@@ -55,2 +56,3 @@ }); | ||
onOuterClick={() => { | ||
event.preventDefault(); | ||
console.log('Clicked outside'); | ||
@@ -57,0 +59,0 @@ }} |
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
26499
147
80
6
23
8
+ Addedtiny-invariant@^1.1.0
+ Addedtiny-invariant@1.3.3(transitive)
Updated@babel/runtime@^7.13.17