react-idle-timer
Advanced tools
Comparing version
@@ -0,1 +1,4 @@ | ||
### 4.1.2 | ||
- Fixes a bug where `stopOnIdle` logic was being applied to active state | ||
### 4.1.1 | ||
@@ -2,0 +5,0 @@ - Fixes a bug where initial `onIdle` event was not firing when `stopOnIdle` is set |
@@ -1,2 +0,2 @@ | ||
import{Component}from"react";import PropTypes from"prop-types";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,a=t.idle,s=n.props,l=s.timeout,u=s.onAction,p=s.debounce,c=s.throttle,d=s.stopOnIdle;if(!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}p>0?n.debouncedAction(e):c>0?n.throttledAction(e):u(e),clearTimeout(n.tId),n.tId=null,a&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),d||(n.tId=setTimeout(n.toggleIdleState,l))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,Component),createClass(t,[{key:"componentWillMount",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.addEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){var e=this;if(clearTimeout(this.tId),IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"render",value:function(){return this.props.children||null}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle;this.setState({idle:!t});var n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||o(e):i(e)}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}();function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0};export default IdleTimer; | ||
import{Component}from"react";import PropTypes from"prop-types";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,a=t.idle,s=n.props,l=s.timeout,u=s.onAction,p=s.debounce,c=s.throttle,d=s.stopOnIdle;if(!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}p>0?n.debouncedAction(e):c>0?n.throttledAction(e):u(e),clearTimeout(n.tId),n.tId=null,a&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),a&&d||(n.tId=setTimeout(n.toggleIdleState,l))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,Component),createClass(t,[{key:"componentWillMount",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.addEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){var e=this;if(clearTimeout(this.tId),IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"render",value:function(){return this.props.children||null}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle;this.setState({idle:!t});var n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||o(e):i(e)}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}();function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0};export default IdleTimer; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var react=require("react"),PropTypes=_interopDefault(require("prop-types")),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,a=t.idle,s=n.props,u=s.timeout,l=s.onAction,p=s.debounce,c=s.throttle,d=s.stopOnIdle;if(!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),clearTimeout(n.tId),n.tId=null,a&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),d||(n.tId=setTimeout(n.toggleIdleState,u))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,e),createClass(t,[{key:"componentWillMount",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.addEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){var e=this;if(clearTimeout(this.tId),IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"render",value:function(){return this.props.children||null}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle;this.setState({idle:!t});var n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||o(e):i(e)}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}(react.Component);function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0},module.exports=IdleTimer; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var react=require("react"),PropTypes=_interopDefault(require("prop-types")),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},IS_BROWSER="object"===("undefined"==typeof window?"undefined":"undefined"==typeof window?"undefined":_typeof(window)),DEFAULT_ELEMENT=IS_BROWSER?document:{},DEFAULT_EVENTS=["mousemove","keydown","wheel","DOMMouseScroll","mouseWheel","mousedown","touchstart","touchmove","MSPointerDown","MSPointerMove"],IdleTimer=function(e){function t(e){classCallCheck(this,t);var n=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));if(n.state={idle:!1,oldDate:+new Date,lastActive:+new Date,remaining:null,pageX:null,pageY:null},n.tId=null,n._handleEvent=function(e){var t=n.state,o=t.remaining,i=t.pageX,r=t.pageY,a=t.idle,s=n.props,u=s.timeout,l=s.onAction,p=s.debounce,c=s.throttle,d=s.stopOnIdle;if(!o){if("mousemove"===e.type){if(e.pageX===i&&e.pageY===r)return;if(void 0===e.pageX&&void 0===e.pageY)return;if(n.getElapsedTime()<200)return}p>0?n.debouncedAction(e):c>0?n.throttledAction(e):l(e),clearTimeout(n.tId),n.tId=null,a&&n.toggleIdleState(e),n.setState({lastActive:+new Date,pageX:e.pageX,pageY:e.pageY}),a&&d||(n.tId=setTimeout(n.toggleIdleState,u))}},e.debounce>0&&e.throttle>0)throw new Error("onAction can either be throttled or debounced (not both)");return e.debounce>0&&(n.debouncedAction=debounced(e.onAction,e.debounce)),e.throttle>0&&(n.throttledAction=throttled(e.onAction,e.throttle)),e.startOnMount||(n.state.idle=!0),n.toggleIdleState=n._toggleIdleState.bind(n),n.reset=n._reset.bind(n),n.pause=n._pause.bind(n),n.resume=n._resume.bind(n),n.getRemainingTime=n._getRemainingTime.bind(n),n.getElapsedTime=n._getElapsedTime.bind(n),n.getLastActiveTime=n._getLastActiveTime.bind(n),n.isIdle=n._isIdle.bind(n),n}return inherits(t,e),createClass(t,[{key:"componentWillMount",value:function(){var e=this;if(IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.addEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"componentDidMount",value:function(){this.props.startOnMount&&this.reset()}},{key:"componentWillUnmount",value:function(){var e=this;if(clearTimeout(this.tId),IS_BROWSER){var t=this.props,n=t.element,o=t.events,i=t.passive,r=t.capture;o.forEach(function(t){n.removeEventListener(t,e._handleEvent,{capture:r,passive:i})})}}},{key:"render",value:function(){return this.props.children||null}},{key:"_toggleIdleState",value:function(e){var t=this.state.idle;this.setState({idle:!t});var n=this.props,o=n.onActive,i=n.onIdle,r=n.stopOnIdle;t?r||o(e):i(e)}},{key:"_reset",value:function(){clearTimeout(this.tId),this.tId=null,this.setState({idle:!1,oldDate:+new Date,lastActive:this.state.oldDate,remaining:null});var e=this.props.timeout;this.tId=setTimeout(this.toggleIdleState,e)}},{key:"_pause",value:function(){null===this.state.remaining&&(clearTimeout(this.tId),this.tId=null,this.setState({remaining:this.getRemainingTime()}))}},{key:"_resume",value:function(){var e=this.state,t=e.remaining,n=e.idle;null!==t&&(n||(this.setState({remaining:null}),this.tId=setTimeout(this.toggleIdleState,t)))}},{key:"_getRemainingTime",value:function(){var e=this.state,t=e.remaining,n=e.idle,o=e.lastActive;if(n)return 0;if(null!==t)return t;var i=this.props.timeout-(+new Date-o);return i<0&&(i=0),i}},{key:"_getElapsedTime",value:function(){var e=this.state.oldDate;return+new Date-e}},{key:"_getLastActiveTime",value:function(){return this.state.lastActive}},{key:"_isIdle",value:function(){return this.state.idle}}]),t}(react.Component);function debounced(e,t){var n=void 0;return function(){for(var o=arguments.length,i=Array(o),r=0;r<o;r++)i[r]=arguments[r];n&&clearTimeout(n),n=setTimeout(function(){e.apply(void 0,i),n=null},t)}}function throttled(e,t){var n=0;return function(){var o=(new Date).getTime();if(!(o-n<t))return n=o,e.apply(void 0,arguments)}}IdleTimer.propTypes={timeout:PropTypes.number,events:PropTypes.arrayOf(PropTypes.string),onIdle:PropTypes.func,onActive:PropTypes.func,onAction:PropTypes.func,debounce:PropTypes.number,throttle:PropTypes.number,element:PropTypes.oneOfType([PropTypes.object,PropTypes.element]),startOnMount:PropTypes.bool,stopOnIdle:PropTypes.bool,passive:PropTypes.bool,capture:PropTypes.bool},IdleTimer.defaultProps={timeout:12e5,element:DEFAULT_ELEMENT,events:DEFAULT_EVENTS,onIdle:function(){},onActive:function(){},onAction:function(){},debounce:0,throttle:0,startOnMount:!0,stopOnIdle:!1,capture:!0,passive:!0},module.exports=IdleTimer; | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "react-idle-timer", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"description": "Activity detection for React.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.min.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
61399
0.51%