UNPKG

su-react-mobile-imgview

Version:

A image album for mobile preview, built with reactjs. esay to use and less config.

1,138 lines (990 loc) 96 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ((function(modules) { // Check all modules for deduplicated modules for(var i in modules) { if(Object.prototype.hasOwnProperty.call(modules, i)) { switch(typeof modules[i]) { case "function": break; case "object": // Module can be created from a template modules[i] = (function(_m) { var args = _m.slice(1), fn = modules[_m[0]]; return function (a,b,c) { fn.apply(this, [a,b,c].concat(args)); }; }(modules[i])); break; default: // Module is a copy of another module modules[i] = modules[modules[i]]; break; } } } return modules; }([ /* 0 */ /***/ (function(module, exports, __webpack_require__) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.SingleImgView = undefined; 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 _react = __webpack_require__(1); var _react2 = _interopRequireDefault(_react); var _propTypes = __webpack_require__(2); var _propTypes2 = _interopRequireDefault(_propTypes); var _index = __webpack_require__(12); var _index2 = _interopRequireDefault(_index); var _alloyfinger = __webpack_require__(16); var _alloyfinger2 = _interopRequireDefault(_alloyfinger); var _transform = __webpack_require__(17); var _transform2 = _interopRequireDefault(_transform); var _components = __webpack_require__(18); var _reactSingleton = __webpack_require__(19); var _reactSingleton2 = _interopRequireDefault(_reactSingleton); __webpack_require__(20); 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; } /********************************************************************************************** * This component is designed for Tribe Project in QQ mobile as a Imageviewer * You can use it as a independent component in your App * * @ examples you can find examples in folder examples or README.md * * @ param(array) imagelist: The list of images to view * @ param(bool) disablePinch: Disable pinch function * @ param(bool) disableRotate: Disable rotate function * @ param(bool) disableDoubleTap: Disable double tap function * @ param(function) longTap: Events called after the long tap * @ param(function) close: the function to close the viewer * * Copyright by nemoliao( liaozksysu@gmail.com), nemo is a member of AlloyTeam in Tencent. * **********************************************************************************************/ var MARGIN = 30; var ImageView = function (_Component) { _inherits(ImageView, _Component); function ImageView(props) { _classCallCheck(this, ImageView); var _this = _possibleConstructorReturn(this, (ImageView.__proto__ || Object.getPrototypeOf(ImageView)).call(this)); _this.initScale = 1; _this.screenWidth = window.innerWidth || window.screen.availWidth; _this.screenHeight = window.innerHeight || window.screen.availHeight; _this.list = null; _this.ob = null; _this.focused = null; _this.arrLength = props.imagelist.length; _this.state = { current: props.current }; return _this; } _createClass(ImageView, [{ key: 'render', value: function render() { var _this2 = this; var _props = this.props, desc = _props.desc, disablePageNum = _props.disablePageNum, children = _props.children, gap = _props.gap; return _react2.default.createElement( 'div', { className: 'imageview' }, _react2.default.createElement( _alloyfinger2.default, { onSingleTap: this.onSingleTap.bind(this), onPressMove: this.onPressMove.bind(this), onSwipe: this.onSwipe.bind(this) }, _react2.default.createElement( 'ul', { ref: 'imagelist', className: 'imagelist' }, this.props.imagelist.map(function (item, i) { var labelsData = _this2.props.cleanData ? _this2.props.cleanData(item) : null; return _react2.default.createElement( 'li', { className: 'imagelist-item', style: { marginRight: gap + 'px' }, key: "img" + i }, _react2.default.createElement( _alloyfinger2.default, { onPressMove: _this2.onPicPressMove.bind(_this2), onMultipointStart: _this2.onMultipointStart.bind(_this2), onLongTap: _this2.onLongTap.bind(_this2), onPinch: _this2.onPinch.bind(_this2), onRotate: _this2.onRotate.bind(_this2), onMultipointEnd: _this2.onMultipointEnd.bind(_this2), onDoubleTap: _this2.onDoubleTap.bind(_this2) }, _react2.default.createElement(_components.CenterImage, { id: 'view' + i, className: 'imagelist-item-img', lazysrc: item.url, index: i, current: _this2.state.current }) ), _react2.default.createElement( 'div', { className: 'su-imagelist-item-tags-div', style: { position: 'absolute', zIndex: 9999999, top: 50, left: 10, backgroundColor: '#fff', padding: 5, borderRadius: 5, opacity: 0.6 } }, labelsData ? labelsData : null ) ); }) ) ), disablePageNum ? null : _react2.default.createElement( 'div', { className: 'page', ref: 'page' }, this.state.current + 1, ' / ', this.arrLength ), desc ? _react2.default.createElement('div', { dangerouslySetInnerHTML: { __html: desc } }) : null, children ); } }, { key: 'componentDidMount', value: function componentDidMount() { var current = this.state.current, _props2 = this.props, imagelist = _props2.imagelist, initCallback = _props2.initCallback; this.arrLength = imagelist.length; this.list = this.refs['imagelist']; (0, _transform2.default)(this.list); current && this.changeIndex(current, false); this.bindStyle(current); initCallback && initCallback(); } }, { key: 'onSingleTap', value: function onSingleTap() { this.props.close && this.props.close(); } }, { key: 'onPressMove', value: function onPressMove(evt) { var current = this.state.current; this.endAnimation(); if (!this.focused) { if (current === 0 && evt.deltaX > 0 || current === this.arrLength - 1 && evt.deltaX < 0) { this.list.translateX += evt.deltaX / 3; } else { this.list.translateX += evt.deltaX; } } evt.preventDefault(); } }, { key: 'onSwipe', value: function onSwipe(evt) { var direction = evt.direction; var current = this.state.current; if (this.focused) { return false; } switch (direction) { case 'Left': current < this.arrLength - 1 && ++current && this.bindStyle(current); break; case 'Right': current > 0 && current-- && this.bindStyle(current); break; } this.changeIndex(current); } }, { key: 'onPicPressMove', value: function onPicPressMove(evt) { var deltaX = evt.deltaX, deltaY = evt.deltaY, isLongPic = this.ob.getAttribute('long'), _ob = this.ob, scaleX = _ob.scaleX, width = _ob.width; if (this.ob.scaleX <= 1 || evt.touches.length > 1) { return; } if (this.ob && this.checkBoundary(deltaX, deltaY)) { !isLongPic && (this.ob.translateX += deltaX); this.ob.translateY += deltaY; if (isLongPic && scaleX * width === this.screenWidth) { this.focused = false; } else { this.focused = true; } } else { this.focused = false; } // console.log('translate ',this.ob.translateX, this.ob.translateY); } }, { key: 'onMultipointStart', value: function onMultipointStart() { this.initScale = this.ob.scaleX; } }, { key: 'onPinch', value: function onPinch(evt) { if (this.props.disablePinch || this.ob.getAttribute('long')) { return false; } this.ob.style.webkitTransition = 'cubic-bezier(.25,.01,.25,1)'; var _ob2 = this.ob, originX = _ob2.originX, originY = _ob2.originY, originX2 = evt.center.x - this.screenWidth / 2 - document.body.scrollLeft, originY2 = evt.center.y - this.screenHeight / 2 - document.body.scrollTop; this.ob.originX = originX2; this.ob.originY = originY2; this.ob.translateX = this.ob.translateX + (originX2 - originX) * this.ob.scaleX; this.ob.translateY = this.ob.translateY + (originY2 - originY) * this.ob.scaleY; this.ob.scaleX = this.ob.scaleY = this.initScale * evt.scale; } }, { key: 'onRotate', value: function onRotate(evt) { if (!this.props.enableRotate || this.ob.getAttribute('rate') >= 3.5) { return false; } this.ob.style.webkitTransition = 'cubic-bezier(.25,.01,.25,1)'; this.ob.rotateZ += evt.angle; } }, { key: 'onLongTap', value: function onLongTap() { this.props.longTap && this.props.longTap(); } }, { key: 'onMultipointEnd', value: function onMultipointEnd(evt) { // translate to normal this.changeIndex(this.state.current); if (!this.ob) { return; } this.ob.style.webkitTransition = '300ms ease'; var maxScale = this.props.maxScale, isLongPic = this.ob.getAttribute('long'); // scale to normal if (this.ob.scaleX < 1) { this.restore(false); } if (this.ob.scaleX > maxScale && !isLongPic) { this.setScale(maxScale); } // rotate to normal var rotation = this.ob.rotateZ % 360, rate = this.ob.getAttribute('rate'); if (rotation < 0) { rotation = 360 + rotation; } this.ob.rotateZ = rotation; if (rotation > 0 && rotation < 45) { this.ob.rotateZ = 0; } else if (rotation >= 315) { this.ob.rotateZ = 360; } else if (rotation >= 45 && rotation < 135) { this.ob.rotateZ = 90; this.setScale(rate); } else if (rotation >= 135 && rotation < 225) { this.ob.rotateZ = 180; } else if (rotation >= 225 && rotation < 315) { this.ob.rotateZ = 270; this.setScale(rate); } } }, { key: 'onDoubleTap', value: function onDoubleTap(evt) { if (this.props.disableDoubleTap) { return false; } var origin = evt.origin, originX = origin[0] - this.screenWidth / 2 - document.body.scrollLeft, originY = origin[1] - this.screenHeight / 2 - document.body.scrollTop, isLongPic = this.ob.getAttribute('long'); if (this.ob.scaleX === 1) { !isLongPic && (this.ob.translateX = this.ob.originX = originX); !isLongPic && (this.ob.translateY = this.ob.originY = originY); this.setScale(isLongPic ? this.screenWidth / this.ob.width : this.props.maxScale); } else { this.ob.translateX = this.ob.originX; this.ob.translateY = this.ob.originY; this.setScale(1); } // console.log('origin',this.ob.originX, this.ob.originY); } }, { key: 'bindStyle', value: function bindStyle(current) { var _this3 = this; this.setState({ current: current }, function () { _this3.ob && _this3.restore(); _this3.ob = document.getElementById('view' + current); if (_this3.ob && !_this3.ob.scaleX) { (0, _transform2.default)(_this3.ob); } // ease hide page number var page = _this3.refs.page; if (page) { page.classList.remove('hide'); setTimeout(function () { page.classList.add('hide'); }, 2000); } }); } }, { key: 'changeIndex', value: function changeIndex(current) { var ease = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; ease && (this.list.style.webkitTransition = '300ms ease'); this.list.translateX = -current * (this.screenWidth + this.props.gap); this.props.changeIndex && this.props.changeIndex(current); } }, { key: 'setScale', value: function setScale(size) { this.ob.style.webkitTransition = '300ms ease-in-out'; this.ob.scaleX = this.ob.scaleY = size; } }, { key: 'restore', value: function restore() { var rotate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; this.ob.translateX = this.ob.translateY = 0; !!rotate && (this.ob.rotateZ = 0); this.ob.scaleX = this.ob.scaleY = 1; this.ob.originX = this.ob.originY = 0; } }, { key: 'endAnimation', value: function endAnimation() { this.list.style.webkitTransition = '0'; this.ob && this.ob.style && (this.ob.style.webkitTransition = '0'); } }, { key: 'checkBoundary', value: function checkBoundary() { var deltaX = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var deltaY = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; // console.log(this.ob.width, this.ob.height); var _ob3 = this.ob, scaleX = _ob3.scaleX, translateX = _ob3.translateX, translateY = _ob3.translateY, originX = _ob3.originX, originY = _ob3.originY, width = _ob3.width, height = _ob3.height, rate = this.ob.getAttribute('rate'); if (scaleX !== 1 || scaleX !== rate) { // include long picture var rangeLeft = (scaleX - 1) * (width / 2 + originX) + originX, rangeRight = -(scaleX - 1) * (width / 2 - originX) + originX, rangeUp = (scaleX - 1) * (height / 2 + originY) + originY, rangeDown = -(scaleX - 1) * (height / 2 - originY) + originY; // console.log(rangeLeft, rangeRight, rangeUp, rangeDown); if (translateX + deltaX <= rangeLeft && translateX + deltaX >= rangeRight && translateY + deltaY <= rangeUp && translateY + deltaY >= rangeDown) { return true; } } return false; } }]); return ImageView; }(_react.Component); ImageView.defaultProps = { gap: MARGIN, current: 0, disablePageNum: false, desc: '', maxScale: 2 }; ImageView.propTypes = { gap: _propTypes2.default.number, maxScale: _propTypes2.default.number, current: _propTypes2.default.number, imagelist: _propTypes2.default.array.isRequired, disablePageNum: _propTypes2.default.bool, disablePinch: _propTypes2.default.bool, enableRotate: _propTypes2.default.bool, disableDoubleTap: _propTypes2.default.bool, longTap: _propTypes2.default.func, close: _propTypes2.default.func.isRequired, changeIndex: _propTypes2.default.func, initCallback: _propTypes2.default.func }; var SingleImgView = exports.SingleImgView = new _reactSingleton2.default(ImageView); exports.default = ImageView; /***/ }), /* 1 */ /***/ (function(module, exports) { module.exports = require("react"); /***/ }), /* 2 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ if (process.env.NODE_ENV !== 'production') { var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7; var isValidElement = function(object) { return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE; }; // By explicitly using `prop-types` you are opting into new development behavior. // http://fb.me/prop-types-in-prod var throwOnDirectAccess = true; module.exports = __webpack_require__(4)(isValidElement, throwOnDirectAccess); } else { // By explicitly using `prop-types` you are opting into new production behavior. // http://fb.me/prop-types-in-prod module.exports = __webpack_require__(11)(); } /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(3))) /***/ }), /* 3 */ /***/ (function(module, exports) { // shim for using process in browser var process = module.exports = {}; // cached from whatever global is present so that test runners that stub it // don't break things. But we need to wrap it in a try catch in case it is // wrapped in strict mode code which doesn't define any globals. It's inside a // function because try/catches deoptimize in certain engines. var cachedSetTimeout; var cachedClearTimeout; function defaultSetTimout() { throw new Error('setTimeout has not been defined'); } function defaultClearTimeout () { throw new Error('clearTimeout has not been defined'); } (function () { try { if (typeof setTimeout === 'function') { cachedSetTimeout = setTimeout; } else { cachedSetTimeout = defaultSetTimout; } } catch (e) { cachedSetTimeout = defaultSetTimout; } try { if (typeof clearTimeout === 'function') { cachedClearTimeout = clearTimeout; } else { cachedClearTimeout = defaultClearTimeout; } } catch (e) { cachedClearTimeout = defaultClearTimeout; } } ()) function runTimeout(fun) { if (cachedSetTimeout === setTimeout) { //normal enviroments in sane situations return setTimeout(fun, 0); } // if setTimeout wasn't available but was latter defined if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { cachedSetTimeout = setTimeout; return setTimeout(fun, 0); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedSetTimeout(fun, 0); } catch(e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedSetTimeout.call(null, fun, 0); } catch(e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error return cachedSetTimeout.call(this, fun, 0); } } } function runClearTimeout(marker) { if (cachedClearTimeout === clearTimeout) { //normal enviroments in sane situations return clearTimeout(marker); } // if clearTimeout wasn't available but was latter defined if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { cachedClearTimeout = clearTimeout; return clearTimeout(marker); } try { // when when somebody has screwed with setTimeout but no I.E. maddness return cachedClearTimeout(marker); } catch (e){ try { // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally return cachedClearTimeout.call(null, marker); } catch (e){ // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. // Some versions of I.E. have different rules for clearTimeout vs setTimeout return cachedClearTimeout.call(this, marker); } } } var queue = []; var draining = false; var currentQueue; var queueIndex = -1; function cleanUpNextTick() { if (!draining || !currentQueue) { return; } draining = false; if (currentQueue.length) { queue = currentQueue.concat(queue); } else { queueIndex = -1; } if (queue.length) { drainQueue(); } } function drainQueue() { if (draining) { return; } var timeout = runTimeout(cleanUpNextTick); draining = true; var len = queue.length; while(len) { currentQueue = queue; queue = []; while (++queueIndex < len) { if (currentQueue) { currentQueue[queueIndex].run(); } } queueIndex = -1; len = queue.length; } currentQueue = null; draining = false; runClearTimeout(timeout); } process.nextTick = function (fun) { var args = new Array(arguments.length - 1); if (arguments.length > 1) { for (var i = 1; i < arguments.length; i++) { args[i - 1] = arguments[i]; } } queue.push(new Item(fun, args)); if (queue.length === 1 && !draining) { runTimeout(drainQueue); } }; // v8 likes predictible objects function Item(fun, array) { this.fun = fun; this.array = array; } Item.prototype.run = function () { this.fun.apply(null, this.array); }; process.title = 'browser'; process.browser = true; process.env = {}; process.argv = []; process.version = ''; // empty string to avoid regexp issues process.versions = {}; function noop() {} process.on = noop; process.addListener = noop; process.once = noop; process.off = noop; process.removeListener = noop; process.removeAllListeners = noop; process.emit = noop; process.prependListener = noop; process.prependOnceListener = noop; process.listeners = function (name) { return [] } process.binding = function (name) { throw new Error('process.binding is not supported'); }; process.cwd = function () { return '/' }; process.chdir = function (dir) { throw new Error('process.chdir is not supported'); }; process.umask = function() { return 0; }; /***/ }), /* 4 */ /***/ (function(module, exports, __webpack_require__) { /* WEBPACK VAR INJECTION */(function(process) {/** * Copyright (c) 2013-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var emptyFunction = __webpack_require__(5); var invariant = __webpack_require__(6); var warning = __webpack_require__(7); var assign = __webpack_require__(8); var ReactPropTypesSecret = __webpack_require__(9); var checkPropTypes = __webpack_require__(10); module.exports = function(isValidElement, throwOnDirectAccess) { /* global Symbol */ var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. /** * Returns the iterator method function contained on the iterable object. * * Be sure to invoke the function with the iterable as context: * * var iteratorFn = getIteratorFn(myIterable); * if (iteratorFn) { * var iterator = iteratorFn.call(myIterable); * ... * } * * @param {?object} maybeIterable * @return {?function} */ function getIteratorFn(maybeIterable) { var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); if (typeof iteratorFn === 'function') { return iteratorFn; } } /** * Collection of methods that allow declaration and validation of props that are * supplied to React components. Example usage: * * var Props = require('ReactPropTypes'); * var MyArticle = React.createClass({ * propTypes: { * // An optional string prop named "description". * description: Props.string, * * // A required enum prop named "category". * category: Props.oneOf(['News','Photos']).isRequired, * * // A prop named "dialog" that requires an instance of Dialog. * dialog: Props.instanceOf(Dialog).isRequired * }, * render: function() { ... } * }); * * A more formal specification of how these methods are used: * * type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) * decl := ReactPropTypes.{type}(.isRequired)? * * Each and every declaration produces a function with the same signature. This * allows the creation of custom validation functions. For example: * * var MyLink = React.createClass({ * propTypes: { * // An optional string or URI prop named "href". * href: function(props, propName, componentName) { * var propValue = props[propName]; * if (propValue != null && typeof propValue !== 'string' && * !(propValue instanceof URI)) { * return new Error( * 'Expected a string or an URI for ' + propName + ' in ' + * componentName * ); * } * } * }, * render: function() {...} * }); * * @internal */ var ANONYMOUS = '<<anonymous>>'; // Important! // Keep this list in sync with production version in `./factoryWithThrowingShims.js`. var ReactPropTypes = { array: createPrimitiveTypeChecker('array'), bool: createPrimitiveTypeChecker('boolean'), func: createPrimitiveTypeChecker('function'), number: createPrimitiveTypeChecker('number'), object: createPrimitiveTypeChecker('object'), string: createPrimitiveTypeChecker('string'), symbol: createPrimitiveTypeChecker('symbol'), any: createAnyTypeChecker(), arrayOf: createArrayOfTypeChecker, element: createElementTypeChecker(), instanceOf: createInstanceTypeChecker, node: createNodeChecker(), objectOf: createObjectOfTypeChecker, oneOf: createEnumTypeChecker, oneOfType: createUnionTypeChecker, shape: createShapeTypeChecker, exact: createStrictShapeTypeChecker, }; /** * inlined Object.is polyfill to avoid requiring consumers ship their own * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ /*eslint-disable no-self-compare*/ function is(x, y) { // SameValue algorithm if (x === y) { // Steps 1-5, 7-10 // Steps 6.b-6.e: +0 != -0 return x !== 0 || 1 / x === 1 / y; } else { // Step 6.a: NaN == NaN return x !== x && y !== y; } } /*eslint-enable no-self-compare*/ /** * We use an Error-like object for backward compatibility as people may call * PropTypes directly and inspect their output. However, we don't use real * Errors anymore. We don't inspect their stack anyway, and creating them * is prohibitively expensive if they are created too often, such as what * happens in oneOfType() for any type before the one that matched. */ function PropTypeError(message) { this.message = message; this.stack = ''; } // Make `instanceof Error` still work for returned errors. PropTypeError.prototype = Error.prototype; function createChainableTypeChecker(validate) { if (process.env.NODE_ENV !== 'production') { var manualPropTypeCallCache = {}; var manualPropTypeWarningCount = 0; } function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { componentName = componentName || ANONYMOUS; propFullName = propFullName || propName; if (secret !== ReactPropTypesSecret) { if (throwOnDirectAccess) { // New behavior only for users of `prop-types` package invariant( false, '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 (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') { // Old behavior for people using React.PropTypes var cacheKey = componentName + ':' + propName; if ( !manualPropTypeCallCache[cacheKey] && // Avoid spamming the console because they are often not actionable except for lib authors manualPropTypeWarningCount < 3 ) { warning( false, '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.', propFullName, componentName ); manualPropTypeCallCache[cacheKey] = true; manualPropTypeWarningCount++; } } } if (props[propName] == null) { if (isRequired) { if (props[propName] === null) { return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); } return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); } return null; } else { return validate(props, propName, componentName, location, propFullName); } } var chainedCheckType = checkType.bind(null, false); chainedCheckType.isRequired = checkType.bind(null, true); return chainedCheckType; } function createPrimitiveTypeChecker(expectedType) { function validate(props, propName, componentName, location, propFullName, secret) { var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== expectedType) { // `propValue` being instance of, say, date/regexp, pass the 'object' // check, but we can offer a more precise error message here rather than // 'of type `object`'. var preciseType = getPreciseType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); } return null; } return createChainableTypeChecker(validate); } function createAnyTypeChecker() { return createChainableTypeChecker(emptyFunction.thatReturnsNull); } function createArrayOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); } var propValue = props[propName]; if (!Array.isArray(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); } for (var i = 0; i < propValue.length; i++) { var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret); if (error instanceof Error) { return error; } } return null; } return createChainableTypeChecker(validate); } function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; if (!isValidElement(propValue)) { var propType = getPropType(propValue); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); } return null; } return createChainableTypeChecker(validate); } function createInstanceTypeChecker(expectedClass) { function validate(props, propName, componentName, location, propFullName) { if (!(props[propName] instanceof expectedClass)) { var expectedClassName = expectedClass.name || ANONYMOUS; var actualClassName = getClassName(props[propName]); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); } return null; } return createChainableTypeChecker(validate); } function createEnumTypeChecker(expectedValues) { if (!Array.isArray(expectedValues)) { process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } function validate(props, propName, componentName, location, propFullName) { var propValue = props[propName]; for (var i = 0; i < expectedValues.length; i++) { if (is(propValue, expectedValues[i])) { return null; } } var valuesString = JSON.stringify(expectedValues); return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); } return createChainableTypeChecker(validate); } function createObjectOfTypeChecker(typeChecker) { function validate(props, propName, componentName, location, propFullName) { if (typeof typeChecker !== 'function') { return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); } var propValue = props[propName]; var propType = getPropType(propValue); if (propType !== 'object') { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); } for (var key in propValue) { if (propValue.hasOwnProperty(key)) { var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret); if (error instanceof Error) { return error; } } } return null; } return createChainableTypeChecker(validate); } function createUnionTypeChecker(arrayOfTypeCheckers) { if (!Array.isArray(arrayOfTypeCheckers)) { process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; return emptyFunction.thatReturnsNull; } for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (typeof checker !== 'function') { warning( false, 'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 'received %s at index %s.', getPostfixForTypeWarning(checker), i ); return emptyFunction.thatReturnsNull; } } function validate(props, propName, componentName, location, propFullName) { for (var i = 0; i < arrayOfTypeCheckers.length; i++) { var checker = arrayOfTypeCheckers[i]; if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) { return null; } } return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); } return createChainableTypeChecker(validate); } function createNodeChecker() { function validate(props, propName, componentName, location, propFullName) { if (!isNode(props[propName])) { return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); } return null; } return createChainableTypeChecker(validate);