react-with-dimension
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.WithDimension=t(require("react")):e.WithDimension=t(e.react)}(this,function(e){return function(e){function t(i){if(n[i])return n[i].exports;var o=n[i]={exports:{},id:i,loaded:!1};return e[i].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var o=n(1),r=i(o);t.default=r.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function o(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)}Object.defineProperty(t,"__esModule",{value:!0});var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},c=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),f=n(5),d=i(f),l=n(4),s=i(l),p=n(2),v=i(p),h=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().height:e?e.clientHeight:null},m=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().width:e?e.clientWidth:null},y=function(e,t){return{containerWidth:e,containerHeight:t}},w={width:"100%",height:"100%",padding:0,border:0},b=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=e.transform,n=void 0===t?y:t,i=e.containerStyle,l=void 0===i?w:i,p=e.getHeight,b=void 0===p?h:p,g=e.getWidth,j=void 0===g?m:g,_=e.wait,x=void 0===_?200:_;return function(e){var t,i;return i=t=function(t){function i(){var e,t,n,u;o(this,i);for(var a=arguments.length,c=Array(a),f=0;a>f;f++)c[f]=arguments[f];return t=n=r(this,(e=Object.getPrototypeOf(i)).call.apply(e,[this].concat(c))),n.state={containerWidth:null,containerHeight:null},n.updateDimensions=function(){if(n.mounted){var e=function(){var e=n.refs.withDimensionContainer;n.setState({containerWidth:j(e),containerHeight:b(e)})};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return e()}):e()}},u=t,r(n,u)}return u(i,t),c(i,[{key:"componentDidMount",value:function(){"undefined"!=typeof window&&null!==window&&window.addEventListener&&(this.mounted=!0,this.debouncedUpdate=(0,v.default)(this.updateDimensions,x),this.updateDimensions(),window.addEventListener("resize",this.debouncedUpdate,{passive:!0}))}},{key:"componentWillUnmount",value:function(){"undefined"!=typeof window&&null!==window&&window.removeEventListener&&(this.mounted=!1,window.removeEventListener("resize",this.debouncedUpdate,{passive:!0}))}},{key:"render",value:function(){return d.default.createElement("div",{ref:"withDimensionContainer",style:l},d.default.createElement(e,a({},n(this.state.containerWidth,this.state.containerHeight),this.props)))}}]),i}(f.Component),t.displayName=(0,s.default)(e,"withDimension"),i}};t.default=b},function(e,t){function n(e,t,n){function i(t){var n=h,i=m;return h=m=void 0,O=t,w=e.apply(i,n)}function r(e){return O=e,b=setTimeout(d,t),E?i(e):w}function u(e){var n=e-x,i=e-O,o=t-n;return W?j(o,y-i):o}function f(e){var n=e-x,i=e-O;return!x||n>=t||0>n||W&&i>=y}function d(){var e=_();return f(e)?l(e):void(b=setTimeout(d,u(e)))}function l(e){return clearTimeout(b),b=void 0,D&&h?i(e):(h=m=void 0,w)}function s(){void 0!==b&&clearTimeout(b),x=O=0,h=m=b=void 0}function p(){return void 0===b?w:l(_())}function v(){var e=_(),n=f(e);if(h=arguments,m=this,x=e,n){if(void 0===b)return r(x);if(W)return clearTimeout(b),b=setTimeout(d,t),i(x)}return void 0===b&&(b=setTimeout(d,t)),w}var h,m,y,w,b,x=0,O=0,E=!1,W=!1,D=!0;if("function"!=typeof e)throw new TypeError(c);return t=a(t)||0,o(n)&&(E=!!n.leading,W="maxWait"in n,y=W?g(a(n.maxWait)||0,t):y,D="trailing"in n?!!n.trailing:D),v.cancel=s,v.flush=p,v}function i(e){var t=o(e)?b.call(e):"";return t==d||t==l}function o(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function r(e){return!!e&&"object"==typeof e}function u(e){return"symbol"==typeof e||r(e)&&b.call(e)==s}function a(e){if("number"==typeof e)return e;if(u(e))return f;if(o(e)){var t=i(e.valueOf)?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(p,"");var n=h.test(e);return n||m.test(e)?y(e.slice(2),n?2:8):v.test(e)?f:+e}var c="Expected a function",f=NaN,d="[object Function]",l="[object GeneratorFunction]",s="[object Symbol]",p=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,h=/^0b[01]+$/i,m=/^0o[0-7]+$/i,y=parseInt,w=Object.prototype,b=w.toString,g=Math.max,j=Math.min,_=Date.now;e.exports=n},function(e,t){"use strict";t.__esModule=!0;var n=function(e){if("string"==typeof e)return e;if(e)return e.displayName||e.name||"Component"};t.default=n},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var o=n(3),r=i(o),u=function(e,t){return t+"("+(0,r.default)(e)+")"};t.default=u},function(t,n){t.exports=e}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.WithDimension=t(require("react")):e.WithDimension=t(e.react)}(this,function(e){return function(e){function t(i){if(n[i])return n[i].exports;var r=n[i]={exports:{},id:i,loaded:!1};return e[i].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),o=i(r);t.default=o.default},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(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)}Object.defineProperty(t,"__esModule",{value:!0});var a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},c=function(){function e(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}}(),f=n(5),d=i(f),l=n(4),s=i(l),p=n(2),v=i(p),h=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().height:e?e.clientHeight:null},m=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.getBoundingClientRect?e.getBoundingClientRect().width:e?e.clientWidth:null},y=function(e,t){return{containerWidth:e,containerHeight:t}},w={width:"100%",height:"100%",padding:0,border:0},b=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=e.transform,n=void 0===t?y:t,i=e.containerStyle,l=void 0===i?w:i,p=e.getHeight,b=void 0===p?h:p,g=e.getWidth,j=void 0===g?m:g,_=e.wait,x=void 0===_?200:_;return function(e){var t,i;return i=t=function(t){function i(){var e,t,n,u;r(this,i);for(var a=arguments.length,c=Array(a),f=0;a>f;f++)c[f]=arguments[f];return t=n=o(this,(e=Object.getPrototypeOf(i)).call.apply(e,[this].concat(c))),n.state={containerWidth:null,containerHeight:null},n.updateDimensions=function(){var e=function(){if(n.canUpdate){var e=n.refs.withDimensionContainer;n.setState({containerWidth:j(e),containerHeight:b(e)})}};"undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return e()}):e()},u=t,o(n,u)}return u(i,t),c(i,[{key:"componentDidMount",value:function(){"undefined"!=typeof window&&null!==window&&window.addEventListener&&(this.canUpdate=!0,this.debouncedUpdate=(0,v.default)(this.updateDimensions,x),this.updateDimensions(),window.addEventListener("resize",this.debouncedUpdate,{passive:!0}))}},{key:"componentWillUnmount",value:function(){"undefined"!=typeof window&&null!==window&&window.removeEventListener&&(this.canUpdate=!1,window.removeEventListener("resize",this.debouncedUpdate,{passive:!0}))}},{key:"render",value:function(){return d.default.createElement("div",{ref:"withDimensionContainer",style:l},d.default.createElement(e,a({},n(this.state.containerWidth,this.state.containerHeight),this.props)))}}]),i}(f.Component),t.displayName=(0,s.default)(e,"withDimension"),i}};t.default=b},function(e,t){function n(e,t,n){function i(t){var n=h,i=m;return h=m=void 0,O=t,w=e.apply(i,n)}function o(e){return O=e,b=setTimeout(d,t),E?i(e):w}function u(e){var n=e-x,i=e-O,r=t-n;return W?j(r,y-i):r}function f(e){var n=e-x,i=e-O;return!x||n>=t||0>n||W&&i>=y}function d(){var e=_();return f(e)?l(e):void(b=setTimeout(d,u(e)))}function l(e){return clearTimeout(b),b=void 0,D&&h?i(e):(h=m=void 0,w)}function s(){void 0!==b&&clearTimeout(b),x=O=0,h=m=b=void 0}function p(){return void 0===b?w:l(_())}function v(){var e=_(),n=f(e);if(h=arguments,m=this,x=e,n){if(void 0===b)return o(x);if(W)return clearTimeout(b),b=setTimeout(d,t),i(x)}return void 0===b&&(b=setTimeout(d,t)),w}var h,m,y,w,b,x=0,O=0,E=!1,W=!1,D=!0;if("function"!=typeof e)throw new TypeError(c);return t=a(t)||0,r(n)&&(E=!!n.leading,W="maxWait"in n,y=W?g(a(n.maxWait)||0,t):y,D="trailing"in n?!!n.trailing:D),v.cancel=s,v.flush=p,v}function i(e){var t=r(e)?b.call(e):"";return t==d||t==l}function r(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function o(e){return!!e&&"object"==typeof e}function u(e){return"symbol"==typeof e||o(e)&&b.call(e)==s}function a(e){if("number"==typeof e)return e;if(u(e))return f;if(r(e)){var t=i(e.valueOf)?e.valueOf():e;e=r(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(p,"");var n=h.test(e);return n||m.test(e)?y(e.slice(2),n?2:8):v.test(e)?f:+e}var c="Expected a function",f=NaN,d="[object Function]",l="[object GeneratorFunction]",s="[object Symbol]",p=/^\s+|\s+$/g,v=/^[-+]0x[0-9a-f]+$/i,h=/^0b[01]+$/i,m=/^0o[0-7]+$/i,y=parseInt,w=Object.prototype,b=w.toString,g=Math.max,j=Math.min,_=Date.now;e.exports=n},function(e,t){"use strict";t.__esModule=!0;var n=function(e){if("string"==typeof e)return e;if(e)return e.displayName||e.name||"Component"};t.default=n},function(e,t,n){"use strict";function i(e){return e&&e.__esModule?e:{"default":e}}t.__esModule=!0;var r=n(3),o=i(r),u=function(e,t){return t+"("+(0,o.default)(e)+")"};t.default=u},function(t,n){t.exports=e}])}); |
@@ -100,7 +100,7 @@ 'use strict'; | ||
}, _this.updateDimensions = function () { | ||
if (!_this.mounted) { | ||
return; | ||
} | ||
var update = function update() { | ||
if (!_this.canUpdate) { | ||
return; | ||
} | ||
var update = function update() { | ||
var elem = _this.refs.withDimensionContainer; | ||
@@ -128,3 +128,3 @@ | ||
if (typeof window !== 'undefined' && window !== null && window.addEventListener) { | ||
this.mounted = true; | ||
this.canUpdate = true; | ||
this.debouncedUpdate = (0, _lodash2.default)(this.updateDimensions, wait); | ||
@@ -139,3 +139,3 @@ this.updateDimensions(); | ||
if (typeof window !== 'undefined' && window !== null && window.removeEventListener) { | ||
this.mounted = false; | ||
this.canUpdate = false; | ||
window.removeEventListener('resize', this.debouncedUpdate, { passive: true }); | ||
@@ -142,0 +142,0 @@ } |
{ | ||
"name": "react-with-dimension", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Debounced React high order component to expose container width and height.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -50,3 +50,3 @@ import React, { Component } from 'react' | ||
if (typeof window !== 'undefined' && window !== null && window.addEventListener) { | ||
this.mounted = true | ||
this.canUpdate = true | ||
this.debouncedUpdate = debounce(this.updateDimensions, wait) | ||
@@ -60,3 +60,3 @@ this.updateDimensions() | ||
if (typeof window !== 'undefined' && window !== null && window.removeEventListener) { | ||
this.mounted = false | ||
this.canUpdate = false | ||
window.removeEventListener('resize', this.debouncedUpdate, { passive: true }) | ||
@@ -67,5 +67,5 @@ } | ||
updateDimensions = () => { | ||
if (!this.mounted) { return } | ||
const update = () => { | ||
if (!this.canUpdate) { return } | ||
const update = () => { | ||
const elem = this.refs.withDimensionContainer | ||
@@ -72,0 +72,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
23180