react-sizeme
Advanced tools
Comparing version 2.6.6 to 2.6.7
@@ -11,4 +11,3 @@ 'use strict'; | ||
var invariant = _interopDefault(require('invariant')); | ||
var throttle = _interopDefault(require('lodash.throttle')); | ||
var debounce = _interopDefault(require('lodash.debounce')); | ||
var throttleDebounce = require('throttle-debounce'); | ||
var isShallowEqual = _interopDefault(require('shallowequal')); | ||
@@ -274,3 +273,3 @@ | ||
var refreshDelayStrategy = refreshMode === 'throttle' ? throttle : debounce; | ||
var refreshDelayStrategy = refreshMode === 'throttle' ? throttleDebounce.throttle : throttleDebounce.debounce; | ||
@@ -334,3 +333,3 @@ return function WrapComponent(WrappedComponent) { | ||
return monitorWidth && c.width !== n.width || monitorHeight && c.height !== n.height || monitorPosition && (cp.top !== np.top || cp.left !== np.left || cp.bottom !== np.bottom || cp.right !== np.right); | ||
}, _this2.checkIfSizeChanged = refreshDelayStrategy(function (el) { | ||
}, _this2.checkIfSizeChanged = refreshDelayStrategy(refreshRate, function (el) { | ||
var _el$getBoundingClient = el.getBoundingClientRect(), | ||
@@ -353,3 +352,3 @@ width = _el$getBoundingClient.width, | ||
} | ||
}, refreshRate), _temp), possibleConstructorReturn(_this2, _ret); | ||
}), _temp), possibleConstructorReturn(_this2, _ret); | ||
} | ||
@@ -356,0 +355,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var createResizeDetector=_interopDefault(require("element-resize-detector")),React=require("react"),React__default=_interopDefault(React),PropTypes=_interopDefault(require("prop-types")),ReactDOM=_interopDefault(require("react-dom")),invariant=_interopDefault(require("invariant")),throttle=_interopDefault(require("lodash.throttle")),debounce=_interopDefault(require("lodash.debounce")),isShallowEqual=_interopDefault(require("shallowequal")),instances={};function resizeDetector(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"scroll";return instances[e]||(instances[e]=createResizeDetector({strategy:e})),instances[e]}var classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function i(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},inherits=function(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)},objectWithoutProperties=function(e,t){var r={};for(var i in e)0<=t.indexOf(i)||Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i]);return r},possibleConstructorReturn=function(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},errMsg="react-sizeme: an error occurred whilst stopping to listen to node size changes",defaultConfig={monitorWidth:!0,monitorHeight:!1,monitorPosition:!1,refreshRate:16,refreshMode:"throttle",noPlaceholder:!1,resizeDetectorStrategy:"scroll"};function getDisplayName(e){return e.displayName||e.name||"Component"}var ReferenceWrapper=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"render",value:function(){return React.Children.only(this.props.children)}}]),t}(React.Component);function Placeholder(e){var t=e.className,r=e.style,i={};return t||r?(t&&(i.className=t),r&&(i.style=r)):i.style={width:"100%",height:"100%"},React__default.createElement("div",i)}ReferenceWrapper.displayName="SizeMeReferenceWrapper",ReferenceWrapper.propTypes={children:PropTypes.element.isRequired},Placeholder.displayName="SizeMePlaceholder",Placeholder.propTypes={className:PropTypes.string,style:PropTypes.object};var renderWrapper=function(h){function e(e){var t=e.explicitRef,r=e.className,i=e.style,n=e.size,o=e.disablePlaceholder,a=(e.onSize,objectWithoutProperties(e,["explicitRef","className","style","size","disablePlaceholder","onSize"])),s=(null==n||null==n.width&&null==n.height&&null==n.position)&&!o,l={className:r,style:i};null!=n&&(l.size=n);var c=s?React__default.createElement(Placeholder,{className:r,style:i}):React__default.createElement(h,_extends({},l,a));return React__default.createElement(ReferenceWrapper,{ref:t},c)}return e.displayName="SizeMeRenderer("+getDisplayName(h)+")",e.propTypes={explicitRef:PropTypes.func.isRequired,className:PropTypes.string,style:PropTypes.object,size:PropTypes.shape({width:PropTypes.number,height:PropTypes.number}),disablePlaceholder:PropTypes.bool,onSize:PropTypes.func},e};function withSize(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultConfig,t=e.monitorWidth,h=void 0===t?defaultConfig.monitorWidth:t,r=e.monitorHeight,u=void 0===r?defaultConfig.monitorHeight:r,i=e.monitorPosition,p=void 0===i?defaultConfig.monitorPosition:i,n=e.refreshRate,a=void 0===n?defaultConfig.refreshRate:n,o=e.refreshMode,s=void 0===o?defaultConfig.refreshMode:o,l=e.noPlaceholder,c=void 0===l?defaultConfig.noPlaceholder:l,d=e.resizeDetectorStrategy,f=void 0===d?defaultConfig.resizeDetectorStrategy:d;invariant(h||u||p,'You have to monitor at least one of the width, height, or position when using "sizeMe"'),invariant(16<=a,"It is highly recommended that you don't put your refreshRate lower than 16 as this may cause layout thrashing."),invariant("throttle"===s||"debounce"===s,'The refreshMode should have a value of "throttle" or "debounce"');var y="throttle"===s?throttle:debounce;return function(e){var r=renderWrapper(e),t=function(e){function o(){var e,t,c;classCallCheck(this,o);for(var r=arguments.length,i=Array(r),n=0;n<r;n++)i[n]=arguments[n];return(t=c=possibleConstructorReturn(this,(e=o.__proto__||Object.getPrototypeOf(o)).call.apply(e,[this].concat(i)))).domEl=null,c.state={width:void 0,height:void 0,position:void 0},c.uninstall=function(){if(c.domEl){try{c.detector.uninstall(c.domEl)}catch(e){console.warn(errMsg)}c.domEl=null}},c.determineStrategy=function(e){e.onSize?(c.callbackState||(c.callbackState=_extends({},c.state)),c.strategy="callback"):c.strategy="render"},c.strategisedSetState=function(e){"callback"===c.strategy&&(c.callbackState=e,c.props.onSize(e)),c.setState(e)},c.strategisedGetState=function(){return"callback"===c.strategy?c.callbackState:c.state},c.refCallback=function(e){c.element=e},c.hasSizeChanged=function(e,t){var r=e,i=t,n=r.position||{},o=i.position||{};return h&&r.width!==i.width||u&&r.height!==i.height||p&&(n.top!==o.top||n.left!==o.left||n.bottom!==o.bottom||n.right!==o.right)},c.checkIfSizeChanged=y(function(e){var t=e.getBoundingClientRect(),r=t.width,i=t.height,n=t.right,o=t.left,a=t.top,s=t.bottom,l={width:h?r:null,height:u?i:null,position:p?{right:n,left:o,top:a,bottom:s}:null};c.hasSizeChanged(c.strategisedGetState(),l)&&c.strategisedSetState(l)},a),possibleConstructorReturn(c,t)}return inherits(o,e),createClass(o,[{key:"componentDidMount",value:function(){this.detector=resizeDetector(f),this.determineStrategy(this.props),this.handleDOMNode()}},{key:"componentDidUpdate",value:function(){this.determineStrategy(this.props),this.handleDOMNode()}},{key:"componentWillUnmount",value:function(){this.hasSizeChanged=function(){},this.checkIfSizeChanged=function(){},this.uninstall()}},{key:"handleDOMNode",value:function(){var e=this.element&&ReactDOM.findDOMNode(this.element);e?this.domEl?this.domEl.isSameNode(e)||(this.uninstall(),this.domEl=e,this.detector.listenTo(this.domEl,this.checkIfSizeChanged)):(this.domEl=e,this.detector.listenTo(this.domEl,this.checkIfSizeChanged)):this.uninstall()}},{key:"render",value:function(){var e=withSize.enableSSRBehaviour||withSize.noPlaceholders||c||"callback"===this.strategy,t=_extends({},this.state);return React__default.createElement(r,_extends({explicitRef:this.refCallback,size:"callback"===this.strategy?null:t,disablePlaceholder:e},this.props))}}]),o}(React__default.Component);return t.displayName="SizeMe("+getDisplayName(e)+")",t.propTypes={onSize:PropTypes.func},t.WrappedComponent=e,t}}withSize.enableSSRBehaviour=!1,withSize.noPlaceholders=!1;var SizeMe=function(e){function i(e){classCallCheck(this,i);var t=possibleConstructorReturn(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));_initialiseProps.call(t);e.children,e.render;var r=objectWithoutProperties(e,["children","render"]);return t.createComponent(r),t.state={size:{width:void 0,height:void 0}},t}return inherits(i,e),createClass(i,[{key:"componentDidUpdate",value:function(e){var t=this.props,r=(t.children,t.render,objectWithoutProperties(t,["children","render"])),i=(e.children,e.render,objectWithoutProperties(e,["children","render"]));isShallowEqual(r,i)||this.createComponent(r)}},{key:"render",value:function(){var e=this.SizeAware,t=this.props.children||this.props.render;return React__default.createElement(e,{onSize:this.onSize},t({size:this.state.size}))}}]),i}(React.Component);SizeMe.propTypes={children:PropTypes.func,render:PropTypes.func},SizeMe.defaultProps={children:void 0,render:void 0};var _initialiseProps=function(){var t=this;this.createComponent=function(e){t.SizeAware=withSize(e)(function(e){return e.children})},this.onSize=function(e){return t.setState({size:e})}};withSize.SizeMe=SizeMe,withSize.withSize=withSize,module.exports=withSize; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var createResizeDetector=_interopDefault(require("element-resize-detector")),React=require("react"),React__default=_interopDefault(React),PropTypes=_interopDefault(require("prop-types")),ReactDOM=_interopDefault(require("react-dom")),invariant=_interopDefault(require("invariant")),throttleDebounce=require("throttle-debounce"),isShallowEqual=_interopDefault(require("shallowequal")),instances={};function resizeDetector(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"scroll";return instances[e]||(instances[e]=createResizeDetector({strategy:e})),instances[e]}var classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function i(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}}(),_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},inherits=function(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)},objectWithoutProperties=function(e,t){var r={};for(var i in e)0<=t.indexOf(i)||Object.prototype.hasOwnProperty.call(e,i)&&(r[i]=e[i]);return r},possibleConstructorReturn=function(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},errMsg="react-sizeme: an error occurred whilst stopping to listen to node size changes",defaultConfig={monitorWidth:!0,monitorHeight:!1,monitorPosition:!1,refreshRate:16,refreshMode:"throttle",noPlaceholder:!1,resizeDetectorStrategy:"scroll"};function getDisplayName(e){return e.displayName||e.name||"Component"}var ReferenceWrapper=function(e){function t(){return classCallCheck(this,t),possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return inherits(t,e),createClass(t,[{key:"render",value:function(){return React.Children.only(this.props.children)}}]),t}(React.Component);function Placeholder(e){var t=e.className,r=e.style,i={};return t||r?(t&&(i.className=t),r&&(i.style=r)):i.style={width:"100%",height:"100%"},React__default.createElement("div",i)}ReferenceWrapper.displayName="SizeMeReferenceWrapper",ReferenceWrapper.propTypes={children:PropTypes.element.isRequired},Placeholder.displayName="SizeMePlaceholder",Placeholder.propTypes={className:PropTypes.string,style:PropTypes.object};var renderWrapper=function(h){function e(e){var t=e.explicitRef,r=e.className,i=e.style,n=e.size,o=e.disablePlaceholder,a=(e.onSize,objectWithoutProperties(e,["explicitRef","className","style","size","disablePlaceholder","onSize"])),s=(null==n||null==n.width&&null==n.height&&null==n.position)&&!o,l={className:r,style:i};null!=n&&(l.size=n);var c=s?React__default.createElement(Placeholder,{className:r,style:i}):React__default.createElement(h,_extends({},l,a));return React__default.createElement(ReferenceWrapper,{ref:t},c)}return e.displayName="SizeMeRenderer("+getDisplayName(h)+")",e.propTypes={explicitRef:PropTypes.func.isRequired,className:PropTypes.string,style:PropTypes.object,size:PropTypes.shape({width:PropTypes.number,height:PropTypes.number}),disablePlaceholder:PropTypes.bool,onSize:PropTypes.func},e};function withSize(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:defaultConfig,t=e.monitorWidth,h=void 0===t?defaultConfig.monitorWidth:t,r=e.monitorHeight,u=void 0===r?defaultConfig.monitorHeight:r,i=e.monitorPosition,p=void 0===i?defaultConfig.monitorPosition:i,n=e.refreshRate,a=void 0===n?defaultConfig.refreshRate:n,o=e.refreshMode,s=void 0===o?defaultConfig.refreshMode:o,l=e.noPlaceholder,c=void 0===l?defaultConfig.noPlaceholder:l,d=e.resizeDetectorStrategy,f=void 0===d?defaultConfig.resizeDetectorStrategy:d;invariant(h||u||p,'You have to monitor at least one of the width, height, or position when using "sizeMe"'),invariant(16<=a,"It is highly recommended that you don't put your refreshRate lower than 16 as this may cause layout thrashing."),invariant("throttle"===s||"debounce"===s,'The refreshMode should have a value of "throttle" or "debounce"');var y="throttle"===s?throttleDebounce.throttle:throttleDebounce.debounce;return function(e){var r=renderWrapper(e),t=function(e){function o(){var e,t,c;classCallCheck(this,o);for(var r=arguments.length,i=Array(r),n=0;n<r;n++)i[n]=arguments[n];return(t=c=possibleConstructorReturn(this,(e=o.__proto__||Object.getPrototypeOf(o)).call.apply(e,[this].concat(i)))).domEl=null,c.state={width:void 0,height:void 0,position:void 0},c.uninstall=function(){if(c.domEl){try{c.detector.uninstall(c.domEl)}catch(e){console.warn(errMsg)}c.domEl=null}},c.determineStrategy=function(e){e.onSize?(c.callbackState||(c.callbackState=_extends({},c.state)),c.strategy="callback"):c.strategy="render"},c.strategisedSetState=function(e){"callback"===c.strategy&&(c.callbackState=e,c.props.onSize(e)),c.setState(e)},c.strategisedGetState=function(){return"callback"===c.strategy?c.callbackState:c.state},c.refCallback=function(e){c.element=e},c.hasSizeChanged=function(e,t){var r=e,i=t,n=r.position||{},o=i.position||{};return h&&r.width!==i.width||u&&r.height!==i.height||p&&(n.top!==o.top||n.left!==o.left||n.bottom!==o.bottom||n.right!==o.right)},c.checkIfSizeChanged=y(a,function(e){var t=e.getBoundingClientRect(),r=t.width,i=t.height,n=t.right,o=t.left,a=t.top,s=t.bottom,l={width:h?r:null,height:u?i:null,position:p?{right:n,left:o,top:a,bottom:s}:null};c.hasSizeChanged(c.strategisedGetState(),l)&&c.strategisedSetState(l)}),possibleConstructorReturn(c,t)}return inherits(o,e),createClass(o,[{key:"componentDidMount",value:function(){this.detector=resizeDetector(f),this.determineStrategy(this.props),this.handleDOMNode()}},{key:"componentDidUpdate",value:function(){this.determineStrategy(this.props),this.handleDOMNode()}},{key:"componentWillUnmount",value:function(){this.hasSizeChanged=function(){},this.checkIfSizeChanged=function(){},this.uninstall()}},{key:"handleDOMNode",value:function(){var e=this.element&&ReactDOM.findDOMNode(this.element);e?this.domEl?this.domEl.isSameNode(e)||(this.uninstall(),this.domEl=e,this.detector.listenTo(this.domEl,this.checkIfSizeChanged)):(this.domEl=e,this.detector.listenTo(this.domEl,this.checkIfSizeChanged)):this.uninstall()}},{key:"render",value:function(){var e=withSize.enableSSRBehaviour||withSize.noPlaceholders||c||"callback"===this.strategy,t=_extends({},this.state);return React__default.createElement(r,_extends({explicitRef:this.refCallback,size:"callback"===this.strategy?null:t,disablePlaceholder:e},this.props))}}]),o}(React__default.Component);return t.displayName="SizeMe("+getDisplayName(e)+")",t.propTypes={onSize:PropTypes.func},t.WrappedComponent=e,t}}withSize.enableSSRBehaviour=!1,withSize.noPlaceholders=!1;var SizeMe=function(e){function i(e){classCallCheck(this,i);var t=possibleConstructorReturn(this,(i.__proto__||Object.getPrototypeOf(i)).call(this,e));_initialiseProps.call(t);e.children,e.render;var r=objectWithoutProperties(e,["children","render"]);return t.createComponent(r),t.state={size:{width:void 0,height:void 0}},t}return inherits(i,e),createClass(i,[{key:"componentDidUpdate",value:function(e){var t=this.props,r=(t.children,t.render,objectWithoutProperties(t,["children","render"])),i=(e.children,e.render,objectWithoutProperties(e,["children","render"]));isShallowEqual(r,i)||this.createComponent(r)}},{key:"render",value:function(){var e=this.SizeAware,t=this.props.children||this.props.render;return React__default.createElement(e,{onSize:this.onSize},t({size:this.state.size}))}}]),i}(React.Component);SizeMe.propTypes={children:PropTypes.func,render:PropTypes.func},SizeMe.defaultProps={children:void 0,render:void 0};var _initialiseProps=function(){var t=this;this.createComponent=function(e){t.SizeAware=withSize(e)(function(e){return e.children})},this.onSize=function(e){return t.setState({size:e})}};withSize.SizeMe=SizeMe,withSize.withSize=withSize,module.exports=withSize; | ||
//# sourceMappingURL=react-sizeme.min.js.map |
{ | ||
"name": "react-sizeme", | ||
"version": "2.6.6", | ||
"version": "2.6.7", | ||
"description": "Make your React Components aware of their dimensions and position.", | ||
@@ -37,5 +37,4 @@ "license": "MIT", | ||
"invariant": "^2.2.4", | ||
"lodash.debounce": "^4.0.8", | ||
"lodash.throttle": "^4.1.1", | ||
"shallowequal": "^1.1.0" | ||
"shallowequal": "^1.1.0", | ||
"throttle-debounce": "^2.1.0" | ||
}, | ||
@@ -42,0 +41,0 @@ "peerDependencies": { |
@@ -11,4 +11,3 @@ const babel = require('rollup-plugin-babel') | ||
'invariant', | ||
'lodash.debounce', | ||
'lodash.throttle', | ||
'throttle-debounce', | ||
'prop-types', | ||
@@ -15,0 +14,0 @@ 'react-dom', |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
7
84734
557
+ Addedthrottle-debounce@^2.1.0
+ Addedthrottle-debounce@2.3.0(transitive)
- Removedlodash.debounce@^4.0.8
- Removedlodash.throttle@^4.1.1
- Removedlodash.debounce@4.0.8(transitive)
- Removedlodash.throttle@4.1.1(transitive)