UNPKG

react-window-size-listener

Version:
1 lines 6.24 kB
module.exports=function(e){function t(o){if(n[o])return n[o].exports;var i=n[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(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}function u(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)}function c(e){return function(t){function n(e){i(this,n);var t=r(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,e));return t.state={windowSize:{windowWidth:window&&window.innerWidth||document&&(document.documentElement&&document.documentElement.clientWidth||document.body&&document.body.clientWidth)||null,windowHeight:window&&window.innerHeight||document&&(document.documentElement.clientHeight||document.body.clientHeight)||null}},t}return u(n,t),a(n,[{key:"render",value:function(){var t=this;return p.default.createElement(m,{onResize:function(e){return t.setState({windowSize:e})}},p.default.createElement(e,s({},this.props,{windowSize:this.state.windowSize})))}}]),n}(p.default.Component)}Object.defineProperty(t,"__esModule",{value:!0});var s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},a=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}}();t.withWindowSizeListener=c;var l=n(1),p=o(l),f=n(2),d=o(f),h=n(5),y=o(h),m=function(e){function t(e){i(this,t);var n=r(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.displayName="WindowSizeListener",n._listeners=[],n.DEBOUNCE_TIME=100,n.onResize=n.onResize.bind(n),n}return u(t,e),a(t,[{key:"shouldComponentUpdate",value:function(e){return e.onResize!==this.props.onResize}},{key:"componentDidMount",value:function(){this._listeners.length||(this._debouncedResize=(0,y.default)(this.onResize,this.DEBOUNCE_TIME),window.addEventListener("resize",this._debouncedResize,!1)),this._listeners.push(this.props.onResize),this._debouncedResize()}},{key:"componentWillUnmount",value:function(){var e=this._listeners.indexOf(this.props.onResize);this._listeners.splice(e,1),this._listeners.length||window.removeEventListener("resize",this._debouncedResize,!1)}},{key:"componentDidUpdate",value:function(e){if(e.onResize!==this.props.onResize){var t=this._listeners.indexOf(e.onResize);this._listeners.splice(t,1,this.props.onResize)}}},{key:"onResize",value:function(){var e=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,t=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;this._listeners.forEach(function(n){n({windowWidth:e,windowHeight:t})})}},{key:"render",value:function(){return this.props.children?this.props.children:null}},{key:"DEBOUNCE_TIME",get:function(){return this._DEBOUNCE_TIME},set:function(e){this._DEBOUNCE_TIME=e}}]),t}(p.default.Component);m.propTypes={onResize:d.default.func.isRequired},t.default=m},function(e,t){e.exports=require("react")},function(e,t,n){e.exports=n(3)()},function(e,t,n){"use strict";function o(){}var i=n(4);e.exports=function(){function e(e,t,n,o,r,u){if(u!==i){var c=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw c.name="Invariant Violation",c}}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=o,n.PropTypes=n,n}},function(e,t,n){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},function(e,t,n){function o(e,t,n){function o(){w&&clearTimeout(w),d&&clearTimeout(d),b=0,d=w=v=void 0}function r(t,n){n&&clearTimeout(n),d=w=v=void 0,t&&(b=a(),h=e.apply(m,f),w||d||(f=m=void 0))}function s(){var e=t-(a()-y);e<=0||e>t?r(v,d):w=setTimeout(s,e)}function l(){r(E,w)}function p(){if(f=arguments,y=a(),m=this,v=E&&(w||!O),!1===_)var n=O&&!w;else{d||O||(b=y);var o=_-(y-b),i=o<=0||o>_;i?(d&&(d=clearTimeout(d)),b=y,h=e.apply(m,f)):d||(d=setTimeout(l,o))}return i&&w?w=clearTimeout(w):w||t===_||(w=setTimeout(s,t)),n&&(i=!0,h=e.apply(m,f)),!i||w||d||(f=m=void 0),h}var f,d,h,y,m,w,v,b=0,_=!1,E=!0;if("function"!=typeof e)throw new TypeError(u);if(t=t<0?0:+t||0,!0===n){var O=!0;E=!1}else i(n)&&(O=!!n.leading,_="maxWait"in n&&c(+n.maxWait||0,t),E="trailing"in n?!!n.trailing:E);return p.cancel=o,p}function i(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}var r=n(6),u="Expected a function",c=Math.max,s=r(Date,"now"),a=s||function(){return(new Date).getTime()};e.exports=o},function(e,t){function n(e){return!!e&&"object"==typeof e}function o(e,t){var n=null==e?void 0:e[t];return u(n)?n:void 0}function i(e){return r(e)&&f.call(e)==c}function r(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function u(e){return null!=e&&(i(e)?d.test(l.call(e)):n(e)&&s.test(e))}var c="[object Function]",s=/^\[object .+?Constructor\]$/,a=Object.prototype,l=Function.prototype.toString,p=a.hasOwnProperty,f=a.toString,d=RegExp("^"+l.call(p).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");e.exports=o}]);