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

react-measure

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-measure - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

lib/get-types.js

3

CHANGELOG.md
## CHANGELOG
### 2.0.1
Observe and disconnect ResizeObserver in ref callback
### 2.0.0

@@ -3,0 +6,0 @@ Complete rewrite. Check README for new docs.

81

dist/react-measure.js
/*!
* React Measure 2.0.0
* React Measure 2.0.1
* https://github.com/souporserious/react-measure

@@ -132,4 +132,2 @@ * Copyright (c) 2017 React Measure Authors

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -149,4 +147,8 @@

var _getContentRect = __webpack_require__(14);
var _getTypes = __webpack_require__(14);
var _getTypes2 = _interopRequireDefault(_getTypes);
var _getContentRect = __webpack_require__(15);
var _getContentRect2 = _interopRequireDefault(_getContentRect);

@@ -164,14 +166,2 @@

var types = ['client', 'offset', 'scroll', 'bounds', 'margin'];
function getTypes(props) {
var allowedTypes = [];
types.forEach(function (type) {
if (props[type]) {
allowedTypes.push(type);
}
});
return allowedTypes;
}
function withContentRect(types) {

@@ -205,3 +195,3 @@ return function (WrappedComponent) {

}, _this.measure = function (entries) {
var contentRect = (0, _getContentRect2.default)(_this._node, types || getTypes(_this.props));
var contentRect = (0, _getContentRect2.default)(_this._node, types || (0, _getTypes2.default)(_this.props));

@@ -217,7 +207,15 @@ if (entries) {

}
}, _this._handleRef = function (component) {
_this._node = component;
}, _this._handleRef = function (node) {
_this._node = node;
if (_this._resizeObserver) {
if (node) {
_this._resizeObserver.observe(node);
} else {
_this._resizeObserver.disconnect(node);
}
}
if (typeof _this.props.innerRef === 'function') {
_this.props.innerRef(component);
_this.props.innerRef(node);
}

@@ -228,21 +226,7 @@ }, _temp), _possibleConstructorReturn(_this, _ret);

_createClass(_class, [{
key: 'componentDidMount',
value: function componentDidMount() {
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object') return;
if (this._node) {
this._resizeObserver = new _resizeObserverPolyfill2.default(this.measure);
this._resizeObserver.observe(this._node);
} else {
console.error('No ref found, attach the `measureRef` prop to the component you want to measure.');
}
key: 'componentWillMount',
value: function componentWillMount() {
this._resizeObserver = new _resizeObserverPolyfill2.default(this.measure);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.resizeObserver && this._node) {
this._resizeObserver.disconnect(this._node);
}
}
}, {
key: 'render',

@@ -1337,2 +1321,25 @@ value: function render() {

});
exports.default = getTypes;
var types = ['client', 'offset', 'scroll', 'bounds', 'margin'];
function getTypes(props) {
var allowedTypes = [];
types.forEach(function (type) {
if (props[type]) {
allowedTypes.push(type);
}
});
return allowedTypes;
}
module.exports = exports['default'];
/***/ },
/* 15 */
/***/ function(module, exports) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
function getContentRect(node, types) {

@@ -1339,0 +1346,0 @@ var calculations = {};

/*!
* React Measure 2.0.0
* React Measure 2.0.1
* https://github.com/souporserious/react-measure
* Copyright (c) 2017 React Measure Authors
*/
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("resize-observer-polyfill")):"function"==typeof define&&define.amd?define(["react","resize-observer-polyfill"],t):"object"==typeof exports?exports.Measure=t(require("react"),require("resize-observer-polyfill")):e.Measure=t(e.React,e.ResizeObserver)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="dist/",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.withContentRect=t.default=void 0;var o=n(1),i=r(o),u=n(3),a=r(u);t.default=i.default,t.withContentRect=a.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function Measure(e){var t=e.measure,n=e.measureRef,r=e.contentRect,o=e.children;return o({measure:t,measureRef:n,contentRect:r})}Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),i=(r(o),n(3)),u=r(i);t.default=(0,u.default)()(Measure),e.exports=t.default},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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 a(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 f(e){var t=[];return w.forEach(function(n){e[n]&&t.push(n)}),t}function c(e){return function(t){var n,r;return r=n=function(n){function r(){var t,n,o,a;i(this,r);for(var c=arguments.length,s=Array(c),l=0;l<c;l++)s[l]=arguments[l];return n=o=u(this,(t=r.__proto__||Object.getPrototypeOf(r)).call.apply(t,[this].concat(s))),o.state={contentRect:{entry:{},client:{},offset:{},scroll:{},bounds:{},margin:{}}},o.measure=function(t){var n=(0,g.default)(o._node,e||f(o.props));t&&(n.entry=t[0].contentRect),o.setState({contentRect:n}),"function"==typeof o.props.onResize&&o.props.onResize(n)},o._handleRef=function(e){o._node=e,"function"==typeof o.props.innerRef&&o.props.innerRef(e)},a=n,u(o,a)}return a(r,n),p(r,[{key:"componentDidMount",value:function(){"object"===("undefined"==typeof window?"undefined":l(window))&&(this._node?(this._resizeObserver=new m.default(this.measure),this._resizeObserver.observe(this._node)):console.error("No ref found, attach the `measureRef` prop to the component you want to measure."))}},{key:"componentWillUnmount",value:function(){this.resizeObserver&&this._node&&this._resizeObserver.disconnect(this._node)}},{key:"render",value:function(){var e=this.props,n=(e.innerRef,e.onResize,o(e,["innerRef","onResize"]));return(0,d.createElement)(t,s({},n,{measureRef:this._handleRef,measure:this.measure,contentRect:this.state.contentRect}))}}]),r}(d.Component),n.propTypes={client:h.default.bool,offset:h.default.bool,scroll:h.default.bool,bounds:h.default.bool,margin:h.default.bool,innerRef:h.default.func,onResize:h.default.func,children:h.default.func},r}}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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},l="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},p=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),d=n(2),y=(r(d),n(4)),h=r(y),v=n(13),m=r(v),b=n(14),g=r(b),w=["client","offset","scroll","bounds","margin"];t.default=c,e.exports=t.default},function(e,t,n){(function(t){"use strict";var r="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};if("production"!==t.env.NODE_ENV){var o="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,i=function(e){return"object"===("undefined"==typeof e?"undefined":r(e))&&null!==e&&e.$$typeof===o},u=!0;e.exports=n(6)(i,u)}else e.exports=n(12)()}).call(t,n(5))},function(e,t){"use strict";function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(e){if(s===setTimeout)return setTimeout(e,0);if((s===n||!s)&&setTimeout)return s=setTimeout,setTimeout(e,0);try{return s(e,0)}catch(t){try{return s.call(null,e,0)}catch(t){return s.call(this,e,0)}}}function i(e){if(l===clearTimeout)return clearTimeout(e);if((l===r||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{return l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}function u(){h&&d&&(h=!1,d.length?y=d.concat(y):v=-1,y.length&&a())}function a(){if(!h){var e=o(u);h=!0;for(var t=y.length;t;){for(d=y,y=[];++v<t;)d&&d[v].run();v=-1,t=y.length}d=null,h=!1,i(e)}}function f(e,t){this.fun=e,this.array=t}function c(){}var s,l,p=e.exports={};!function(){try{s="function"==typeof setTimeout?setTimeout:n}catch(e){s=n}try{l="function"==typeof clearTimeout?clearTimeout:r}catch(e){l=r}}();var d,y=[],h=!1,v=-1;p.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new f(e,t)),1!==y.length||h||o(a)},f.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=c,p.addListener=c,p.once=c,p.off=c,p.removeListener=c,p.removeAllListeners=c,p.emit=c,p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0}},function(e,t,n){(function(t){"use strict";var r="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},o=n(7),i=n(8),u=n(9),a=n(10),f=n(11);e.exports=function(e,n){function c(e){var t=e&&(P&&e[P]||e[N]);if("function"==typeof t)return t}function s(e,t){return e===t?0!==e||1/e===1/t:e!==e&&t!==t}function l(e){this.message=e,this.stack=""}function p(e){function r(r,c,s,p,d,y,h){if(p=p||k,y=y||s,h!==a)if(n)i(!1,"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");else if("production"!==t.env.NODE_ENV&&"undefined"!=typeof console){var v=p+":"+s;!o[v]&&f<3&&(u(!1,"You are manually calling a React.PropTypes validation function for the `%s` prop on `%s`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.",y,p),o[v]=!0,f++)}return null==c[s]?r?new l(null===c[s]?"The "+d+" `"+y+"` is marked as required "+("in `"+p+"`, but its value is `null`."):"The "+d+" `"+y+"` is marked as required in "+("`"+p+"`, but its value is `undefined`.")):null:e(c,s,p,d,y)}if("production"!==t.env.NODE_ENV)var o={},f=0;var c=r.bind(null,!1);return c.isRequired=r.bind(null,!0),c}function d(e){function t(t,n,r,o,i,u){var a=t[n],f=_(a);if(f!==e){var c=E(a);return new l("Invalid "+o+" `"+i+"` of type "+("`"+c+"` supplied to `"+r+"`, expected ")+("`"+e+"`."))}return null}return p(t)}function y(){return p(o.thatReturnsNull)}function h(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var u=t[n];if(!Array.isArray(u)){var f=_(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+f+"` supplied to `"+r+"`, expected an array."))}for(var c=0;c<u.length;c++){var s=e(u,c,r,o,i+"["+c+"]",a);if(s instanceof Error)return s}return null}return p(t)}function v(){function t(t,n,r,o,i){var u=t[n];if(!e(u)){var a=_(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected a single ReactElement."))}return null}return p(t)}function m(e){function t(t,n,r,o,i){if(!(t[n]instanceof e)){var u=e.name||k,a=j(t[n]);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected ")+("instance of `"+u+"`."))}return null}return p(t)}function b(e){function n(t,n,r,o,i){for(var u=t[n],a=0;a<e.length;a++)if(s(u,e[a]))return null;var f=JSON.stringify(e);return new l("Invalid "+o+" `"+i+"` of value `"+u+"` "+("supplied to `"+r+"`, expected one of "+f+"."))}return Array.isArray(e)?p(n):("production"!==t.env.NODE_ENV?u(!1,"Invalid argument supplied to oneOf, expected an instance of array."):void 0,o.thatReturnsNull)}function g(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var u=t[n],f=_(u);if("object"!==f)return new l("Invalid "+o+" `"+i+"` of type "+("`"+f+"` supplied to `"+r+"`, expected an object."));for(var c in u)if(u.hasOwnProperty(c)){var s=e(u,c,r,o,i+"."+c,a);if(s instanceof Error)return s}return null}return p(t)}function w(e){function n(t,n,r,o,i){for(var u=0;u<e.length;u++){var f=e[u];if(null==f(t,n,r,o,i,a))return null}return new l("Invalid "+o+" `"+i+"` supplied to "+("`"+r+"`."))}if(!Array.isArray(e))return"production"!==t.env.NODE_ENV?u(!1,"Invalid argument supplied to oneOfType, expected an instance of array."):void 0,o.thatReturnsNull;for(var r=0;r<e.length;r++){var i=e[r];if("function"!=typeof i)return u(!1,"Invalid argument supplid to oneOfType. Expected an array of check functions, but received %s at index %s.",S(i),r),o.thatReturnsNull}return p(n)}function O(){function e(e,t,n,r,o){return T(e[t])?null:new l("Invalid "+r+" `"+o+"` supplied to "+("`"+n+"`, expected a ReactNode."))}return p(e)}function R(e){function t(t,n,r,o,i){var u=t[n],f=_(u);if("object"!==f)return new l("Invalid "+o+" `"+i+"` of type `"+f+"` "+("supplied to `"+r+"`, expected `object`."));for(var c in e){var s=e[c];if(s){var p=s(u,c,r,o,i+"."+c,a);if(p)return p}}return null}return p(t)}function T(t){switch("undefined"==typeof t?"undefined":r(t)){case"number":case"string":case"undefined":return!0;case"boolean":return!t;case"object":if(Array.isArray(t))return t.every(T);if(null===t||e(t))return!0;var n=c(t);if(!n)return!1;var o,i=n.call(t);if(n!==t.entries){for(;!(o=i.next()).done;)if(!T(o.value))return!1}else for(;!(o=i.next()).done;){var u=o.value;if(u&&!T(u[1]))return!1}return!0;default:return!1}}function x(e,t){return"symbol"===e||("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}function _(e){var t="undefined"==typeof e?"undefined":r(e);return Array.isArray(e)?"array":e instanceof RegExp?"object":x(t,e)?"symbol":t}function E(e){if("undefined"==typeof e||null===e)return""+e;var t=_(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function S(e){var t=E(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}function j(e){return e.constructor&&e.constructor.name?e.constructor.name:k}var P="function"==typeof Symbol&&Symbol.iterator,N="@@iterator",k="<<anonymous>>",I={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:y(),arrayOf:h,element:v(),instanceOf:m,node:O(),objectOf:g,oneOf:b,oneOfType:w,shape:R};return l.prototype=Error.prototype,I.checkPropTypes=f,I.PropTypes=I,I}}).call(t,n(5))},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t,n){(function(t){"use strict";function n(e,t,n,o,i,u,a,f){if(r(t),!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,i,u,a,f],l=0;c=new Error(t.replace(/%s/g,function(){return s[l++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}}var r=function(e){};"production"!==t.env.NODE_ENV&&(r=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")}),e.exports=n}).call(t,n(5))},function(e,t,n){(function(t){"use strict";var r=n(7),o=r;"production"!==t.env.NODE_ENV&&!function(){var e=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=0,i="Warning: "+e.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.error(i);try{throw new Error(i)}catch(e){}};o=function(t,n){if(void 0===n)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(0!==n.indexOf("Failed Composite propType: ")&&!t){for(var r=arguments.length,o=Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];e.apply(void 0,[n].concat(o))}}}(),e.exports=o}).call(t,n(5))},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(e,t,n){(function(t){"use strict";function r(e,n,r,c,s){if("production"!==t.env.NODE_ENV)for(var l in e)if(e.hasOwnProperty(l)){var p;try{i("function"==typeof e[l],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",c||"React class",r,l),p=e[l](n,l,c,r,null,a)}catch(e){p=e}if(u(!p||p instanceof Error,"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",c||"React class",r,l,"undefined"==typeof p?"undefined":o(p)),p instanceof Error&&!(p.message in f)){f[p.message]=!0;var d=s?s():"";u(!1,"Failed %s type: %s%s",r,p.message,null!=d?d:"")}}}var o="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};if("production"!==t.env.NODE_ENV)var i=n(8),u=n(9),a=n(10),f={};e.exports=r}).call(t,n(5))},function(e,t,n){"use strict";var r=n(7),o=n(8),i=n(10);e.exports=function(){function e(e,t,n,r,u,a){a!==i&&o(!1,"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")}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};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,n){e.exports=t},function(e,t){"use strict";function n(e,t){var n={};if(t.indexOf("client")>-1&&(n.client={top:e.clientTop,left:e.clientLeft,width:e.clientWidth,height:e.clientHeight}),t.indexOf("offset")>-1&&(n.offset={top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth,height:e.offsetHeight}),t.indexOf("scroll")>-1&&(n.scroll={top:e.scrollTop,left:e.scrollLeft,width:e.scrollWidth,height:e.scrollHeight}),t.indexOf("bounds")>-1){var r=e.getBoundingClientRect();n.bounds={top:r.top,right:r.right,bottom:r.bottom,left:r.left,width:r.width,height:r.height}}if(t.indexOf("margin")>-1){var o=getComputedStyle(e);n.margin={top:parseInt(o.marginTop),right:parseInt(o.marginRight),bottom:parseInt(o.marginBottom),left:parseInt(o.marginLeft)}}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("resize-observer-polyfill")):"function"==typeof define&&define.amd?define(["react","resize-observer-polyfill"],t):"object"==typeof exports?exports.Measure=t(require("react"),require("resize-observer-polyfill")):e.Measure=t(e.React,e.ResizeObserver)}(this,function(e,t){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="dist/",t(0)}([function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0}),t.withContentRect=t.default=void 0;var o=n(1),i=r(o),u=n(3),a=r(u);t.default=i.default,t.withContentRect=a.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function Measure(e){var t=e.measure,n=e.measureRef,r=e.contentRect,o=e.children;return o({measure:t,measureRef:n,contentRect:r})}Object.defineProperty(t,"__esModule",{value:!0});var o=n(2),i=(r(o),n(3)),u=r(i);t.default=(0,u.default)()(Measure),e.exports=t.default},function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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 a(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 f(e){return function(t){var n,r;return r=n=function(n){function r(){var t,n,o,a;i(this,r);for(var f=arguments.length,c=Array(f),s=0;s<f;s++)c[s]=arguments[s];return n=o=u(this,(t=r.__proto__||Object.getPrototypeOf(r)).call.apply(t,[this].concat(c))),o.state={contentRect:{entry:{},client:{},offset:{},scroll:{},bounds:{},margin:{}}},o.measure=function(t){var n=(0,g.default)(o._node,e||(0,m.default)(o.props));t&&(n.entry=t[0].contentRect),o.setState({contentRect:n}),"function"==typeof o.props.onResize&&o.props.onResize(n)},o._handleRef=function(e){o._node=e,o._resizeObserver&&(e?o._resizeObserver.observe(e):o._resizeObserver.disconnect(e)),"function"==typeof o.props.innerRef&&o.props.innerRef(e)},a=n,u(o,a)}return a(r,n),s(r,[{key:"componentWillMount",value:function(){this._resizeObserver=new v.default(this.measure)}},{key:"render",value:function(){var e=this.props,n=(e.innerRef,e.onResize,o(e,["innerRef","onResize"]));return(0,l.createElement)(t,c({},n,{measureRef:this._handleRef,measure:this.measure,contentRect:this.state.contentRect}))}}]),r}(l.Component),n.propTypes={client:d.default.bool,offset:d.default.bool,scroll:d.default.bool,bounds:d.default.bool,margin:d.default.bool,innerRef:d.default.func,onResize:d.default.func,children:d.default.func},r}}Object.defineProperty(t,"__esModule",{value:!0});var c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),l=n(2),p=(r(l),n(4)),d=r(p),y=n(13),v=r(y),h=n(14),m=r(h),b=n(15),g=r(b);t.default=f,e.exports=t.default},function(e,t,n){(function(t){"use strict";var r="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};if("production"!==t.env.NODE_ENV){var o="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,i=function(e){return"object"===("undefined"==typeof e?"undefined":r(e))&&null!==e&&e.$$typeof===o},u=!0;e.exports=n(6)(i,u)}else e.exports=n(12)()}).call(t,n(5))},function(e,t){"use strict";function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(e){if(s===setTimeout)return setTimeout(e,0);if((s===n||!s)&&setTimeout)return s=setTimeout,setTimeout(e,0);try{return s(e,0)}catch(t){try{return s.call(null,e,0)}catch(t){return s.call(this,e,0)}}}function i(e){if(l===clearTimeout)return clearTimeout(e);if((l===r||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{return l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}function u(){v&&d&&(v=!1,d.length?y=d.concat(y):h=-1,y.length&&a())}function a(){if(!v){var e=o(u);v=!0;for(var t=y.length;t;){for(d=y,y=[];++h<t;)d&&d[h].run();h=-1,t=y.length}d=null,v=!1,i(e)}}function f(e,t){this.fun=e,this.array=t}function c(){}var s,l,p=e.exports={};!function(){try{s="function"==typeof setTimeout?setTimeout:n}catch(e){s=n}try{l="function"==typeof clearTimeout?clearTimeout:r}catch(e){l=r}}();var d,y=[],v=!1,h=-1;p.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new f(e,t)),1!==y.length||v||o(a)},f.prototype.run=function(){this.fun.apply(null,this.array)},p.title="browser",p.browser=!0,p.env={},p.argv=[],p.version="",p.versions={},p.on=c,p.addListener=c,p.once=c,p.off=c,p.removeListener=c,p.removeAllListeners=c,p.emit=c,p.binding=function(e){throw new Error("process.binding is not supported")},p.cwd=function(){return"/"},p.chdir=function(e){throw new Error("process.chdir is not supported")},p.umask=function(){return 0}},function(e,t,n){(function(t){"use strict";var r="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},o=n(7),i=n(8),u=n(9),a=n(10),f=n(11);e.exports=function(e,n){function c(e){var t=e&&(P&&e[P]||e[N]);if("function"==typeof t)return t}function s(e,t){return e===t?0!==e||1/e===1/t:e!==e&&t!==t}function l(e){this.message=e,this.stack=""}function p(e){function r(r,c,s,p,d,y,v){if(p=p||k,y=y||s,v!==a)if(n)i(!1,"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");else if("production"!==t.env.NODE_ENV&&"undefined"!=typeof console){var h=p+":"+s;!o[h]&&f<3&&(u(!1,"You are manually calling a React.PropTypes validation function for the `%s` prop on `%s`. This is deprecated and will throw in the standalone `prop-types` package. You may be seeing this warning due to a third-party PropTypes library. See https://fb.me/react-warning-dont-call-proptypes for details.",y,p),o[h]=!0,f++)}return null==c[s]?r?new l(null===c[s]?"The "+d+" `"+y+"` is marked as required "+("in `"+p+"`, but its value is `null`."):"The "+d+" `"+y+"` is marked as required in "+("`"+p+"`, but its value is `undefined`.")):null:e(c,s,p,d,y)}if("production"!==t.env.NODE_ENV)var o={},f=0;var c=r.bind(null,!1);return c.isRequired=r.bind(null,!0),c}function d(e){function t(t,n,r,o,i,u){var a=t[n],f=_(a);if(f!==e){var c=E(a);return new l("Invalid "+o+" `"+i+"` of type "+("`"+c+"` supplied to `"+r+"`, expected ")+("`"+e+"`."))}return null}return p(t)}function y(){return p(o.thatReturnsNull)}function v(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside arrayOf.");var u=t[n];if(!Array.isArray(u)){var f=_(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+f+"` supplied to `"+r+"`, expected an array."))}for(var c=0;c<u.length;c++){var s=e(u,c,r,o,i+"["+c+"]",a);if(s instanceof Error)return s}return null}return p(t)}function h(){function t(t,n,r,o,i){var u=t[n];if(!e(u)){var a=_(u);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected a single ReactElement."))}return null}return p(t)}function m(e){function t(t,n,r,o,i){if(!(t[n]instanceof e)){var u=e.name||k,a=S(t[n]);return new l("Invalid "+o+" `"+i+"` of type "+("`"+a+"` supplied to `"+r+"`, expected ")+("instance of `"+u+"`."))}return null}return p(t)}function b(e){function n(t,n,r,o,i){for(var u=t[n],a=0;a<e.length;a++)if(s(u,e[a]))return null;var f=JSON.stringify(e);return new l("Invalid "+o+" `"+i+"` of value `"+u+"` "+("supplied to `"+r+"`, expected one of "+f+"."))}return Array.isArray(e)?p(n):("production"!==t.env.NODE_ENV?u(!1,"Invalid argument supplied to oneOf, expected an instance of array."):void 0,o.thatReturnsNull)}function g(e){function t(t,n,r,o,i){if("function"!=typeof e)return new l("Property `"+i+"` of component `"+r+"` has invalid PropType notation inside objectOf.");var u=t[n],f=_(u);if("object"!==f)return new l("Invalid "+o+" `"+i+"` of type "+("`"+f+"` supplied to `"+r+"`, expected an object."));for(var c in u)if(u.hasOwnProperty(c)){var s=e(u,c,r,o,i+"."+c,a);if(s instanceof Error)return s}return null}return p(t)}function O(e){function n(t,n,r,o,i){for(var u=0;u<e.length;u++){var f=e[u];if(null==f(t,n,r,o,i,a))return null}return new l("Invalid "+o+" `"+i+"` supplied to "+("`"+r+"`."))}if(!Array.isArray(e))return"production"!==t.env.NODE_ENV?u(!1,"Invalid argument supplied to oneOfType, expected an instance of array."):void 0,o.thatReturnsNull;for(var r=0;r<e.length;r++){var i=e[r];if("function"!=typeof i)return u(!1,"Invalid argument supplid to oneOfType. Expected an array of check functions, but received %s at index %s.",j(i),r),o.thatReturnsNull}return p(n)}function w(){function e(e,t,n,r,o){return R(e[t])?null:new l("Invalid "+r+" `"+o+"` supplied to "+("`"+n+"`, expected a ReactNode."))}return p(e)}function T(e){function t(t,n,r,o,i){var u=t[n],f=_(u);if("object"!==f)return new l("Invalid "+o+" `"+i+"` of type `"+f+"` "+("supplied to `"+r+"`, expected `object`."));for(var c in e){var s=e[c];if(s){var p=s(u,c,r,o,i+"."+c,a);if(p)return p}}return null}return p(t)}function R(t){switch("undefined"==typeof t?"undefined":r(t)){case"number":case"string":case"undefined":return!0;case"boolean":return!t;case"object":if(Array.isArray(t))return t.every(R);if(null===t||e(t))return!0;var n=c(t);if(!n)return!1;var o,i=n.call(t);if(n!==t.entries){for(;!(o=i.next()).done;)if(!R(o.value))return!1}else for(;!(o=i.next()).done;){var u=o.value;if(u&&!R(u[1]))return!1}return!0;default:return!1}}function x(e,t){return"symbol"===e||("Symbol"===t["@@toStringTag"]||"function"==typeof Symbol&&t instanceof Symbol)}function _(e){var t="undefined"==typeof e?"undefined":r(e);return Array.isArray(e)?"array":e instanceof RegExp?"object":x(t,e)?"symbol":t}function E(e){if("undefined"==typeof e||null===e)return""+e;var t=_(e);if("object"===t){if(e instanceof Date)return"date";if(e instanceof RegExp)return"regexp"}return t}function j(e){var t=E(e);switch(t){case"array":case"object":return"an "+t;case"boolean":case"date":case"regexp":return"a "+t;default:return t}}function S(e){return e.constructor&&e.constructor.name?e.constructor.name:k}var P="function"==typeof Symbol&&Symbol.iterator,N="@@iterator",k="<<anonymous>>",I={array:d("array"),bool:d("boolean"),func:d("function"),number:d("number"),object:d("object"),string:d("string"),symbol:d("symbol"),any:y(),arrayOf:v,element:h(),instanceOf:m,node:w(),objectOf:g,oneOf:b,oneOfType:O,shape:T};return l.prototype=Error.prototype,I.checkPropTypes=f,I.PropTypes=I,I}}).call(t,n(5))},function(e,t){"use strict";function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e},e.exports=r},function(e,t,n){(function(t){"use strict";function n(e,t,n,o,i,u,a,f){if(r(t),!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=[n,o,i,u,a,f],l=0;c=new Error(t.replace(/%s/g,function(){return s[l++]})),c.name="Invariant Violation"}throw c.framesToPop=1,c}}var r=function(e){};"production"!==t.env.NODE_ENV&&(r=function(e){if(void 0===e)throw new Error("invariant requires an error message argument")}),e.exports=n}).call(t,n(5))},function(e,t,n){(function(t){"use strict";var r=n(7),o=r;"production"!==t.env.NODE_ENV&&!function(){var e=function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=0,i="Warning: "+e.replace(/%s/g,function(){return n[o++]});"undefined"!=typeof console&&console.error(i);try{throw new Error(i)}catch(e){}};o=function(t,n){if(void 0===n)throw new Error("`warning(condition, format, ...args)` requires a warning message argument");if(0!==n.indexOf("Failed Composite propType: ")&&!t){for(var r=arguments.length,o=Array(r>2?r-2:0),i=2;i<r;i++)o[i-2]=arguments[i];e.apply(void 0,[n].concat(o))}}}(),e.exports=o}).call(t,n(5))},function(e,t){"use strict";var n="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED";e.exports=n},function(e,t,n){(function(t){"use strict";function r(e,n,r,c,s){if("production"!==t.env.NODE_ENV)for(var l in e)if(e.hasOwnProperty(l)){var p;try{i("function"==typeof e[l],"%s: %s type `%s` is invalid; it must be a function, usually from React.PropTypes.",c||"React class",r,l),p=e[l](n,l,c,r,null,a)}catch(e){p=e}if(u(!p||p instanceof Error,"%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",c||"React class",r,l,"undefined"==typeof p?"undefined":o(p)),p instanceof Error&&!(p.message in f)){f[p.message]=!0;var d=s?s():"";u(!1,"Failed %s type: %s%s",r,p.message,null!=d?d:"")}}}var o="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};if("production"!==t.env.NODE_ENV)var i=n(8),u=n(9),a=n(10),f={};e.exports=r}).call(t,n(5))},function(e,t,n){"use strict";var r=n(7),o=n(8),i=n(10);e.exports=function(){function e(e,t,n,r,u,a){a!==i&&o(!1,"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")}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};return n.checkPropTypes=r,n.PropTypes=n,n}},function(e,n){e.exports=t},function(e,t){"use strict";function n(e){var t=[];return r.forEach(function(n){e[n]&&t.push(n)}),t}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n;var r=["client","offset","scroll","bounds","margin"];e.exports=t.default},function(e,t){"use strict";function n(e,t){var n={};if(t.indexOf("client")>-1&&(n.client={top:e.clientTop,left:e.clientLeft,width:e.clientWidth,height:e.clientHeight}),t.indexOf("offset")>-1&&(n.offset={top:e.offsetTop,left:e.offsetLeft,width:e.offsetWidth,height:e.offsetHeight}),t.indexOf("scroll")>-1&&(n.scroll={top:e.scrollTop,left:e.scrollLeft,width:e.scrollWidth,height:e.scrollHeight}),t.indexOf("bounds")>-1){var r=e.getBoundingClientRect();n.bounds={top:r.top,right:r.right,bottom:r.bottom,left:r.left,width:r.width,height:r.height}}if(t.indexOf("margin")>-1){var o=getComputedStyle(e);n.margin={top:parseInt(o.marginTop),right:parseInt(o.marginRight),bottom:parseInt(o.marginBottom),left:parseInt(o.marginLeft)}}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.default=n,e.exports=t.default}])});

@@ -9,4 +9,2 @@ 'use strict';

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -26,2 +24,6 @@

var _getTypes = require('./get-types');
var _getTypes2 = _interopRequireDefault(_getTypes);
var _getContentRect = require('./get-content-rect');

@@ -41,14 +43,2 @@

var types = ['client', 'offset', 'scroll', 'bounds', 'margin'];
function getTypes(props) {
var allowedTypes = [];
types.forEach(function (type) {
if (props[type]) {
allowedTypes.push(type);
}
});
return allowedTypes;
}
function withContentRect(types) {

@@ -82,3 +72,3 @@ return function (WrappedComponent) {

}, _this.measure = function (entries) {
var contentRect = (0, _getContentRect2.default)(_this._node, types || getTypes(_this.props));
var contentRect = (0, _getContentRect2.default)(_this._node, types || (0, _getTypes2.default)(_this.props));

@@ -94,7 +84,15 @@ if (entries) {

}
}, _this._handleRef = function (component) {
_this._node = component;
}, _this._handleRef = function (node) {
_this._node = node;
if (_this._resizeObserver) {
if (node) {
_this._resizeObserver.observe(node);
} else {
_this._resizeObserver.disconnect(node);
}
}
if (typeof _this.props.innerRef === 'function') {
_this.props.innerRef(component);
_this.props.innerRef(node);
}

@@ -105,21 +103,7 @@ }, _temp), _possibleConstructorReturn(_this, _ret);

_createClass(_class, [{
key: 'componentDidMount',
value: function componentDidMount() {
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) !== 'object') return;
if (this._node) {
this._resizeObserver = new _resizeObserverPolyfill2.default(this.measure);
this._resizeObserver.observe(this._node);
} else {
console.error('No ref found, attach the `measureRef` prop to the component you want to measure.');
}
key: 'componentWillMount',
value: function componentWillMount() {
this._resizeObserver = new _resizeObserverPolyfill2.default(this.measure);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.resizeObserver && this._node) {
this._resizeObserver.disconnect(this._node);
}
}
}, {
key: 'render',

@@ -126,0 +110,0 @@ value: function render() {

{
"name": "react-measure",
"version": "2.0.0",
"version": "2.0.1",
"description": "Compute measurements of React components.",

@@ -5,0 +5,0 @@ "main": "lib/react-measure.js",

@@ -21,2 +21,4 @@ ## React Measure

Wrap any child component and calculate its client rect.
### Props

@@ -112,7 +114,10 @@

A higher-order component that provides dimensions to the wrapped component. Accepts `types` which determines what measurements are returned, similar to above. Pass an array or single value of either `client`, `offset`, `scroll`, `bounds`, or `margin` to calculate and receive those measurements as the prop `contentRect` in your wrapped component. You can also use the `measure` function passed down to programmatically measure your component if you need to.
A higher-order component that provides dimensions to the wrapped component. Accepts `types`, which determines what measurements are returned, similar to above. Then returns a function to pass the component you want measured.
**please note**
`measureRef` must be passed down to your component's ref in order to obtain a proper node to measure
Pass an array or single value of either `client`, `offset`, `scroll`, `bounds`, or `margin` to calculate and receive those measurements as the prop `contentRect` in your wrapped component. You can also use the `measure` function passed down to programmatically measure your component if you need to. And finally, remember to pass down the `measureRef` to the component you want measured.
Passes down the same props as the `Measure` child function above, `measureRef`, `measure`, and `contentRect`.
Fun fact, the `Measure` component is a thin wrapper around `withContentRect`. Just check [the source](https://github.com/souporserious/react-measure/blob/master/src/Measure.jsx). This means your wrapped component will accept the same props as `Measure` does 😊
### Example

@@ -119,0 +124,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