'use strict'; exports.__esModule = true; exports.version = undefined; exports.uncontrolledPropTypes = uncontrolledPropTypes; exports.getType = getType; exports.getValue = getValue; exports.getLinkName = getLinkName; exports.defaultKey = defaultKey; exports.chain = chain; exports.transform = transform; exports.each = each; exports.has = has; exports.isReactComponent = isReactComponent; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function readOnlyPropType(handler, name) { return function (props, propName) { if (props[propName] !== undefined) { if (!props[handler]) { return new Error('You have provided a `' + propName + '` prop to ' + '`' + name + '` without an `' + handler + '` handler. This will render a read-only field. ' + 'If the field should be mutable use `' + defaultKey(propName) + '`. Otherwise, set `' + handler + '`'); } } }; } function uncontrolledPropTypes(controlledValues, basePropTypes, displayName) { var propTypes = {}; if (process.env.NODE_ENV !== 'production' && basePropTypes) { transform(controlledValues, function (obj, handler, prop) { (0, _invariant2.default)(typeof handler === 'string' && handler.trim().length, 'Uncontrollable - [%s]: the prop `%s` needs a valid handler key name in order to make it uncontrollable', displayName, prop); obj[prop] = readOnlyPropType(handler, displayName); }, propTypes); } return propTypes; } var version = exports.version = _react2.default.version.split('.').map(parseFloat); function getType(component) { if (version[0] >= 15 || version[0] === 0 && version[1] >= 13) return component; return component.type; } function getValue(props, name) { var linkPropName = getLinkName(name); if (linkPropName && !isProp(props, name) && isProp(props, linkPropName)) return props[linkPropName].value; return props[name]; } function isProp(props, prop) { return props[prop] !== undefined; } function getLinkName(name) { return name === 'value' ? 'valueLink' : name === 'checked' ? 'checkedLink' : null; } function defaultKey(key) { return 'default' + key.charAt(0).toUpperCase() + key.substr(1); } function chain(thisArg, a, b) { return function chainedFunction() { for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } a && a.call.apply(a, [thisArg].concat(args)); b && b.call.apply(b, [thisArg].concat(args)); }; } function transform(obj, cb, seed) { each(obj, cb.bind(null, seed = seed || (Array.isArray(obj) ? [] : {}))); return seed; } function each(obj, cb, thisArg) { if (Array.isArray(obj)) return obj.forEach(cb, thisArg); for (var key in obj) { if (has(obj, key)) cb.call(thisArg, obj[key], key, obj); } } function has(o, k) { return o ? Object.prototype.hasOwnProperty.call(o, k) : false; } /** * Copyright (c) 2013-present, Facebook, Inc. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. An additional grant * of patent rights can be found in the PATENTS file in the same directory. */ function isReactComponent(component) { return !!(component && component.prototype && component.prototype.isReactComponent); }