Completely updated React, fixed #11, (hopefully)
This commit is contained in:
170
goTorrentWebUI/node_modules/material-ui/utils/withWidth.js
generated
vendored
170
goTorrentWebUI/node_modules/material-ui/utils/withWidth.js
generated
vendored
@@ -37,6 +37,10 @@ var _react = require('react');
|
||||
|
||||
var _react2 = _interopRequireDefault(_react);
|
||||
|
||||
var _propTypes = require('prop-types');
|
||||
|
||||
var _propTypes2 = _interopRequireDefault(_propTypes);
|
||||
|
||||
var _reactEventListener = require('react-event-listener');
|
||||
|
||||
var _reactEventListener2 = _interopRequireDefault(_reactEventListener);
|
||||
@@ -49,6 +53,10 @@ var _wrapDisplayName = require('recompose/wrapDisplayName');
|
||||
|
||||
var _wrapDisplayName2 = _interopRequireDefault(_wrapDisplayName);
|
||||
|
||||
var _hoistNonReactStatics = require('hoist-non-react-statics');
|
||||
|
||||
var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
|
||||
|
||||
var _withTheme = require('../styles/withTheme');
|
||||
|
||||
var _withTheme2 = _interopRequireDefault(_withTheme);
|
||||
@@ -57,98 +65,56 @@ var _createBreakpoints = require('../styles/createBreakpoints');
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var babelPluginFlowReactPropTypes_proptype_HigherOrderComponent = require('react-flow-types').babelPluginFlowReactPropTypes_proptype_HigherOrderComponent || require('prop-types').any; // weak
|
||||
|
||||
// flow sanity check (DO NOT DELETE) https://flow.org/try/#0JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoUSWOGATzCTgG84BhXSAOyS5gBUGTAL5xsuAkXQwy5OQHp5cALSq16jZuVwdccorgB3YDAAW-U0hBMAEgHk25JAA9qWAK5cMwCFyMnzS2sAHgAFHDAAZwAuFmEAPgAKcl12Tl9eGFiOcAy+QUZg1jMrJFi7ACMAKyQMOFEAMjhwiCj4gBpyAEps9J58oTCIyPiWOR00ABsUSMi4AHUAi1K4FxheABM55GkAOhzuTKHWyPaWWiCyuEqauoSx1KIuDaQoRK6H1LgiGHcoP2CBzy8GYuzBZmAkV2YGGohK1gAvMwIVDIjAUOtdvCkKJ5PEKKlhAT6ilvkhfv8FktLuRhAolFpGUy1PolMYzMtrHAAKqRFAAcyQ5CmMzmAEFVs51s9tsQYPs+kdipdytVavBGiwULEuO4QBVXmcKjq9QaoPdmHS0L40XBOUgNkD+vAEf4OZdEmKuhQDPMmBtfPh4DwHbQIHAwKK4MA-AADbGx1YAN14Fwg7n5pjgsYAsnQnZlE0QAI7uYBEOYmXbkYL2x2KvhwFBIgCMogqSIATLj4vSVMyB6lWW7TIsNmY4PZHC43LQhHAAEJSADWkBjLoIzki+DgAB8CJEQDv9-gQBtjwRJvyL-hnJNZOR6IwqePTC0onBXcxSTGTMAUJMY5mAA-LES6oKuEDrp0OjGK+oGLiua58J0dJOK40AeF4MA+H47KjsAr7vJ8mCeN4virFwpgoF4SDHFEsRAW+wxJKSqQFnwvS5M6BR0cwcFmGBSFQShcBgrs76RAkMFwD0aTcZkvH0SMYxsXAIqzFSZhMZK0pbIgcoKgpfDKaM35fGSzyvMR5kWepNogr+OEAUxZwCaYoiuii0LDGpjzkn8AIcSC4neTCJyiO5SL4Ie+A9sShIJSSak-IFWkEa+xJEuMZIUn4vDUbRFBoQYA5leow7uHygrCtMmkLrpmyynswVFO5QkQchMBnNqcC6vqhrGn1pqvBapJPC8bwfLZEwOSw7meRckI+ScKUBZSwQbMASZwHipJ0lac1MQ6wWfiOTHvIkC7esOfpwAGXBBn1SChjA4aRppMbZu5iZICmfhmOmmbZnmwVFkgpblkglbyjWx31sZ8DNswbZwB2zDdrt+JAA
|
||||
|
||||
|
||||
/**
|
||||
* By default, returns true if screen width is the same or greater than the given breakpoint.
|
||||
*
|
||||
* @param screenWidth
|
||||
* @param breakpoint
|
||||
* @param inclusive - defaults to true
|
||||
*/
|
||||
var babelPluginFlowReactPropTypes_proptype_Breakpoint = require('../styles/createBreakpoints').babelPluginFlowReactPropTypes_proptype_Breakpoint || require('prop-types').any;
|
||||
|
||||
var isWidthUp = exports.isWidthUp = function isWidthUp(breakpoint, screenWidth) {
|
||||
// By default, returns true if screen width is the same or greater than the given breakpoint.
|
||||
var isWidthUp = exports.isWidthUp = function isWidthUp(breakpoint, width) {
|
||||
var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
|
||||
if (inclusive) {
|
||||
return _createBreakpoints.keys.indexOf(breakpoint) <= _createBreakpoints.keys.indexOf(screenWidth);
|
||||
return _createBreakpoints.keys.indexOf(breakpoint) <= _createBreakpoints.keys.indexOf(width);
|
||||
}
|
||||
return _createBreakpoints.keys.indexOf(breakpoint) < _createBreakpoints.keys.indexOf(screenWidth);
|
||||
return _createBreakpoints.keys.indexOf(breakpoint) < _createBreakpoints.keys.indexOf(width);
|
||||
};
|
||||
|
||||
/**
|
||||
* By default, returns true if screen width is the same or less than the given breakpoint.
|
||||
*
|
||||
* @param screenWidth
|
||||
* @param breakpoint
|
||||
* @param inclusive - defaults to true
|
||||
*/
|
||||
var isWidthDown = exports.isWidthDown = function isWidthDown(breakpoint, screenWidth) {
|
||||
// By default, returns true if screen width is the same or less than the given breakpoint.
|
||||
var isWidthDown = exports.isWidthDown = function isWidthDown(breakpoint, width) {
|
||||
var inclusive = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
|
||||
if (inclusive) {
|
||||
return _createBreakpoints.keys.indexOf(screenWidth) <= _createBreakpoints.keys.indexOf(breakpoint);
|
||||
return _createBreakpoints.keys.indexOf(width) <= _createBreakpoints.keys.indexOf(breakpoint);
|
||||
}
|
||||
return _createBreakpoints.keys.indexOf(screenWidth) < _createBreakpoints.keys.indexOf(breakpoint);
|
||||
return _createBreakpoints.keys.indexOf(width) < _createBreakpoints.keys.indexOf(breakpoint);
|
||||
};
|
||||
|
||||
// optional props introduced by this HOC
|
||||
var babelPluginFlowReactPropTypes_proptype_HOCProps = {
|
||||
/**
|
||||
* As `window.innerWidth` is unavailable on the server,
|
||||
* we default to rendering an empty componenent during the first mount.
|
||||
* In some situation you might want to use an heristic to approximate
|
||||
* the screen width of the client browser screen width.
|
||||
*
|
||||
* For instance, you could be using the user-agent or the client-hints.
|
||||
* http://caniuse.com/#search=client%20hint
|
||||
*/
|
||||
initialWidth: typeof babelPluginFlowReactPropTypes_proptype_Breakpoint === 'function' ? babelPluginFlowReactPropTypes_proptype_Breakpoint : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Breakpoint),
|
||||
|
||||
/**
|
||||
* Bypass the width calculation logic.
|
||||
*/
|
||||
width: typeof babelPluginFlowReactPropTypes_proptype_Breakpoint === 'function' ? babelPluginFlowReactPropTypes_proptype_Breakpoint : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Breakpoint)
|
||||
};
|
||||
var babelPluginFlowReactPropTypes_proptype_InjectedProps = {
|
||||
width: typeof babelPluginFlowReactPropTypes_proptype_Breakpoint === 'function' ? babelPluginFlowReactPropTypes_proptype_Breakpoint.isRequired ? babelPluginFlowReactPropTypes_proptype_Breakpoint.isRequired : babelPluginFlowReactPropTypes_proptype_Breakpoint : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Breakpoint).isRequired
|
||||
};
|
||||
|
||||
|
||||
var withWidth = function withWidth() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
return function (Component) {
|
||||
var _options$resizeInterv = options.resizeInterval,
|
||||
resizeInterval = _options$resizeInterv === undefined ? 166 : _options$resizeInterv;
|
||||
resizeInterval = _options$resizeInterv === undefined ? 166 : _options$resizeInterv,
|
||||
_options$withTheme = options.withTheme,
|
||||
withThemeOption = _options$withTheme === undefined ? false : _options$withTheme;
|
||||
|
||||
// `theme` is injected below by withTheme
|
||||
var WithWidth = function (_React$Component) {
|
||||
(0, _inherits3.default)(WithWidth, _React$Component);
|
||||
|
||||
var Width = function (_React$Component) {
|
||||
(0, _inherits3.default)(Width, _React$Component);
|
||||
|
||||
function Width() {
|
||||
function WithWidth() {
|
||||
var _ref;
|
||||
|
||||
var _temp, _this, _ret;
|
||||
|
||||
(0, _classCallCheck3.default)(this, Width);
|
||||
(0, _classCallCheck3.default)(this, WithWidth);
|
||||
|
||||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Width.__proto__ || (0, _getPrototypeOf2.default)(Width)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
||||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = WithWidth.__proto__ || (0, _getPrototypeOf2.default)(WithWidth)).call.apply(_ref, [this].concat(args))), _this), _this.state = {
|
||||
width: undefined
|
||||
}, _this.handleResize = (0, _debounce2.default)(function () {
|
||||
_this.updateWidth(window.innerWidth);
|
||||
}, resizeInterval), _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
|
||||
}
|
||||
|
||||
(0, _createClass3.default)(Width, [{
|
||||
(0, _createClass3.default)(WithWidth, [{
|
||||
key: 'componentDidMount',
|
||||
value: function componentDidMount() {
|
||||
this.updateWidth(window.innerWidth);
|
||||
@@ -161,37 +127,35 @@ var withWidth = function withWidth() {
|
||||
}, {
|
||||
key: 'updateWidth',
|
||||
value: function updateWidth(innerWidth) {
|
||||
if (this.props.theme) {
|
||||
var breakpoints = this.props.theme.breakpoints;
|
||||
var _width = null;
|
||||
var breakpoints = this.props.theme.breakpoints;
|
||||
var width = null;
|
||||
|
||||
/**
|
||||
* Start with the slowest value as low end devices often have a small screen.
|
||||
*
|
||||
* innerWidth |0 xs sm md lg xl
|
||||
* |-------|-------|-------|-------|-------|------>
|
||||
* width | xs | xs | sm | md | lg | xl
|
||||
*/
|
||||
var index = 1;
|
||||
while (_width === null && index < _createBreakpoints.keys.length) {
|
||||
var currentWidth = _createBreakpoints.keys[index];
|
||||
/**
|
||||
* Start with the slowest value as low end devices often have a small screen.
|
||||
*
|
||||
* innerWidth |xs sm md lg xl
|
||||
* |-------|-------|-------|-------|------>
|
||||
* width | xs | sm | md | lg | xl
|
||||
*/
|
||||
var index = 1;
|
||||
while (width === null && index < _createBreakpoints.keys.length) {
|
||||
var currentWidth = _createBreakpoints.keys[index];
|
||||
|
||||
// @media are inclusive, so reproduce the behavior here.
|
||||
if (innerWidth < breakpoints.values[currentWidth]) {
|
||||
_width = _createBreakpoints.keys[index - 1];
|
||||
break;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
// @media are inclusive, so reproduce the behavior here.
|
||||
if (innerWidth < breakpoints.values[currentWidth]) {
|
||||
width = _createBreakpoints.keys[index - 1];
|
||||
break;
|
||||
}
|
||||
|
||||
_width = _width || 'xl';
|
||||
index += 1;
|
||||
}
|
||||
|
||||
if (_width !== this.state.width) {
|
||||
this.setState({
|
||||
width: _width
|
||||
});
|
||||
}
|
||||
width = width || 'xl';
|
||||
|
||||
if (width !== this.state.width) {
|
||||
this.setState({
|
||||
width: width
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@@ -206,6 +170,11 @@ var withWidth = function withWidth() {
|
||||
var props = (0, _extends3.default)({
|
||||
width: width || this.state.width || initialWidth
|
||||
}, other);
|
||||
var more = {};
|
||||
|
||||
if (withThemeOption) {
|
||||
more.theme = theme;
|
||||
}
|
||||
|
||||
// When rendering the component on the server,
|
||||
// we have no idea about the client browser screen width.
|
||||
@@ -220,18 +189,41 @@ var withWidth = function withWidth() {
|
||||
return _react2.default.createElement(
|
||||
_reactEventListener2.default,
|
||||
{ target: 'window', onResize: this.handleResize },
|
||||
_react2.default.createElement(Component, props)
|
||||
_react2.default.createElement(Component, (0, _extends3.default)({}, more, props))
|
||||
);
|
||||
}
|
||||
}]);
|
||||
return Width;
|
||||
return WithWidth;
|
||||
}(_react2.default.Component);
|
||||
|
||||
WithWidth.propTypes = process.env.NODE_ENV !== "production" ? {
|
||||
/**
|
||||
* As `window.innerWidth` is unavailable on the server,
|
||||
* we default to rendering an empty componenent during the first mount.
|
||||
* In some situation you might want to use an heristic to approximate
|
||||
* the screen width of the client browser screen width.
|
||||
*
|
||||
* For instance, you could be using the user-agent or the client-hints.
|
||||
* http://caniuse.com/#search=client%20hint
|
||||
*/
|
||||
initialWidth: _propTypes2.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
theme: _propTypes2.default.object.isRequired,
|
||||
/**
|
||||
* Bypass the width calculation logic.
|
||||
*/
|
||||
width: _propTypes2.default.oneOf(['xs', 'sm', 'md', 'lg', 'xl'])
|
||||
} : {};
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
Width.displayName = (0, _wrapDisplayName2.default)(Component, 'withWidth');
|
||||
WithWidth.displayName = (0, _wrapDisplayName2.default)(Component, 'WithWidth');
|
||||
}
|
||||
|
||||
return (0, _withTheme2.default)()(Width);
|
||||
(0, _hoistNonReactStatics2.default)(WithWidth, Component);
|
||||
|
||||
return (0, _withTheme2.default)()(WithWidth);
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user