Skip to content

Commit

Permalink
Update to babel@7-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Nov 11, 2017
1 parent 0053a78 commit 519854d
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 165 deletions.
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

11 changes: 11 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const loose = true;

module.exports = {
presets: [
['@babel/env', { loose, modules: false }],
],
plugins: [
['@babel/proposal-class-properties', { loose }],
'@babel/proposal-object-rest-spread',
],
};
172 changes: 76 additions & 96 deletions dist/react-onclickoutside.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,87 @@
(factory((global.onClickOutside = {}),global.React,global.ReactDOM));
}(this, (function (exports,react,reactDom) { 'use strict';

function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}

function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;

for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}

if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);

for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}

return target;
}

/**
* Check whether some DOM node is our Component's node.
*/
function isNodeFound(current, componentNode, ignoreClass) {
if (current === componentNode) {
return true;
}
// SVG <use/> elements do not technically reside in the rendered DOM, so
} // SVG <use/> elements do not technically reside in the rendered DOM, so
// they do not have classList directly, but they offer a link to their
// corresponding element, which can have classList. This extra check is for
// that case.
// See: http://www.w3.org/TR/SVG11/struct.html#InterfaceSVGUseElement
// Discussion: https://github.com/Pomax/react-onclickoutside/pull/17


if (current.correspondingElement) {
return current.correspondingElement.classList.contains(ignoreClass);
}

return current.classList.contains(ignoreClass);
}

/**
* Try to find our node in a hierarchy of nodes, returning the document
* node as highest node if our node is not found in the path up.
*/

function findHighest(current, componentNode, ignoreClass) {
if (current === componentNode) {
return true;
}

// If source=local then this event came from 'somewhere'
} // If source=local then this event came from 'somewhere'
// inside and should be ignored. We could handle this with
// a layered approach, too, but that requires going back to
// thinking in terms of Dom node nesting, running counter
// to React's 'you shouldn't care about the DOM' philosophy.


while (current.parentNode) {
if (isNodeFound(current, componentNode, ignoreClass)) {
return true;
}

current = current.parentNode;
}

return current;
}

/**
* Check if the browser scrollbar was clicked
*/

function clickedScrollbar(evt) {
return document.documentElement.clientWidth <= evt.clientX || document.documentElement.clientHeight <= evt.clientY;
}
Expand All @@ -61,7 +97,6 @@ var testPassiveEventSupport = function testPassiveEventSupport() {
}

var passive = false;

var options = Object.defineProperty({}, 'passive', {
get: function get() {
passive = true;
Expand All @@ -72,12 +107,13 @@ var testPassiveEventSupport = function testPassiveEventSupport() {

window.addEventListener('testPassiveEventSupport', noop, options);
window.removeEventListener('testPassiveEventSupport', noop, options);

return passive;
};

function autoInc() {
var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
function autoInc(seed) {
if (seed === void 0) {
seed = 0;
}

return function () {
return ++seed;
Expand All @@ -86,85 +122,36 @@ function autoInc() {

var uid = autoInc();

var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};











var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}

subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};











var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}

return call && (typeof call === "object" || typeof call === "function") ? call : self;
};

var passiveEventSupport = void 0;

var passiveEventSupport;
var handlersMap = {};
var enabledInstances = {};

var touchEvents = ['touchstart', 'touchmove'];
var IGNORE_CLASS_NAME = 'ignore-react-onclickoutside';

/**
* This function generates the HOC function that you'll use
* in order to impart onOutsideClick listening to an
* arbitrary component. It gets called at the end of the
* bootstrapping code to yield an instance of the
* onClickOutsideHOC function defined inside setupHOC().
*/

function onClickOutsideHOC(WrappedComponent, config) {
var _class, _temp;

return _temp = _class = function (_Component) {
inherits(onClickOutside, _Component);
return _temp = _class =
/*#__PURE__*/
function (_Component) {
_inheritsLoose(onClickOutside, _Component);

function onClickOutside(props) {
classCallCheck(this, onClickOutside);
var _this;

var _this = possibleConstructorReturn(this, _Component.call(this, props));
_this = _Component.call(this, props) || this;

_this.__outsideClickHandler = function (event) {
if (typeof _this.__clickOutsideHandlerProp === 'function') {
_this.__clickOutsideHandlerProp(event);

return;
}

Expand Down Expand Up @@ -193,8 +180,8 @@ function onClickOutsideHOC(WrappedComponent, config) {
}

enabledInstances[_this._uid] = true;

var events = _this.props.eventTypes;

if (!events.forEach) {
events = [events];
}
Expand All @@ -212,7 +199,6 @@ function onClickOutsideHOC(WrappedComponent, config) {
}

if (_this.props.excludeScrollbar && clickedScrollbar(event)) return;

var current = event.target;

if (findHighest(current, _this.componentNode, _this.props.outsideClickIgnoreClass) !== document) {
Expand All @@ -227,7 +213,9 @@ function onClickOutsideHOC(WrappedComponent, config) {
var isTouchEvent = touchEvents.indexOf(eventName) !== -1;

if (isTouchEvent && passiveEventSupport) {
handlerOptions = { passive: !_this.props.preventDefault };
handlerOptions = {
passive: !_this.props.preventDefault
};
}

document.addEventListener(eventName, handlersMap[_this._uid], handlerOptions);
Expand All @@ -240,9 +228,11 @@ function onClickOutsideHOC(WrappedComponent, config) {

if (fn && typeof document !== 'undefined') {
var events = _this.props.eventTypes;

if (!events.forEach) {
events = [events];
}

events.forEach(function (eventName) {
return document.removeEventListener(eventName, fn);
});
Expand All @@ -257,16 +247,18 @@ function onClickOutsideHOC(WrappedComponent, config) {
_this._uid = uid();
return _this;
}

/**
* Access the WrappedComponent's instance.
*/


onClickOutside.prototype.getInstance = function getInstance() {
var _proto = onClickOutside.prototype;

_proto.getInstance = function getInstance() {
if (!WrappedComponent.prototype.isReactComponent) {
return this;
}

var ref = this.instanceRef;
return ref.getInstance ? ref.getInstance() : ref;
};
Expand All @@ -275,7 +267,7 @@ function onClickOutsideHOC(WrappedComponent, config) {
* Add click listeners to the current document,
* linked to this component's state.
*/
onClickOutside.prototype.componentDidMount = function componentDidMount() {
_proto.componentDidMount = function componentDidMount() {
// If we are in an environment without a DOM such
// as shallow rendering or snapshots then we exit
// early to prevent any unhandled errors being thrown.
Expand All @@ -287,6 +279,7 @@ function onClickOutsideHOC(WrappedComponent, config) {

if (config && typeof config.handleClickOutside === 'function') {
this.__clickOutsideHandlerProp = config.handleClickOutside(instance);

if (typeof this.__clickOutsideHandlerProp !== 'function') {
throw new Error('WrappedComponent lacks a function for processing outside click events specified by the handleClickOutside config option.');
}
Expand All @@ -296,43 +289,31 @@ function onClickOutsideHOC(WrappedComponent, config) {
this.enableOnClickOutside();
};

onClickOutside.prototype.componentDidUpdate = function componentDidUpdate() {
_proto.componentDidUpdate = function componentDidUpdate() {
this.componentNode = reactDom.findDOMNode(this.getInstance());
};

/**
* Remove all document's event listeners for this component
*/


onClickOutside.prototype.componentWillUnmount = function componentWillUnmount() {
_proto.componentWillUnmount = function componentWillUnmount() {
this.disableOnClickOutside();
};

/**
* Can be called to explicitly enable event listening
* for clicks and touches outside of this element.
*/


/**
* Can be called to explicitly disable event listening
* for clicks and touches outside of this element.
*/


/**
* Pass-through render
*/
onClickOutside.prototype.render = function render() {
var _this2 = this;

var props = Object.keys(this.props).filter(function (prop) {
return prop !== 'excludeScrollbar';
}).reduce(function (props, prop) {
props[prop] = _this2.props[prop];
return props;
}, {});
_proto.render = function render() {
// eslint-disable-next-line no-unused-vars
var _props = this.props,
excludeScrollbar = _props.excludeScrollbar,
props = _objectWithoutProperties(_props, ["excludeScrollbar"]);

if (WrappedComponent.prototype.isReactComponent) {
props.ref = this.getRef;
Expand All @@ -342,12 +323,11 @@ function onClickOutsideHOC(WrappedComponent, config) {

props.disableOnClickOutside = this.disableOnClickOutside;
props.enableOnClickOutside = this.enableOnClickOutside;

return react.createElement(WrappedComponent, props);
};

return onClickOutside;
}(react.Component), _class.displayName = 'OnClickOutside(' + (WrappedComponent.displayName || WrappedComponent.name || 'Component') + ')', _class.defaultProps = {
}(react.Component), _class.displayName = "OnClickOutside(" + (WrappedComponent.displayName || WrappedComponent.name || 'Component') + ")", _class.defaultProps = {
eventTypes: ['mousedown', 'touchstart'],
excludeScrollbar: config && config.excludeScrollbar || false,
outsideClickIgnoreClass: IGNORE_CLASS_NAME,
Expand Down

0 comments on commit 519854d

Please sign in to comment.