react-measure
Advanced tools
Comparing version 1.2.0 to 1.2.1
## CHANGELOG | ||
### 1.2.1 | ||
Ensure `setState` is not called after unmounting [#18](https://github.com/souporserious/react-measure/pull/18) | ||
### 1.2.0 | ||
@@ -3,0 +6,0 @@ Provide dimension defaults |
@@ -0,1 +1,6 @@ | ||
/*! | ||
* React Measure 1.2.1 | ||
* https://github.com/souporserious/react-measure | ||
* Copyright (c) 2016 React Measure Authors | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
@@ -59,8 +64,7 @@ if(typeof exports === 'object' && typeof module === 'object') | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _Measure = __webpack_require__(1); | ||
@@ -70,5 +74,6 @@ | ||
exports['default'] = _Measure2['default']; | ||
module.exports = exports['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _Measure2.default; | ||
/***/ }, | ||
@@ -80,3 +85,3 @@ /* 1 */ | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
@@ -87,12 +92,4 @@ }); | ||
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; }; })(); | ||
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; }; }(); | ||
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _react = __webpack_require__(2); | ||
@@ -114,40 +111,20 @@ | ||
var Measure = (function (_Component) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Measure = function (_Component) { | ||
_inherits(Measure, _Component); | ||
_createClass(Measure, null, [{ | ||
key: 'propTypes', | ||
value: { | ||
whitelist: _react.PropTypes.array, | ||
blacklist: _react.PropTypes.array, | ||
useClone: _react.PropTypes.bool, | ||
cloneOptions: _react.PropTypes.object, | ||
shouldMeasure: _react.PropTypes.bool, | ||
onMeasure: _react.PropTypes.func | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'defaultProps', | ||
value: { | ||
whitelist: ['width', 'height', 'top', 'right', 'bottom', 'left'], | ||
blacklist: [], | ||
useClone: false, | ||
cloneOptions: {}, | ||
shouldMeasure: true, | ||
onMeasure: function onMeasure() { | ||
return null; | ||
} | ||
}, | ||
enumerable: true | ||
}]); | ||
function Measure(props) { | ||
var _this = this; | ||
_classCallCheck(this, Measure); | ||
_get(Object.getPrototypeOf(Measure.prototype), 'constructor', this).call(this, props); | ||
var _this = _possibleConstructorReturn(this, (Measure.__proto__ || Object.getPrototypeOf(Measure)).call(this, props)); | ||
this.measure = function () { | ||
var useClone = arguments.length <= 0 || arguments[0] === undefined ? _this.props.useClone : arguments[0]; | ||
_this.measure = function () { | ||
var useClone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.useClone; | ||
@@ -167,3 +144,3 @@ // bail out if we shouldn't measure | ||
// update state to send dimensions to child function | ||
if (isChildFunction) { | ||
if (isChildFunction && typeof _this !== 'undefined') { | ||
_this.setState({ dimensions: dimensions }); | ||
@@ -181,3 +158,3 @@ } | ||
this.state = { | ||
_this.state = { | ||
dimensions: { | ||
@@ -192,5 +169,6 @@ width: 0, | ||
}; | ||
this._node = null; | ||
this._propsToMeasure = this._getPropsToMeasure(props); | ||
this._lastDimensions = {}; | ||
_this._node = null; | ||
_this._propsToMeasure = _this._getPropsToMeasure(props); | ||
_this._lastDimensions = {}; | ||
return _this; | ||
} | ||
@@ -203,3 +181,3 @@ | ||
this._node = _reactDom2['default'].findDOMNode(this); | ||
this._node = _reactDom2.default.findDOMNode(this); | ||
@@ -210,3 +188,3 @@ // measure on first render | ||
// add component to resize detector to detect changes on resize | ||
(0, _resizeDetector2['default'])().listenTo(this._node, function () { | ||
(0, _resizeDetector2.default)().listenTo(this._node, function () { | ||
return _this2.measure(); | ||
@@ -231,4 +209,4 @@ }); | ||
value: function componentWillUnmount() { | ||
(0, _resizeDetector2['default'])().removeAllListeners(this._node); | ||
(0, _resizeDetector2['default'])().uninstall(this._node); | ||
(0, _resizeDetector2.default)().removeAllListeners(this._node); | ||
(0, _resizeDetector2.default)().uninstall(this._node); | ||
this._node = null; | ||
@@ -239,7 +217,7 @@ } | ||
value: function getDimensions() { | ||
var node = arguments.length <= 0 || arguments[0] === undefined ? this._node : arguments[0]; | ||
var useClone = arguments.length <= 1 || arguments[1] === undefined ? this.props.useClone : arguments[1]; | ||
var cloneOptions = arguments.length <= 2 || arguments[2] === undefined ? this.props.cloneOptions : arguments[2]; | ||
var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._node; | ||
var useClone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.props.useClone; | ||
var cloneOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.props.cloneOptions; | ||
return (0, _getNodeDimensions2['default'])(node, _extends({ clone: useClone }, cloneOptions)); | ||
return (0, _getNodeDimensions2.default)(node, _extends({ clone: useClone }, cloneOptions)); | ||
} | ||
@@ -266,6 +244,23 @@ }, { | ||
return Measure; | ||
})(_react.Component); | ||
}(_react.Component); | ||
exports['default'] = Measure; | ||
module.exports = exports['default']; | ||
Measure.propTypes = { | ||
whitelist: _react.PropTypes.array, | ||
blacklist: _react.PropTypes.array, | ||
useClone: _react.PropTypes.bool, | ||
cloneOptions: _react.PropTypes.object, | ||
shouldMeasure: _react.PropTypes.bool, | ||
onMeasure: _react.PropTypes.func | ||
}; | ||
Measure.defaultProps = { | ||
whitelist: ['width', 'height', 'top', 'right', 'bottom', 'left'], | ||
blacklist: [], | ||
useClone: false, | ||
cloneOptions: {}, | ||
shouldMeasure: true, | ||
onMeasure: function onMeasure() { | ||
return null; | ||
} | ||
}; | ||
exports.default = Measure; | ||
@@ -296,9 +291,7 @@ /***/ }, | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports['default'] = resizeDetector; | ||
exports.default = resizeDetector; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _elementResizeDetector = __webpack_require__(6); | ||
@@ -308,2 +301,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var instance = null; | ||
@@ -313,3 +308,3 @@ | ||
if (!instance) { | ||
instance = (0, _elementResizeDetector2['default'])({ | ||
instance = (0, _elementResizeDetector2.default)({ | ||
strategy: 'scroll' | ||
@@ -321,4 +316,2 @@ }); | ||
module.exports = exports['default']; | ||
/***/ }, | ||
@@ -325,0 +318,0 @@ /* 6 */ |
@@ -1,1 +0,6 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom"),require("get-node-dimensions"),require("element-resize-detector")):"function"==typeof define&&define.amd?define(["react","react-dom","get-node-dimensions","element-resize-detector"],t):"object"==typeof exports?exports.Measure=t(require("react"),require("react-dom"),require("get-node-dimensions"),require("element-resize-detector")):e.Measure=t(e.React,e.ReactDOM,e.getNodeDimensions,e.elementResizeDetectorMaker)}(this,function(e,t,o,r){return function(e){function t(r){if(o[r])return o[r].exports;var n=o[r]={exports:{},id:r,loaded:!1};return e[r].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var o={};return t.m=e,t.c=o,t.p="dist/",t(0)}([function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0});var n=o(1),i=r(n);t["default"]=i["default"],e.exports=t["default"]},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(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 s=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},u=function(){function e(e,t){for(var o=0;o<t.length;o++){var r=t[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,o,r){return o&&e(t.prototype,o),r&&e(t,r),t}}(),l=function(e,t,o){for(var r=!0;r;){var n=e,i=t,s=o;r=!1,null===n&&(n=Function.prototype);var u=Object.getOwnPropertyDescriptor(n,i);if(void 0!==u){if("value"in u)return u.value;var l=u.get;if(void 0===l)return;return l.call(s)}var a=Object.getPrototypeOf(n);if(null===a)return;e=a,t=i,o=s,r=!0,u=a=void 0}},a=o(2),c=(r(a),o(3)),p=r(c),f=o(4),d=r(f),h=o(5),v=r(h),Measure=function(e){function Measure(e){var t=this;n(this,Measure),l(Object.getPrototypeOf(Measure.prototype),"constructor",this).call(this,e),this.measure=function(){var e=arguments.length<=0||void 0===arguments[0]?t.props.useClone:arguments[0];if(t.props.shouldMeasure){var o=t.getDimensions(t._node,e),r="function"==typeof t.props.children;t._propsToMeasure.some(function(e){if(o[e]!==t._lastDimensions[e])return t.props.onMeasure(o),r&&t.setState({dimensions:o}),t._lastDimensions=o,!0})}},this.state={dimensions:{width:0,height:0,top:0,right:0,bottom:0,left:0}},this._node=null,this._propsToMeasure=this._getPropsToMeasure(e),this._lastDimensions={}}return i(Measure,e),u(Measure,null,[{key:"propTypes",value:{whitelist:a.PropTypes.array,blacklist:a.PropTypes.array,useClone:a.PropTypes.bool,cloneOptions:a.PropTypes.object,shouldMeasure:a.PropTypes.bool,onMeasure:a.PropTypes.func},enumerable:!0},{key:"defaultProps",value:{whitelist:["width","height","top","right","bottom","left"],blacklist:[],useClone:!1,cloneOptions:{},shouldMeasure:!0,onMeasure:function(){return null}},enumerable:!0}]),u(Measure,[{key:"componentDidMount",value:function(){var e=this;this._node=p["default"].findDOMNode(this),this.measure(),(0,v["default"])().listenTo(this._node,function(){return e.measure()})}},{key:"componentWillReceiveProps",value:function(e){var t=(e.config,e.whitelist),o=e.blacklist;this.props.whitelist===t&&this.props.blacklist===o||(this._propsToMeasure=this._getPropsToMeasure({whitelist:t,blacklist:o}))}},{key:"componentWillUnmount",value:function(){(0,v["default"])().removeAllListeners(this._node),(0,v["default"])().uninstall(this._node),this._node=null}},{key:"getDimensions",value:function(){var e=arguments.length<=0||void 0===arguments[0]?this._node:arguments[0],t=arguments.length<=1||void 0===arguments[1]?this.props.useClone:arguments[1],o=arguments.length<=2||void 0===arguments[2]?this.props.cloneOptions:arguments[2];return(0,d["default"])(e,s({clone:t},o))}},{key:"_getPropsToMeasure",value:function(e){var t=e.whitelist,o=e.blacklist;return t.filter(function(e){return o.indexOf(e)<0})}},{key:"render",value:function(){var e=this.props.children;return a.Children.only("function"==typeof e?e(this.state.dimensions):e)}}]),Measure}(a.Component);t["default"]=Measure,e.exports=t["default"]},function(t,o){t.exports=e},function(e,o){e.exports=t},function(e,t){e.exports=o},function(e,t,o){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function n(){return u||(u=(0,s["default"])({strategy:"scroll"})),u}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=n;var i=o(6),s=r(i),u=null;e.exports=t["default"]},function(e,t){e.exports=r}])}); | ||
/*! | ||
* React Measure 1.2.1 | ||
* https://github.com/souporserious/react-measure | ||
* Copyright (c) 2016 React Measure Authors | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("react-dom"),require("get-node-dimensions"),require("element-resize-detector")):"function"==typeof define&&define.amd?define(["react","react-dom","get-node-dimensions","element-resize-detector"],t):"object"==typeof exports?exports.Measure=t(require("react"),require("react-dom"),require("get-node-dimensions"),require("element-resize-detector")):e.Measure=t(e.React,e.ReactDOM,e.getNodeDimensions,e.elementResizeDetectorMaker)}(this,function(e,t,o,n){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="dist/",t(0)}([function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=void 0;var r=o(1),i=n(r);t["default"]=i["default"]},function(e,t,o){"use strict";function n(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 i(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 s(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 u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}return e},l=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),a=o(2),c=(n(a),o(3)),p=n(c),f=o(4),d=n(f),h=o(5),y=n(h),Measure=function(e){function Measure(e){r(this,Measure);var t=i(this,(Measure.__proto__||Object.getPrototypeOf(Measure)).call(this,e));return t.measure=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:t.props.useClone;if(t.props.shouldMeasure){var o=t.getDimensions(t._node,e),n="function"==typeof t.props.children;t._propsToMeasure.some(function(e){if(o[e]!==t._lastDimensions[e])return t.props.onMeasure(o),n&&"undefined"!=typeof t&&t.setState({dimensions:o}),t._lastDimensions=o,!0})}},t.state={dimensions:{width:0,height:0,top:0,right:0,bottom:0,left:0}},t._node=null,t._propsToMeasure=t._getPropsToMeasure(e),t._lastDimensions={},t}return s(Measure,e),l(Measure,[{key:"componentDidMount",value:function(){var e=this;this._node=p["default"].findDOMNode(this),this.measure(),(0,y["default"])().listenTo(this._node,function(){return e.measure()})}},{key:"componentWillReceiveProps",value:function(e){var t=(e.config,e.whitelist),o=e.blacklist;this.props.whitelist===t&&this.props.blacklist===o||(this._propsToMeasure=this._getPropsToMeasure({whitelist:t,blacklist:o}))}},{key:"componentWillUnmount",value:function(){(0,y["default"])().removeAllListeners(this._node),(0,y["default"])().uninstall(this._node),this._node=null}},{key:"getDimensions",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this._node,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.props.useClone,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.props.cloneOptions;return(0,d["default"])(e,u({clone:t},o))}},{key:"_getPropsToMeasure",value:function(e){var t=e.whitelist,o=e.blacklist;return t.filter(function(e){return o.indexOf(e)<0})}},{key:"render",value:function(){var e=this.props.children;return a.Children.only("function"==typeof e?e(this.state.dimensions):e)}}]),Measure}(a.Component);Measure.propTypes={whitelist:a.PropTypes.array,blacklist:a.PropTypes.array,useClone:a.PropTypes.bool,cloneOptions:a.PropTypes.object,shouldMeasure:a.PropTypes.bool,onMeasure:a.PropTypes.func},Measure.defaultProps={whitelist:["width","height","top","right","bottom","left"],blacklist:[],useClone:!1,cloneOptions:{},shouldMeasure:!0,onMeasure:function(){return null}},t["default"]=Measure},function(t,o){t.exports=e},function(e,o){e.exports=t},function(e,t){e.exports=o},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(){return u||(u=(0,s["default"])({strategy:"scroll"})),u}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r;var i=o(6),s=n(i),u=null},function(e,t){e.exports=n}])}); |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
@@ -9,12 +9,4 @@ }); | ||
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; }; })(); | ||
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; }; }(); | ||
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var _react = require('react'); | ||
@@ -36,40 +28,20 @@ | ||
var Measure = (function (_Component) { | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Measure = function (_Component) { | ||
_inherits(Measure, _Component); | ||
_createClass(Measure, null, [{ | ||
key: 'propTypes', | ||
value: { | ||
whitelist: _react.PropTypes.array, | ||
blacklist: _react.PropTypes.array, | ||
useClone: _react.PropTypes.bool, | ||
cloneOptions: _react.PropTypes.object, | ||
shouldMeasure: _react.PropTypes.bool, | ||
onMeasure: _react.PropTypes.func | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'defaultProps', | ||
value: { | ||
whitelist: ['width', 'height', 'top', 'right', 'bottom', 'left'], | ||
blacklist: [], | ||
useClone: false, | ||
cloneOptions: {}, | ||
shouldMeasure: true, | ||
onMeasure: function onMeasure() { | ||
return null; | ||
} | ||
}, | ||
enumerable: true | ||
}]); | ||
function Measure(props) { | ||
var _this = this; | ||
_classCallCheck(this, Measure); | ||
_get(Object.getPrototypeOf(Measure.prototype), 'constructor', this).call(this, props); | ||
var _this = _possibleConstructorReturn(this, (Measure.__proto__ || Object.getPrototypeOf(Measure)).call(this, props)); | ||
this.measure = function () { | ||
var useClone = arguments.length <= 0 || arguments[0] === undefined ? _this.props.useClone : arguments[0]; | ||
_this.measure = function () { | ||
var useClone = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.useClone; | ||
@@ -89,3 +61,3 @@ // bail out if we shouldn't measure | ||
// update state to send dimensions to child function | ||
if (isChildFunction) { | ||
if (isChildFunction && typeof _this !== 'undefined') { | ||
_this.setState({ dimensions: dimensions }); | ||
@@ -103,3 +75,3 @@ } | ||
this.state = { | ||
_this.state = { | ||
dimensions: { | ||
@@ -114,5 +86,6 @@ width: 0, | ||
}; | ||
this._node = null; | ||
this._propsToMeasure = this._getPropsToMeasure(props); | ||
this._lastDimensions = {}; | ||
_this._node = null; | ||
_this._propsToMeasure = _this._getPropsToMeasure(props); | ||
_this._lastDimensions = {}; | ||
return _this; | ||
} | ||
@@ -125,3 +98,3 @@ | ||
this._node = _reactDom2['default'].findDOMNode(this); | ||
this._node = _reactDom2.default.findDOMNode(this); | ||
@@ -132,3 +105,3 @@ // measure on first render | ||
// add component to resize detector to detect changes on resize | ||
(0, _resizeDetector2['default'])().listenTo(this._node, function () { | ||
(0, _resizeDetector2.default)().listenTo(this._node, function () { | ||
return _this2.measure(); | ||
@@ -153,4 +126,4 @@ }); | ||
value: function componentWillUnmount() { | ||
(0, _resizeDetector2['default'])().removeAllListeners(this._node); | ||
(0, _resizeDetector2['default'])().uninstall(this._node); | ||
(0, _resizeDetector2.default)().removeAllListeners(this._node); | ||
(0, _resizeDetector2.default)().uninstall(this._node); | ||
this._node = null; | ||
@@ -161,7 +134,7 @@ } | ||
value: function getDimensions() { | ||
var node = arguments.length <= 0 || arguments[0] === undefined ? this._node : arguments[0]; | ||
var useClone = arguments.length <= 1 || arguments[1] === undefined ? this.props.useClone : arguments[1]; | ||
var cloneOptions = arguments.length <= 2 || arguments[2] === undefined ? this.props.cloneOptions : arguments[2]; | ||
var node = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._node; | ||
var useClone = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.props.useClone; | ||
var cloneOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : this.props.cloneOptions; | ||
return (0, _getNodeDimensions2['default'])(node, _extends({ clone: useClone }, cloneOptions)); | ||
return (0, _getNodeDimensions2.default)(node, _extends({ clone: useClone }, cloneOptions)); | ||
} | ||
@@ -188,5 +161,22 @@ }, { | ||
return Measure; | ||
})(_react.Component); | ||
}(_react.Component); | ||
exports['default'] = Measure; | ||
module.exports = exports['default']; | ||
Measure.propTypes = { | ||
whitelist: _react.PropTypes.array, | ||
blacklist: _react.PropTypes.array, | ||
useClone: _react.PropTypes.bool, | ||
cloneOptions: _react.PropTypes.object, | ||
shouldMeasure: _react.PropTypes.bool, | ||
onMeasure: _react.PropTypes.func | ||
}; | ||
Measure.defaultProps = { | ||
whitelist: ['width', 'height', 'top', 'right', 'bottom', 'left'], | ||
blacklist: [], | ||
useClone: false, | ||
cloneOptions: {}, | ||
shouldMeasure: true, | ||
onMeasure: function onMeasure() { | ||
return null; | ||
} | ||
}; | ||
exports.default = Measure; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = undefined; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _Measure = require('./Measure'); | ||
@@ -13,3 +12,4 @@ | ||
exports['default'] = _Measure2['default']; | ||
module.exports = exports['default']; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = _Measure2.default; |
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports['default'] = resizeDetector; | ||
exports.default = resizeDetector; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } | ||
var _elementResizeDetector = require('element-resize-detector'); | ||
@@ -14,2 +12,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var instance = null; | ||
@@ -19,3 +19,3 @@ | ||
if (!instance) { | ||
instance = (0, _elementResizeDetector2['default'])({ | ||
instance = (0, _elementResizeDetector2.default)({ | ||
strategy: 'scroll' | ||
@@ -25,4 +25,2 @@ }); | ||
return instance; | ||
} | ||
module.exports = exports['default']; | ||
} |
{ | ||
"name": "react-measure", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Compute measurements of React components.", | ||
@@ -11,9 +11,8 @@ "main": "lib/react-measure.js", | ||
"scripts": { | ||
"build:lib": "babel src --out-dir lib", | ||
"build": "npm run build:lib && NODE_ENV=production webpack --config webpack.prod.config.js", | ||
"build:lib": "babel src --out-dir lib --stage 0", | ||
"dev": "webpack-dev-server --devtool eval --hot --progress --colors", | ||
"prebuild": "rm -rf dist lib && mkdir dist lib", | ||
"prepublish": "npm run build", | ||
"postbuild": "NODE_ENV=production TARGET=minify webpack --config webpack.prod.config.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"prebuild": "rm -rf dist && mkdir dist", | ||
"prepublish": "npm run build" | ||
}, | ||
@@ -49,18 +48,22 @@ "repository": { | ||
"devDependencies": { | ||
"autoprefixer-loader": "^2.0.0", | ||
"babel": "^5.8.23", | ||
"babel-core": "^5.6.15", | ||
"babel-loader": "^5.2.2", | ||
"css-loader": "^0.15.1", | ||
"http-server": "^0.8.0", | ||
"node-libs-browser": "^0.5.2", | ||
"babel-cli": "^6.16.0", | ||
"babel-core": "^6.17.0", | ||
"babel-loader": "^6.2.5", | ||
"babel-preset-es2015": "^6.16.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-0": "^6.16.0", | ||
"chokidar": "^1.6.1", | ||
"css-loader": "^0.25.0", | ||
"http-server": "^0.9.0", | ||
"node-libs-browser": "^1.0.0", | ||
"node-sass": "^3.2.0", | ||
"react": "15.2.1", | ||
"react-dom": "15.2.1", | ||
"postcss-loader": "^0.13.0", | ||
"react": "15.3.2", | ||
"react-dom": "15.3.2", | ||
"react-motion": "^0.4.2", | ||
"sass-loader": "^1.0.2", | ||
"style-loader": "^0.12.3", | ||
"webpack": "^1.9.12", | ||
"sass-loader": "^4.0.2", | ||
"style-loader": "^0.13.1", | ||
"webpack": "^1.13.2", | ||
"webpack-dev-server": "^1.9.0" | ||
} | ||
} |
@@ -25,2 +25,3 @@ ## React Measure | ||
import Measure from 'react-measure'; | ||
import classNames from 'classnames'; | ||
@@ -33,3 +34,7 @@ class ItemToMeasure extends Component { | ||
render() { | ||
const { height } = this.state.dimensions | ||
const { width, height } = this.state.dimensions | ||
const className = classNames( | ||
(width < 400) && 'small-width-modifier' | ||
) | ||
return ( | ||
@@ -41,4 +46,8 @@ <Measure | ||
> | ||
<div> | ||
<div className={className}> | ||
I can do cool things with my dimensions now :D | ||
{ (height > 250) && | ||
<div>Render responsive content based on the component size!</div> | ||
} | ||
</div> | ||
@@ -56,17 +65,14 @@ </Measure> | ||
class ItemToMeasure extends Component { | ||
render() { | ||
return ( | ||
<Measure> | ||
{ dimensions => | ||
<div> | ||
{Object.keys(dimensions).map((dimension, i) => | ||
<div key={i}>{dimension}: {dimensions[dimension]}</div> | ||
)} | ||
</div> | ||
} | ||
</Measure> | ||
) | ||
} | ||
} | ||
const ItemToMeasure = () => ( | ||
<Measure> | ||
{ dimensions => | ||
<div> | ||
Some content here | ||
<pre> | ||
{JSON.stringify(dimensions, null, 2)} | ||
</pre> | ||
</div> | ||
} | ||
</Measure> | ||
) | ||
``` | ||
@@ -73,0 +79,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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
1
126
33250
19
404