Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-with-dimension

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-with-dimension - npm Package Compare versions

Comparing version 1.0.7 to 1.0.8

2

dist/bundle.js

@@ -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),s=n(4),l=i(s),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},y=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return e&&e.getBoundingClientRect?e.getBoundingClientRect().width:e?e.clientWidth:null},m=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?m:t,i=e.containerStyle,s=void 0===i?w:i,p=e.getHeight,b=void 0===p?h:p,g=e.getWidth,j=void 0===g?y:g,_=e.wait,O=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;f<a;f++)c[f]=arguments[f];return t=n=r(this,(e=i.__proto__||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,r(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,O),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:s},d.default.createElement(e,a({},n(this.state.containerWidth,this.state.containerHeight),this.props)))}}]),i}(f.Component),t.displayName=(0,l.default)(e,"withDimension"),i}};t.default=b},function(e,t){(function(t){function n(e,t,n){function o(t){var n=h,i=y;return h=y=void 0,x=t,w=e.apply(i,n)}function r(e){return x=e,b=setTimeout(d,t),E?o(e):w}function c(e){var n=e-O,i=e-x,o=t-n;return W?j(o,m-i):o}function f(e){var n=e-O,i=e-x;return void 0===O||n>=t||n<0||W&&i>=m}function d(){var e=_();return f(e)?s(e):void(b=setTimeout(d,c(e)))}function s(e){return b=void 0,D&&h?o(e):(h=y=void 0,w)}function l(){void 0!==b&&clearTimeout(b),x=0,h=O=y=b=void 0}function p(){return void 0===b?w:s(_())}function v(){var e=_(),n=f(e);if(h=arguments,y=this,O=e,n){if(void 0===b)return r(O);if(W)return b=setTimeout(d,t),o(O)}return void 0===b&&(b=setTimeout(d,t)),w}var h,y,m,w,b,O,x=0,E=!1,W=!1,D=!0;if("function"!=typeof e)throw new TypeError(a);return t=u(t)||0,i(n)&&(E=!!n.leading,W="maxWait"in n,m=W?g(u(n.maxWait)||0,t):m,D="trailing"in n?!!n.trailing:D),v.cancel=l,v.flush=p,v}function i(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function o(e){return!!e&&"object"==typeof e}function r(e){return"symbol"==typeof e||o(e)&&b.call(e)==f}function u(e){if("number"==typeof e)return e;if(r(e))return c;if(i(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=i(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(d,"");var n=l.test(e);return n||p.test(e)?v(e.slice(2),n?2:8):s.test(e)?c:+e}var a="Expected a function",c=NaN,f="[object Symbol]",d=/^\s+|\s+$/g,s=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,p=/^0o[0-7]+$/i,v=parseInt,h="object"==typeof t&&t&&t.Object===Object&&t,y="object"==typeof self&&self&&self.Object===Object&&self,m=h||y||Function("return this")(),w=Object.prototype,b=w.toString,g=Math.max,j=Math.min,_=function(){return m.Date.now()};e.exports=n}).call(t,function(){return this}())},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 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.clientHeight?e.clientHeight:e&&e.getBoundingClientRect?e.getBoundingClientRect().height:null},m=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];return e&&e.clientWidth?e.clientWidth:e&&e.getBoundingClientRect?e.getBoundingClientRect().width:null},y=function(e,t){return{containerWidth:e,containerHeight:t}},w={width:"100%",height:"100%",padding:0,border:0},b={leading:!1,trailing:!0,maxWait:800},g=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,g=void 0===p?h:p,j=e.getWidth,x=void 0===j?m:j,_=e.wait,O=void 0===_?200:_,W=e.debounceOptions,E=void 0===W?b:W;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.update=function(e){n.setState({containerWidth:x(e),containerHeight:g(e)})},n.updateDimensions=function(){var e=n.refs.withDimensionContainer;n.canUpdate&&(n.state.containerWidth===x(e)&&n.state.containerHeight===g(e)||("undefined"!=typeof window&&null!==window&&window.requestAnimationFrame?window.requestAnimationFrame(function(){return n.update(e)}):n.update(e)))},u=t,r(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,O,E),window.addEventListener("resize",this.debouncedUpdate,{passive:!0}),this.debouncedUpdate())}},{key:"componentDidUpdate",value:function(){this.debouncedUpdate&&this.debouncedUpdate()}},{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=g},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),W?i(e):w}function u(e){var n=e-_,i=e-O,o=t-n;return E?j(o,y-i):o}function f(e){var n=e-_,i=e-O;return!_||n>=t||0>n||E&&i>=y}function d(){var e=x();return f(e)?l(e):void(b=setTimeout(d,u(e)))}function l(e){return clearTimeout(b),b=void 0,U&&h?i(e):(h=m=void 0,w)}function s(){void 0!==b&&clearTimeout(b),_=O=0,h=m=b=void 0}function p(){return void 0===b?w:l(x())}function v(){var e=x(),n=f(e);if(h=arguments,m=this,_=e,n){if(void 0===b)return r(_);if(E)return clearTimeout(b),b=setTimeout(d,t),i(_)}return void 0===b&&(b=setTimeout(d,t)),w}var h,m,y,w,b,_=0,O=0,W=!1,E=!1,U=!0;if("function"!=typeof e)throw new TypeError(c);return t=a(t)||0,o(n)&&(W=!!n.leading,E="maxWait"in n,y=E?g(a(n.maxWait)||0,t):y,U="trailing"in n?!!n.trailing:U),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,x=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}])});

@@ -32,10 +32,10 @@ 'use strict';

var defaultGetHeight = function defaultGetHeight() {
var elem = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var elem = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
if (elem && elem.clientHeight) {
return elem.clientHeight;
}
if (elem && elem.getBoundingClientRect) {
return elem.getBoundingClientRect().height;
}
if (elem) {
return elem.clientHeight;
}
return null;

@@ -45,10 +45,10 @@ };

var defaultGetWidth = function defaultGetWidth() {
var elem = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var elem = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
if (elem && elem.clientWidth) {
return elem.clientWidth;
}
if (elem && elem.getBoundingClientRect) {
return elem.getBoundingClientRect().width;
}
if (elem) {
return elem.clientWidth;
}
return null;

@@ -68,15 +68,23 @@ };

var defaultDebounceOptions = {
leading: false,
trailing: true,
maxWait: 800
};
var withDimension = function withDimension() {
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
_ref$transform = _ref.transform,
transform = _ref$transform === undefined ? defaultTransform : _ref$transform,
_ref$containerStyle = _ref.containerStyle,
containerStyle = _ref$containerStyle === undefined ? defaultContainerStyle : _ref$containerStyle,
_ref$getHeight = _ref.getHeight,
getHeight = _ref$getHeight === undefined ? defaultGetHeight : _ref$getHeight,
_ref$getWidth = _ref.getWidth,
getWidth = _ref$getWidth === undefined ? defaultGetWidth : _ref$getWidth,
_ref$wait = _ref.wait,
wait = _ref$wait === undefined ? 200 : _ref$wait;
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var _ref$transform = _ref.transform;
var transform = _ref$transform === undefined ? defaultTransform : _ref$transform;
var _ref$containerStyle = _ref.containerStyle;
var containerStyle = _ref$containerStyle === undefined ? defaultContainerStyle : _ref$containerStyle;
var _ref$getHeight = _ref.getHeight;
var getHeight = _ref$getHeight === undefined ? defaultGetHeight : _ref$getHeight;
var _ref$getWidth = _ref.getWidth;
var getWidth = _ref$getWidth === undefined ? defaultGetWidth : _ref$getWidth;
var _ref$wait = _ref.wait;
var wait = _ref$wait === undefined ? 200 : _ref$wait;
var _ref$debounceOptions = _ref.debounceOptions;
var debounceOptions = _ref$debounceOptions === undefined ? defaultDebounceOptions : _ref$debounceOptions;
return function (BaseComponent) {

@@ -89,3 +97,3 @@ var _class, _temp2;

function _class() {
var _ref2;
var _Object$getPrototypeO;

@@ -100,25 +108,26 @@ var _temp, _this, _ret;

return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref2, [this].concat(args))), _this), _this.state = {
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(_class)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.state = {
containerWidth: null,
containerHeight: null
}, _this.update = function (elem) {
_this.setState({
containerWidth: getWidth(elem),
containerHeight: getHeight(elem)
});
}, _this.updateDimensions = function () {
var update = function update() {
if (!_this.canUpdate) {
return;
}
var elem = _this.refs.withDimensionContainer;
var elem = _this.refs.withDimensionContainer;
if (!_this.canUpdate) {
return;
}
if (_this.state.containerWidth === getWidth(elem) && _this.state.containerHeight === getHeight(elem)) {
return;
}
_this.setState({
containerWidth: getWidth(elem),
containerHeight: getHeight(elem)
});
};
if (typeof window !== 'undefined' && window !== null && window.requestAnimationFrame) {
window.requestAnimationFrame(function () {
return update();
return _this.update(elem);
});
} else {
update();
_this.update(elem);
}

@@ -133,8 +142,15 @@ }, _temp), _possibleConstructorReturn(_this, _ret);

this.canUpdate = true;
this.debouncedUpdate = (0, _lodash2.default)(this.updateDimensions, wait);
this.updateDimensions();
this.debouncedUpdate = (0, _lodash2.default)(this.updateDimensions, wait, debounceOptions);
window.addEventListener('resize', this.debouncedUpdate, { passive: true });
this.debouncedUpdate();
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
if (this.debouncedUpdate) {
this.debouncedUpdate();
}
}
}, {
key: 'componentWillUnmount',

@@ -141,0 +157,0 @@ value: function componentWillUnmount() {

{
"name": "react-with-dimension",
"version": "1.0.7",
"version": "1.0.8",
"description": "Debounced React high order component to expose container width and height.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

jest.unmock('../with-dimension')
jest.mock('lodash.debounce', () => ((param) => param))

@@ -3,0 +4,0 @@ import React from 'react'

@@ -6,8 +6,8 @@ import React, { Component } from 'react'

const defaultGetHeight = (elem = {}) => {
if (elem && elem.clientHeight) {
return elem.clientHeight
}
if (elem && elem.getBoundingClientRect) {
return elem.getBoundingClientRect().height
}
if (elem) {
return elem.clientHeight
}
return null

@@ -17,8 +17,8 @@ }

const defaultGetWidth = (elem = {}) => {
if (elem && elem.clientWidth) {
return elem.clientWidth
}
if (elem && elem.getBoundingClientRect) {
return elem.getBoundingClientRect().width
}
if (elem) {
return elem.clientWidth
}
return null

@@ -36,2 +36,8 @@ }

const defaultDebounceOptions = {
leading: false,
trailing: true,
maxWait: 800,
}
const withDimension = ({

@@ -43,2 +49,3 @@ transform = defaultTransform,

wait = 200,
debounceOptions = defaultDebounceOptions,
} = {}) => (BaseComponent) => class extends Component {

@@ -55,8 +62,14 @@ static displayName = wrapDisplayName(BaseComponent, 'withDimension')

this.canUpdate = true
this.debouncedUpdate = debounce(this.updateDimensions, wait)
this.updateDimensions()
this.debouncedUpdate = debounce(this.updateDimensions, wait, debounceOptions)
window.addEventListener('resize', this.debouncedUpdate, { passive: true })
this.debouncedUpdate()
}
}
componentDidUpdate() {
if (this.debouncedUpdate) {
this.debouncedUpdate()
}
}
componentWillUnmount() {

@@ -69,18 +82,21 @@ if (typeof window !== 'undefined' && window !== null && window.removeEventListener) {

update = (elem) => {
this.setState({
containerWidth: getWidth(elem),
containerHeight: getHeight(elem),
})
}
updateDimensions = () => {
const update = () => {
if (!this.canUpdate) { return }
const elem = this.refs.withDimensionContainer
const elem = this.refs.withDimensionContainer
if (!this.canUpdate) { return }
if (this.state.containerWidth === getWidth(elem)
&& this.state.containerHeight === getHeight(elem)
) { return }
this.setState({
containerWidth: getWidth(elem),
containerHeight: getHeight(elem),
})
}
if (typeof window !== 'undefined' && window !== null && window.requestAnimationFrame) {
window.requestAnimationFrame(() => update())
window.requestAnimationFrame(() => this.update(elem))
} else {
update()
this.update(elem)
}

@@ -87,0 +103,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc