react-textarea-autosize
Advanced tools
Comparing version 6.1.0 to 7.0.0
@@ -34,15 +34,2 @@ 'use strict'; | ||
var _sPO = Object.setPrototypeOf || function _sPO(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
var _construct = typeof Reflect === "object" && Reflect.construct || function _construct(Parent, args, Class) { | ||
var Constructor, | ||
a = [null]; | ||
a.push.apply(a, args); | ||
Constructor = Parent.bind.apply(Parent, a); | ||
return _sPO(new Constructor(), Class.prototype); | ||
}; | ||
function _objectWithoutProperties(source, excluded) { | ||
@@ -74,5 +61,13 @@ if (source == null) return {}; | ||
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
var isIE = isBrowser ? !!document.documentElement.currentStyle : false; | ||
return self; | ||
} | ||
var _isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
var isIE = _isBrowser ? !!document.documentElement.currentStyle : false; | ||
var HIDDEN_TEXTAREA_STYLE = { | ||
@@ -91,3 +86,3 @@ 'min-height': '0', | ||
var computedStyleCache = {}; | ||
var hiddenTextarea = isBrowser && document.createElement('textarea'); | ||
var hiddenTextarea = (_isBrowser) && document.createElement('textarea'); | ||
@@ -100,3 +95,3 @@ var forceHiddenStyles = function forceHiddenStyles(node) { | ||
if (isBrowser) { | ||
if (_isBrowser) { | ||
forceHiddenStyles(hiddenTextarea); | ||
@@ -156,24 +151,25 @@ } | ||
hiddenTextarea.value = 'x'; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; // Stores the value's rows count rendered in `hiddenTextarea`, | ||
// regardless if `maxRows` or `minRows` props are passed | ||
if (minRows !== null || maxRows !== null) { | ||
if (minRows !== null) { | ||
minHeight = singleRowHeight * minRows; | ||
var valueRowCount = Math.floor(height / singleRowHeight); | ||
if (boxSizing === 'border-box') { | ||
minHeight = minHeight + paddingSize + borderSize; | ||
} | ||
if (minRows !== null) { | ||
minHeight = singleRowHeight * minRows; | ||
height = Math.max(minHeight, height); | ||
if (boxSizing === 'border-box') { | ||
minHeight = minHeight + paddingSize + borderSize; | ||
} | ||
if (maxRows !== null) { | ||
maxHeight = singleRowHeight * maxRows; | ||
height = Math.max(minHeight, height); | ||
} | ||
if (boxSizing === 'border-box') { | ||
maxHeight = maxHeight + paddingSize + borderSize; | ||
} | ||
if (maxRows !== null) { | ||
maxHeight = singleRowHeight * maxRows; | ||
height = Math.min(maxHeight, height); | ||
if (boxSizing === 'border-box') { | ||
maxHeight = maxHeight + paddingSize + borderSize; | ||
} | ||
height = Math.min(maxHeight, height); | ||
} | ||
@@ -186,3 +182,4 @@ | ||
maxHeight: maxHeight, | ||
rowCount: rowCount | ||
rowCount: rowCount, | ||
valueRowCount: valueRowCount | ||
}; | ||
@@ -239,20 +236,5 @@ } | ||
var purgeCache = function purgeCache(uid) { | ||
return delete computedStyleCache[uid]; | ||
delete computedStyleCache[uid]; | ||
}; | ||
function autoInc(seed) { | ||
if (seed === void 0) { | ||
seed = 0; | ||
} | ||
return function () { | ||
return ++seed; | ||
}; | ||
} | ||
var uid = autoInc(); | ||
/** | ||
* <TextareaAutosize /> | ||
*/ | ||
var noop = function noop() {}; // IE11 has a problem with eval source maps, can be reproduced with: | ||
@@ -263,6 +245,8 @@ // eval('"use strict"; var onNextFrame = window.cancelAnimationFrame; onNextFrame(4);') | ||
var _ref = isBrowser && window.requestAnimationFrame ? process.env.NODE_ENV !== 'development' ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [window.requestAnimationFrame.bind(window), window.cancelAnimationFrame.bind(window)] : [setTimeout, clearTimeout]; | ||
var onNextFrame = _ref[0]; | ||
var clearNextFrameAction = _ref[1]; | ||
var _ref = (_isBrowser) && window.requestAnimationFrame ? process.env.NODE_ENV !== 'development' ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [window.requestAnimationFrame.bind(window), window.cancelAnimationFrame.bind(window)] : [setTimeout, clearTimeout], | ||
onNextFrame = _ref[0], | ||
clearNextFrameAction = _ref[1]; | ||
var uid = 0; | ||
var TextareaAutosize = | ||
@@ -277,6 +261,5 @@ /*#__PURE__*/ | ||
_this = _React$Component.call(this, props) || this; | ||
_this._resizeLock = false; | ||
_this._onRootDOMNode = function (node) { | ||
_this._rootDOMNode = node; | ||
_this._onRef = function (node) { | ||
_this._ref = node; | ||
@@ -291,3 +274,3 @@ _this.props.inputRef(node); | ||
_this.props.onChange(event); | ||
_this.props.onChange(event, _assertThisInitialized(_assertThisInitialized(_this))); | ||
}; | ||
@@ -300,3 +283,3 @@ | ||
if (typeof _this._rootDOMNode === 'undefined') { | ||
if (!_this._ref) { | ||
callback(); | ||
@@ -306,3 +289,3 @@ return; | ||
var nodeHeight = calculateNodeHeight(_this._rootDOMNode, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows); | ||
var nodeHeight = calculateNodeHeight(_this._ref, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows); | ||
@@ -317,4 +300,6 @@ if (nodeHeight === null) { | ||
maxHeight = nodeHeight.maxHeight, | ||
rowCount = nodeHeight.rowCount; | ||
rowCount = nodeHeight.rowCount, | ||
valueRowCount = nodeHeight.valueRowCount; | ||
_this.rowCount = rowCount; | ||
_this.valueRowCount = valueRowCount; | ||
@@ -339,4 +324,5 @@ if (_this.state.height !== height || _this.state.minHeight !== minHeight || _this.state.maxHeight !== maxHeight) { | ||
}; | ||
_this._uid = uid(); | ||
_this._controlled = typeof props.value === 'string'; | ||
_this._uid = uid++; | ||
_this._controlled = props.value !== undefined; | ||
_this._resizeLock = false; | ||
return _this; | ||
@@ -348,9 +334,9 @@ } | ||
_proto.render = function render() { | ||
var _props = this.props, | ||
_inputRef = _props.inputRef, | ||
_maxRows = _props.maxRows, | ||
_minRows = _props.minRows, | ||
_onHeightChange = _props.onHeightChange, | ||
_useCacheForDOMMeasurements = _props.useCacheForDOMMeasurements, | ||
props = _objectWithoutProperties(_props, ["inputRef", "maxRows", "minRows", "onHeightChange", "useCacheForDOMMeasurements"]); | ||
var _this$props = this.props, | ||
_inputRef = _this$props.inputRef, | ||
_maxRows = _this$props.maxRows, | ||
_minRows = _this$props.minRows, | ||
_onHeightChange = _this$props.onHeightChange, | ||
_useCacheForDOMMeasurements = _this$props.useCacheForDOMMeasurements, | ||
props = _objectWithoutProperties(_this$props, ["inputRef", "maxRows", "minRows", "onHeightChange", "useCacheForDOMMeasurements"]); | ||
@@ -368,3 +354,3 @@ props.style = _extends({}, props.style, { | ||
onChange: this._onChange, | ||
ref: this._onRootDOMNode | ||
ref: this._onRef | ||
})); | ||
@@ -389,3 +375,3 @@ }; | ||
_this2._resizeComponent(function () { | ||
return _this2._resizeLock = false; | ||
_this2._resizeLock = false; | ||
}); | ||
@@ -398,10 +384,5 @@ }; | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var _this3 = this; | ||
if (prevProps !== this.props) { | ||
this._clearNextFrame(); | ||
this._onNextFrameActionId = onNextFrame(function () { | ||
return _this3._resizeComponent(); | ||
}); | ||
clearNextFrameAction(this._rafId); | ||
this._rafId = onNextFrame(this._resizeComponent); | ||
} | ||
@@ -415,4 +396,3 @@ | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._clearNextFrame(); | ||
clearNextFrameAction(this._rafId); | ||
window.removeEventListener('resize', this._resizeListener); | ||
@@ -422,10 +402,12 @@ purgeCache(this._uid); | ||
_proto._clearNextFrame = function _clearNextFrame() { | ||
clearNextFrameAction(this._onNextFrameActionId); | ||
}; | ||
return TextareaAutosize; | ||
}(React.Component); | ||
TextareaAutosize.propTypes = { | ||
TextareaAutosize.defaultProps = { | ||
inputRef: noop, | ||
onChange: noop, | ||
onHeightChange: noop, | ||
useCacheForDOMMeasurements: false | ||
}; | ||
process.env.NODE_ENV !== "production" ? TextareaAutosize.propTypes = { | ||
inputRef: PropTypes.func, | ||
@@ -438,10 +420,4 @@ maxRows: PropTypes.number, | ||
value: PropTypes.string | ||
}; | ||
TextareaAutosize.defaultProps = { | ||
inputRef: noop, | ||
onChange: noop, | ||
onHeightChange: noop, | ||
useCacheForDOMMeasurements: false | ||
}; | ||
} : void 0; | ||
exports['default'] = TextareaAutosize; | ||
exports.default = TextareaAutosize; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(factory((global.TextareaAutosize = {}),global.React)); | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(factory((global.TextareaAutosize = {}),global.React)); | ||
}(this, (function (exports,React) { 'use strict'; | ||
React = React && React.hasOwnProperty('default') ? React['default'] : React; | ||
React = React && React.hasOwnProperty('default') ? React['default'] : React; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
return target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
return _extends.apply(this, arguments); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
var _sPO = Object.setPrototypeOf || function _sPO(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
var _construct = typeof Reflect === "object" && Reflect.construct || function _construct(Parent, args, Class) { | ||
var Constructor, | ||
a = [null]; | ||
a.push.apply(a, args); | ||
Constructor = Parent.bind.apply(Parent, a); | ||
return _sPO(new Constructor(), Class.prototype); | ||
}; | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
/** | ||
* 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. | ||
* | ||
* | ||
*/ | ||
return target; | ||
} | ||
function makeEmptyFunction(arg) { | ||
return function () { | ||
return arg; | ||
}; | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
/** | ||
* This function accepts and discards inputs; it has no side effects. This is | ||
* primarily useful idiomatically for overridable function endpoints which | ||
* always need to be callable, since JS lacks a null-call idiom ala Cocoa. | ||
*/ | ||
var emptyFunction = function emptyFunction() {}; | ||
return self; | ||
} | ||
emptyFunction.thatReturns = makeEmptyFunction; | ||
emptyFunction.thatReturnsFalse = makeEmptyFunction(false); | ||
emptyFunction.thatReturnsTrue = makeEmptyFunction(true); | ||
emptyFunction.thatReturnsNull = makeEmptyFunction(null); | ||
emptyFunction.thatReturnsThis = function () { | ||
return this; | ||
}; | ||
emptyFunction.thatReturnsArgument = function (arg) { | ||
return arg; | ||
}; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var emptyFunction_1 = emptyFunction; | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
/** | ||
* 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. | ||
* | ||
*/ | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
/** | ||
* Use invariant() to assert state which your program assumes to be true. | ||
* | ||
* Provide sprintf-style format (only %s is supported) and arguments | ||
* to provide information about what broke and what you were | ||
* expecting. | ||
* | ||
* The invariant message will be stripped in production, but the invariant | ||
* will remain to ensure logic does not differ in production. | ||
*/ | ||
return Object(val); | ||
} | ||
var validateFormat = function validateFormat(format) {}; | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
{ | ||
validateFormat = function validateFormat(format) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
}; | ||
} | ||
// Detect buggy property enumeration order in older V8 versions. | ||
function invariant(condition, format, a, b, c, d, e, f) { | ||
validateFormat(format); | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
test1[5] = 'de'; | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} | ||
if (!condition) { | ||
var error; | ||
if (format === undefined) { | ||
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); | ||
} else { | ||
var args = [a, b, c, d, e, f]; | ||
var argIndex = 0; | ||
error = new Error(format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
})); | ||
error.name = 'Invariant Violation'; | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test2 = {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
if (Object.keys(Object.assign({}, test3)).join('') !== | ||
'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
} | ||
var invariant_1 = invariant; | ||
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
/** | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
var warning = emptyFunction_1; | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
{ | ||
var printWarning = function printWarning(format) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
return to; | ||
}; | ||
warning = function warning(condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
var objectAssign$1 = /*#__PURE__*/Object.freeze({ | ||
default: objectAssign, | ||
__moduleExports: objectAssign | ||
}); | ||
if (format.indexOf('Failed Composite propType: ') === 0) { | ||
return; // Ignore CompositeComponent proptype check. | ||
} | ||
/** | ||
* 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 (!condition) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; | ||
printWarning.apply(undefined, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
var ReactPropTypesSecret_1 = ReactPropTypesSecret; | ||
var warning_1 = warning; | ||
var ReactPropTypesSecret$1 = /*#__PURE__*/Object.freeze({ | ||
default: ReactPropTypesSecret_1, | ||
__moduleExports: ReactPropTypesSecret_1 | ||
}); | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
var require$$0 = ( ReactPropTypesSecret$1 && ReactPropTypesSecret_1 ) || ReactPropTypesSecret$1; | ||
/* eslint-disable no-unused-vars */ | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
var printWarning = function() {}; | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
{ | ||
var ReactPropTypesSecret$2 = require$$0; | ||
var loggedTypeFailures = {}; | ||
return Object(val); | ||
} | ||
printWarning = function(text) { | ||
var message = 'Warning: ' + text; | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
{ | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
if (typeof typeSpecs[typeSpecName] !== 'function') { | ||
var err = Error( | ||
(componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + | ||
'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' | ||
); | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$2); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
if (error && !(error instanceof Error)) { | ||
printWarning( | ||
(componentName || 'React class') + ': type specification of ' + | ||
location + ' `' + typeSpecName + '` is invalid; the type checker ' + | ||
'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + | ||
'You may have forgotten to pass an argument to the type checker ' + | ||
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + | ||
'shape all require an argument).' | ||
); | ||
// Detect buggy property enumeration order in older V8 versions. | ||
} | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
test1[5] = 'de'; | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} | ||
var stack = getStack ? getStack() : ''; | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test2 = {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} | ||
printWarning( | ||
'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '') | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
if (Object.keys(Object.assign({}, test3)).join('') !== | ||
'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
var checkPropTypes_1 = checkPropTypes; | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
var checkPropTypes$1 = /*#__PURE__*/Object.freeze({ | ||
default: checkPropTypes_1, | ||
__moduleExports: checkPropTypes_1 | ||
}); | ||
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
var assign = ( objectAssign$1 && objectAssign ) || objectAssign$1; | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
var checkPropTypes$2 = ( checkPropTypes$1 && checkPropTypes_1 ) || checkPropTypes$1; | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
var printWarning$1 = function() {}; | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
return to; | ||
}; | ||
/** | ||
* 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. | ||
*/ | ||
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; | ||
var ReactPropTypesSecret_1 = ReactPropTypesSecret; | ||
{ | ||
var invariant$1 = invariant_1; | ||
var warning$1 = warning_1; | ||
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; | ||
var loggedTypeFailures = {}; | ||
} | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
{ | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
invariant$1(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
warning$1(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
var stack = getStack ? getStack() : ''; | ||
warning$1(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); | ||
} | ||
printWarning$1 = function(text) { | ||
var message = 'Warning: ' + text; | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
} | ||
} | ||
var checkPropTypes_1 = checkPropTypes; | ||
function emptyFunctionThatReturnsNull() { | ||
return null; | ||
} | ||
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) { | ||
/* global Symbol */ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
var factoryWithTypeCheckers = 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; | ||
/** | ||
* 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 | ||
*/ | ||
/** | ||
* 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>>'; | ||
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'), | ||
// 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, | ||
}; | ||
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; | ||
/** | ||
* 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*/ | ||
/*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) { | ||
{ | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
/** | ||
* 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 = ''; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
// Make `instanceof Error` still work for returned errors. | ||
PropTypeError.prototype = Error.prototype; | ||
if (secret !== ReactPropTypesSecret_1) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
invariant_1( | ||
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 ("development" !== '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_1( | ||
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 | ||
function createChainableTypeChecker(validate) { | ||
{ | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
if (secret !== require$$0) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
var err = new Error( | ||
'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' | ||
); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
err.name = 'Invariant Violation'; | ||
throw err; | ||
} else if (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 | ||
) { | ||
printWarning$1( | ||
'You are manually calling a React.PropTypes validation ' + | ||
'function for the `' + propFullName + '` prop on `' + componentName + '`. 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.' | ||
); | ||
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`.')); | ||
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 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); | ||
} | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
return chainedCheckType; | ||
} | ||
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); | ||
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 new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
} | ||
return null; | ||
} | ||
return null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunction_1.thatReturnsNull); | ||
} | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunctionThatReturnsNull); | ||
} | ||
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_1); | ||
if (error instanceof Error) { | ||
return error; | ||
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 + ']', require$$0); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
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.')); | ||
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 null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
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 + '`.')); | ||
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 null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
warning_1(false, 'Invalid argument supplied to oneOf, expected an instance of array.'); | ||
return emptyFunction_1.thatReturnsNull; | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
printWarning$1('Invalid argument supplied to oneOf, expected an instance of array.'); | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
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; | ||
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 + '.')); | ||
} | ||
var valuesString = JSON.stringify(expectedValues); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
return createChainableTypeChecker(validate); | ||
} | ||
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_1); | ||
if (error instanceof Error) { | ||
return error; | ||
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, require$$0); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
warning_1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.'); | ||
return emptyFunction_1.thatReturnsNull; | ||
} | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (typeof checker !== 'function') { | ||
warning_1( | ||
false, | ||
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + | ||
'received %s at index %s.', | ||
getPostfixForTypeWarning(checker), | ||
i | ||
); | ||
return emptyFunction_1.thatReturnsNull; | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.'); | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
} | ||
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_1) == null) { | ||
return null; | ||
if (typeof checker !== 'function') { | ||
printWarning$1( | ||
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + | ||
'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.' | ||
); | ||
return emptyFunctionThatReturnsNull; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
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, require$$0) == null) { | ||
return null; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
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.')); | ||
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 null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, require$$0); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
// We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = objectAssign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError( | ||
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + | ||
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') + | ||
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') | ||
); | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
// We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = assign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError( | ||
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + | ||
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') + | ||
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') | ||
); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, require$$0); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return null; | ||
return createChainableTypeChecker(validate); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
} | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
return true; | ||
} | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
} | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
} | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
return false; | ||
} | ||
return false; | ||
} | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
} | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
} | ||
} | ||
return propType; | ||
} | ||
return propType; | ||
} | ||
// Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
// Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
} | ||
} | ||
} | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
ReactPropTypes.checkPropTypes = checkPropTypes_1; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
ReactPropTypes.checkPropTypes = checkPropTypes$2; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
return ReactPropTypes; | ||
}; | ||
var propTypes = createCommonjsModule(function (module) { | ||
/** | ||
* 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. | ||
*/ | ||
var factoryWithTypeCheckers$1 = /*#__PURE__*/Object.freeze({ | ||
default: factoryWithTypeCheckers, | ||
__moduleExports: factoryWithTypeCheckers | ||
}); | ||
{ | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
var require$$0$1 = ( factoryWithTypeCheckers$1 && factoryWithTypeCheckers ) || factoryWithTypeCheckers$1; | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
var propTypes = createCommonjsModule(function (module) { | ||
/** | ||
* 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. | ||
*/ | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess); | ||
} | ||
}); | ||
{ | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
var isIE = isBrowser ? !!document.documentElement.currentStyle : false; | ||
var HIDDEN_TEXTAREA_STYLE = { | ||
'min-height': '0', | ||
'max-height': 'none', | ||
height: '0', | ||
visibility: 'hidden', | ||
overflow: 'hidden', | ||
position: 'absolute', | ||
'z-index': '-1000', | ||
top: '0', | ||
right: '0' | ||
}; | ||
var SIZING_STYLE = ['letter-spacing', 'line-height', 'font-family', 'font-weight', 'font-size', 'font-style', 'tab-size', 'text-rendering', 'text-transform', 'width', 'text-indent', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width', 'box-sizing']; | ||
var computedStyleCache = {}; | ||
var hiddenTextarea = isBrowser && document.createElement('textarea'); | ||
var forceHiddenStyles = function forceHiddenStyles(node) { | ||
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) { | ||
node.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important'); | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = require$$0$1(isValidElement, throwOnDirectAccess); | ||
} | ||
}); | ||
}; | ||
if (isBrowser) { | ||
forceHiddenStyles(hiddenTextarea); | ||
} | ||
var isIE = !!document.documentElement.currentStyle; | ||
var HIDDEN_TEXTAREA_STYLE = { | ||
'min-height': '0', | ||
'max-height': 'none', | ||
height: '0', | ||
visibility: 'hidden', | ||
overflow: 'hidden', | ||
position: 'absolute', | ||
'z-index': '-1000', | ||
top: '0', | ||
right: '0' | ||
}; | ||
var SIZING_STYLE = ['letter-spacing', 'line-height', 'font-family', 'font-weight', 'font-size', 'font-style', 'tab-size', 'text-rendering', 'text-transform', 'width', 'text-indent', 'padding-top', 'padding-right', 'padding-bottom', 'padding-left', 'border-top-width', 'border-right-width', 'border-bottom-width', 'border-left-width', 'box-sizing']; | ||
var computedStyleCache = {}; | ||
var hiddenTextarea = document.createElement('textarea'); | ||
function calculateNodeHeight(uiTextNode, uid, useCache, minRows, maxRows) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
var forceHiddenStyles = function forceHiddenStyles(node) { | ||
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) { | ||
node.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important'); | ||
}); | ||
}; | ||
if (minRows === void 0) { | ||
minRows = null; | ||
{ | ||
forceHiddenStyles(hiddenTextarea); | ||
} | ||
if (maxRows === void 0) { | ||
maxRows = null; | ||
} | ||
function calculateNodeHeight(uiTextNode, uid, useCache, minRows, maxRows) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
if (hiddenTextarea.parentNode === null) { | ||
document.body.appendChild(hiddenTextarea); | ||
} // Copy all CSS properties that have an impact on the height of the content in | ||
// the textbox | ||
if (minRows === void 0) { | ||
minRows = null; | ||
} | ||
if (maxRows === void 0) { | ||
maxRows = null; | ||
} | ||
var nodeStyling = calculateNodeStyling(uiTextNode, uid, useCache); | ||
if (hiddenTextarea.parentNode === null) { | ||
document.body.appendChild(hiddenTextarea); | ||
} // Copy all CSS properties that have an impact on the height of the content in | ||
// the textbox | ||
if (nodeStyling === null) { | ||
return null; | ||
} | ||
var paddingSize = nodeStyling.paddingSize, | ||
borderSize = nodeStyling.borderSize, | ||
boxSizing = nodeStyling.boxSizing, | ||
sizingStyle = nodeStyling.sizingStyle; // Need to have the overflow attribute to hide the scrollbar otherwise | ||
// text-lines will not calculated properly as the shadow will technically be | ||
// narrower for content | ||
var nodeStyling = calculateNodeStyling(uiTextNode, uid, useCache); | ||
Object.keys(sizingStyle).forEach(function (key) { | ||
hiddenTextarea.style[key] = sizingStyle[key]; | ||
}); | ||
forceHiddenStyles(hiddenTextarea); | ||
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || 'x'; | ||
var minHeight = -Infinity; | ||
var maxHeight = Infinity; | ||
var height = hiddenTextarea.scrollHeight; | ||
if (nodeStyling === null) { | ||
return null; | ||
} | ||
if (boxSizing === 'border-box') { | ||
// border-box: add border, since height = content + padding + border | ||
height = height + borderSize; | ||
} else if (boxSizing === 'content-box') { | ||
// remove padding, since height = content | ||
height = height - paddingSize; | ||
} // measure height of a textarea with a single row | ||
var paddingSize = nodeStyling.paddingSize, | ||
borderSize = nodeStyling.borderSize, | ||
boxSizing = nodeStyling.boxSizing, | ||
sizingStyle = nodeStyling.sizingStyle; // Need to have the overflow attribute to hide the scrollbar otherwise | ||
// text-lines will not calculated properly as the shadow will technically be | ||
// narrower for content | ||
Object.keys(sizingStyle).forEach(function (key) { | ||
hiddenTextarea.style[key] = sizingStyle[key]; | ||
}); | ||
forceHiddenStyles(hiddenTextarea); | ||
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || 'x'; | ||
var minHeight = -Infinity; | ||
var maxHeight = Infinity; | ||
var height = hiddenTextarea.scrollHeight; | ||
hiddenTextarea.value = 'x'; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; | ||
if (boxSizing === 'border-box') { | ||
// border-box: add border, since height = content + padding + border | ||
height = height + borderSize; | ||
} else if (boxSizing === 'content-box') { | ||
// remove padding, since height = content | ||
height = height - paddingSize; | ||
} // measure height of a textarea with a single row | ||
if (minRows !== null || maxRows !== null) { | ||
hiddenTextarea.value = 'x'; | ||
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; // Stores the value's rows count rendered in `hiddenTextarea`, | ||
// regardless if `maxRows` or `minRows` props are passed | ||
var valueRowCount = Math.floor(height / singleRowHeight); | ||
if (minRows !== null) { | ||
@@ -1020,258 +952,232 @@ minHeight = singleRowHeight * minRows; | ||
} | ||
var rowCount = Math.floor(height / singleRowHeight); | ||
return { | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight, | ||
rowCount: rowCount, | ||
valueRowCount: valueRowCount | ||
}; | ||
} | ||
var rowCount = Math.floor(height / singleRowHeight); | ||
return { | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight, | ||
rowCount: rowCount | ||
}; | ||
} | ||
function calculateNodeStyling(node, uid, useCache) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
function calculateNodeStyling(node, uid, useCache) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
if (useCache && computedStyleCache[uid]) { | ||
return computedStyleCache[uid]; | ||
} | ||
if (useCache && computedStyleCache[uid]) { | ||
return computedStyleCache[uid]; | ||
} | ||
var style = window.getComputedStyle(node); | ||
var style = window.getComputedStyle(node); | ||
if (style === null) { | ||
return null; | ||
} | ||
if (style === null) { | ||
return null; | ||
} | ||
var sizingStyle = SIZING_STYLE.reduce(function (obj, name) { | ||
obj[name] = style.getPropertyValue(name); | ||
return obj; | ||
}, {}); | ||
var boxSizing = sizingStyle['box-sizing']; // probably node is detached from DOM, can't read computed dimensions | ||
var sizingStyle = SIZING_STYLE.reduce(function (obj, name) { | ||
obj[name] = style.getPropertyValue(name); | ||
return obj; | ||
}, {}); | ||
var boxSizing = sizingStyle['box-sizing']; // probably node is detached from DOM, can't read computed dimensions | ||
if (boxSizing === '') { | ||
return null; | ||
} // IE (Edge has already correct behaviour) returns content width as computed width | ||
// so we need to add manually padding and border widths | ||
if (boxSizing === '') { | ||
return null; | ||
} // IE (Edge has already correct behaviour) returns content width as computed width | ||
// so we need to add manually padding and border widths | ||
if (isIE && boxSizing === 'border-box') { | ||
sizingStyle.width = parseFloat(sizingStyle.width) + parseFloat(style['border-right-width']) + parseFloat(style['border-left-width']) + parseFloat(style['padding-right']) + parseFloat(style['padding-left']) + 'px'; | ||
} | ||
if (isIE && boxSizing === 'border-box') { | ||
sizingStyle.width = parseFloat(sizingStyle.width) + parseFloat(style['border-right-width']) + parseFloat(style['border-left-width']) + parseFloat(style['padding-right']) + parseFloat(style['padding-left']) + 'px'; | ||
var paddingSize = parseFloat(sizingStyle['padding-bottom']) + parseFloat(sizingStyle['padding-top']); | ||
var borderSize = parseFloat(sizingStyle['border-bottom-width']) + parseFloat(sizingStyle['border-top-width']); | ||
var nodeInfo = { | ||
sizingStyle: sizingStyle, | ||
paddingSize: paddingSize, | ||
borderSize: borderSize, | ||
boxSizing: boxSizing | ||
}; | ||
if (useCache) { | ||
computedStyleCache[uid] = nodeInfo; | ||
} | ||
return nodeInfo; | ||
} | ||
var paddingSize = parseFloat(sizingStyle['padding-bottom']) + parseFloat(sizingStyle['padding-top']); | ||
var borderSize = parseFloat(sizingStyle['border-bottom-width']) + parseFloat(sizingStyle['border-top-width']); | ||
var nodeInfo = { | ||
sizingStyle: sizingStyle, | ||
paddingSize: paddingSize, | ||
borderSize: borderSize, | ||
boxSizing: boxSizing | ||
var purgeCache = function purgeCache(uid) { | ||
delete computedStyleCache[uid]; | ||
}; | ||
if (useCache) { | ||
computedStyleCache[uid] = nodeInfo; | ||
} | ||
var noop = function noop() {}; // IE11 has a problem with eval source maps, can be reproduced with: | ||
// eval('"use strict"; var onNextFrame = window.cancelAnimationFrame; onNextFrame(4);') | ||
// so we bind window as context in dev modes | ||
return nodeInfo; | ||
} | ||
var purgeCache = function purgeCache(uid) { | ||
return delete computedStyleCache[uid]; | ||
}; | ||
var _ref = window.requestAnimationFrame ? [window.requestAnimationFrame.bind(window), window.cancelAnimationFrame.bind(window)] : [setTimeout, clearTimeout], | ||
onNextFrame = _ref[0], | ||
clearNextFrameAction = _ref[1]; | ||
function autoInc(seed) { | ||
if (seed === void 0) { | ||
seed = 0; | ||
} | ||
var uid = 0; | ||
return function () { | ||
return ++seed; | ||
}; | ||
} | ||
var TextareaAutosize = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(TextareaAutosize, _React$Component); | ||
var uid = autoInc(); | ||
function TextareaAutosize(props) { | ||
var _this; | ||
/** | ||
* <TextareaAutosize /> | ||
*/ | ||
var noop = function noop() {}; // IE11 has a problem with eval source maps, can be reproduced with: | ||
// eval('"use strict"; var onNextFrame = window.cancelAnimationFrame; onNextFrame(4);') | ||
// so we bind window as context in dev modes | ||
_this = _React$Component.call(this, props) || this; | ||
_this._onRef = function (node) { | ||
_this._ref = node; | ||
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame.bind(window), window.cancelAnimationFrame.bind(window)] : [setTimeout, clearTimeout]; | ||
var onNextFrame = _ref[0]; | ||
var clearNextFrameAction = _ref[1]; | ||
_this.props.inputRef(node); | ||
}; | ||
var TextareaAutosize = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(TextareaAutosize, _React$Component); | ||
_this._onChange = function (event) { | ||
if (!_this._controlled) { | ||
_this._resizeComponent(); | ||
} | ||
function TextareaAutosize(props) { | ||
var _this; | ||
_this.props.onChange(event, _assertThisInitialized(_assertThisInitialized(_this))); | ||
}; | ||
_this = _React$Component.call(this, props) || this; | ||
_this._resizeLock = false; | ||
_this._resizeComponent = function (callback) { | ||
if (callback === void 0) { | ||
callback = noop; | ||
} | ||
_this._onRootDOMNode = function (node) { | ||
_this._rootDOMNode = node; | ||
var nodeHeight = calculateNodeHeight(_this._ref, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows); | ||
_this.props.inputRef(node); | ||
}; | ||
if (nodeHeight === null) { | ||
callback(); | ||
return; | ||
} | ||
_this._onChange = function (event) { | ||
if (!_this._controlled) { | ||
_this._resizeComponent(); | ||
} | ||
var height = nodeHeight.height, | ||
minHeight = nodeHeight.minHeight, | ||
maxHeight = nodeHeight.maxHeight, | ||
rowCount = nodeHeight.rowCount, | ||
valueRowCount = nodeHeight.valueRowCount; | ||
_this.rowCount = rowCount; | ||
_this.valueRowCount = valueRowCount; | ||
_this.props.onChange(event); | ||
}; | ||
if (_this.state.height !== height || _this.state.minHeight !== minHeight || _this.state.maxHeight !== maxHeight) { | ||
_this.setState({ | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight | ||
}, callback); | ||
_this._resizeComponent = function (callback) { | ||
if (callback === void 0) { | ||
callback = noop; | ||
} | ||
return; | ||
} | ||
if (typeof _this._rootDOMNode === 'undefined') { | ||
callback(); | ||
return; | ||
} | ||
}; | ||
var nodeHeight = calculateNodeHeight(_this._rootDOMNode, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows); | ||
_this.state = { | ||
height: props.style && props.style.height || 0, | ||
minHeight: -Infinity, | ||
maxHeight: Infinity | ||
}; | ||
_this._uid = uid++; | ||
_this._controlled = props.value !== undefined; | ||
_this._resizeLock = false; | ||
return _this; | ||
} | ||
if (nodeHeight === null) { | ||
callback(); | ||
return; | ||
} | ||
var _proto = TextareaAutosize.prototype; | ||
var height = nodeHeight.height, | ||
minHeight = nodeHeight.minHeight, | ||
maxHeight = nodeHeight.maxHeight, | ||
rowCount = nodeHeight.rowCount; | ||
_this.rowCount = rowCount; | ||
_proto.render = function render() { | ||
var _this$props = this.props, | ||
_inputRef = _this$props.inputRef, | ||
_maxRows = _this$props.maxRows, | ||
_minRows = _this$props.minRows, | ||
_onHeightChange = _this$props.onHeightChange, | ||
_useCacheForDOMMeasurements = _this$props.useCacheForDOMMeasurements, | ||
props = _objectWithoutProperties(_this$props, ["inputRef", "maxRows", "minRows", "onHeightChange", "useCacheForDOMMeasurements"]); | ||
if (_this.state.height !== height || _this.state.minHeight !== minHeight || _this.state.maxHeight !== maxHeight) { | ||
_this.setState({ | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight | ||
}, callback); | ||
props.style = _extends({}, props.style, { | ||
height: this.state.height | ||
}); | ||
var maxHeight = Math.max(props.style.maxHeight || Infinity, this.state.maxHeight); | ||
return; | ||
if (maxHeight < this.state.height) { | ||
props.style.overflow = 'hidden'; | ||
} | ||
callback(); | ||
return React.createElement("textarea", _extends({}, props, { | ||
onChange: this._onChange, | ||
ref: this._onRef | ||
})); | ||
}; | ||
_this.state = { | ||
height: props.style && props.style.height || 0, | ||
minHeight: -Infinity, | ||
maxHeight: Infinity | ||
}; | ||
_this._uid = uid(); | ||
_this._controlled = typeof props.value === 'string'; | ||
return _this; | ||
} | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
var _proto = TextareaAutosize.prototype; | ||
this._resizeComponent(); // Working around Firefox bug which runs resize listeners even when other JS is running at the same moment | ||
// causing competing rerenders (due to setState in the listener) in React. | ||
// More can be found here - facebook/react#6324 | ||
_proto.render = function render() { | ||
var _props = this.props, | ||
_inputRef = _props.inputRef, | ||
_maxRows = _props.maxRows, | ||
_minRows = _props.minRows, | ||
_onHeightChange = _props.onHeightChange, | ||
_useCacheForDOMMeasurements = _props.useCacheForDOMMeasurements, | ||
props = _objectWithoutProperties(_props, ["inputRef", "maxRows", "minRows", "onHeightChange", "useCacheForDOMMeasurements"]); | ||
props.style = _extends({}, props.style, { | ||
height: this.state.height | ||
}); | ||
var maxHeight = Math.max(props.style.maxHeight || Infinity, this.state.maxHeight); | ||
this._resizeListener = function () { | ||
if (_this2._resizeLock) { | ||
return; | ||
} | ||
if (maxHeight < this.state.height) { | ||
props.style.overflow = 'hidden'; | ||
} | ||
_this2._resizeLock = true; | ||
return React.createElement("textarea", _extends({}, props, { | ||
onChange: this._onChange, | ||
ref: this._onRootDOMNode | ||
})); | ||
}; | ||
_this2._resizeComponent(function () { | ||
_this2._resizeLock = false; | ||
}); | ||
}; | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
window.addEventListener('resize', this._resizeListener); | ||
}; | ||
this._resizeComponent(); // Working around Firefox bug which runs resize listeners even when other JS is running at the same moment | ||
// causing competing rerenders (due to setState in the listener) in React. | ||
// More can be found here - facebook/react#6324 | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
if (prevProps !== this.props) { | ||
clearNextFrameAction(this._rafId); | ||
this._rafId = onNextFrame(this._resizeComponent); | ||
} | ||
this._resizeListener = function () { | ||
if (_this2._resizeLock) { | ||
return; | ||
if (this.state.height !== prevState.height) { | ||
this.props.onHeightChange(this.state.height, this); | ||
} | ||
}; | ||
_this2._resizeLock = true; | ||
_this2._resizeComponent(function () { | ||
return _this2._resizeLock = false; | ||
}); | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
clearNextFrameAction(this._rafId); | ||
window.removeEventListener('resize', this._resizeListener); | ||
purgeCache(this._uid); | ||
}; | ||
window.addEventListener('resize', this._resizeListener); | ||
}; | ||
return TextareaAutosize; | ||
}(React.Component); | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var _this3 = this; | ||
if (prevProps !== this.props) { | ||
this._clearNextFrame(); | ||
this._onNextFrameActionId = onNextFrame(function () { | ||
return _this3._resizeComponent(); | ||
}); | ||
} | ||
if (this.state.height !== prevState.height) { | ||
this.props.onHeightChange(this.state.height, this); | ||
} | ||
TextareaAutosize.defaultProps = { | ||
inputRef: noop, | ||
onChange: noop, | ||
onHeightChange: noop, | ||
useCacheForDOMMeasurements: false | ||
}; | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._clearNextFrame(); | ||
window.removeEventListener('resize', this._resizeListener); | ||
purgeCache(this._uid); | ||
TextareaAutosize.propTypes = { | ||
inputRef: propTypes.func, | ||
maxRows: propTypes.number, | ||
minRows: propTypes.number, | ||
onChange: propTypes.func, | ||
onHeightChange: propTypes.func, | ||
useCacheForDOMMeasurements: propTypes.bool, | ||
value: propTypes.string | ||
}; | ||
_proto._clearNextFrame = function _clearNextFrame() { | ||
clearNextFrameAction(this._onNextFrameActionId); | ||
}; | ||
exports.default = TextareaAutosize; | ||
return TextareaAutosize; | ||
}(React.Component); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
TextareaAutosize.propTypes = { | ||
inputRef: propTypes.func, | ||
maxRows: propTypes.number, | ||
minRows: propTypes.number, | ||
onChange: propTypes.func, | ||
onHeightChange: propTypes.func, | ||
useCacheForDOMMeasurements: propTypes.bool, | ||
value: propTypes.string | ||
}; | ||
TextareaAutosize.defaultProps = { | ||
inputRef: noop, | ||
onChange: noop, | ||
onHeightChange: noop, | ||
useCacheForDOMMeasurements: false | ||
}; | ||
exports['default'] = TextareaAutosize; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.TextareaAutosize={},e.React)}(this,function(e,t){"use strict";function n(){return(n=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}t=t&&t.hasOwnProperty("default")?t.default:t;var r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e};"object"==typeof Reflect&&Reflect;function o(e){return function(){return e}}var i=function(){};i.thatReturns=o,i.thatReturnsFalse=o(!1),i.thatReturnsTrue=o(!0),i.thatReturnsNull=o(null),i.thatReturnsThis=function(){return this},i.thatReturnsArgument=function(e){return e};var a=i;var s=function(e,t,n,r,o,i,a,s){if(!e){var u;if(void 0===t)u=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var h=[n,r,o,i,a,s],p=0;(u=Error(t.replace(/%s/g,function(){return h[p++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}},u=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,p=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;10>n;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return!1;var r={};"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),Object.keys(Object.assign({},r)).join("")}catch(e){return!1}}();var l,c="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",d=(function(e){e.exports=function(){function e(e,t,n,r,o,i){i!==c&&s(!1,"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")}function t(){return e}e.isRequired=e;var n={array:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return n.checkPropTypes=a,n.PropTypes=n,n}()}(l={exports:{}},l.exports),l.exports),f="undefined"!=typeof window&&"undefined"!=typeof document,g=!!f&&!!document.documentElement.currentStyle,m={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0"},b=["letter-spacing","line-height","font-family","font-weight","font-size","font-style","tab-size","text-rendering","text-transform","width","text-indent","padding-top","padding-right","padding-bottom","padding-left","border-top-width","border-right-width","border-bottom-width","border-left-width","box-sizing"],y={},v=f&&document.createElement("textarea"),_=function(e){Object.keys(m).forEach(function(t){e.style.setProperty(t,m[t],"important")})};function w(e,t,n,r,o){void 0===n&&(n=!1),void 0===r&&(r=null),void 0===o&&(o=null),null===v.parentNode&&document.body.appendChild(v);var i=function(e,t,n){void 0===n&&(n=!1);if(n&&y[t])return y[t];var r=window.getComputedStyle(e);if(null===r)return null;var o=b.reduce(function(e,t){return e[t]=r.getPropertyValue(t),e},{}),i=o["box-sizing"];if(""===i)return null;g&&"border-box"===i&&(o.width=parseFloat(o.width)+parseFloat(r["border-right-width"])+parseFloat(r["border-left-width"])+parseFloat(r["padding-right"])+parseFloat(r["padding-left"])+"px");var a={sizingStyle:o,paddingSize:parseFloat(o["padding-bottom"])+parseFloat(o["padding-top"]),borderSize:parseFloat(o["border-bottom-width"])+parseFloat(o["border-top-width"]),boxSizing:i};n&&(y[t]=a);return a}(e,t,n);if(null===i)return null;var a=i.paddingSize,s=i.borderSize,u=i.boxSizing,h=i.sizingStyle;Object.keys(h).forEach(function(e){v.style[e]=h[e]}),_(v),v.value=e.value||e.placeholder||"x";var p=-1/0,l=1/0,c=v.scrollHeight;"border-box"===u?c+=s:"content-box"===u&&(c-=a),v.value="x";var d=v.scrollHeight-a;return null===r&&null===o||(null!==r&&(p=d*r,"border-box"===u&&(p=p+a+s),c=Math.max(p,c)),null!==o&&(l=d*o,"border-box"===u&&(l=l+a+s),c=Math.min(l,c))),{height:c,minHeight:p,maxHeight:l,rowCount:Math.floor(c/d)}}f&&_(v);var x,O=(void 0===x&&(x=0),function(){return++x}),C=function(){},z=f&&window.requestAnimationFrame?[window.requestAnimationFrame,window.cancelAnimationFrame]:[setTimeout,clearTimeout],j=z[0],R=z[1],F=function(e){var r,o;function i(t){var n;return(n=e.call(this,t)||this)._resizeLock=!1,n._onRootDOMNode=function(e){n._rootDOMNode=e,n.props.inputRef(e)},n._onChange=function(e){n._controlled||n._resizeComponent(),n.props.onChange(e)},n._resizeComponent=function(e){if(void 0===e&&(e=C),void 0!==n._rootDOMNode){var t=w(n._rootDOMNode,n._uid,n.props.useCacheForDOMMeasurements,n.props.minRows,n.props.maxRows);if(null!==t){var r=t.height,o=t.minHeight,i=t.maxHeight;n.rowCount=t.rowCount,n.state.height===r&&n.state.minHeight===o&&n.state.maxHeight===i?e():n.setState({height:r,minHeight:o,maxHeight:i},e)}else e()}else e()},n.state={height:t.style&&t.style.height||0,minHeight:-1/0,maxHeight:1/0},n._uid=O(),n._controlled="string"==typeof t.value,n}(r=i).prototype=Object.create((o=e).prototype),r.prototype.constructor=r,r.__proto__=o;var a=i.prototype;return a.render=function(){var e=this.props,r=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;i.length>r;r++)0>t.indexOf(n=i[r])&&(o[n]=e[n]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;a.length>r;r++)0>t.indexOf(n=a[r])&&Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,["inputRef","maxRows","minRows","onHeightChange","useCacheForDOMMeasurements"]);return r.style=n({},r.style,{height:this.state.height}),this.state.height>Math.max(r.style.maxHeight||1/0,this.state.maxHeight)&&(r.style.overflow="hidden"),t.createElement("textarea",n({},r,{onChange:this._onChange,ref:this._onRootDOMNode}))},a.componentDidMount=function(){var e=this;this._resizeComponent(),this._resizeListener=function(){e._resizeLock||(e._resizeLock=!0,e._resizeComponent(function(){return e._resizeLock=!1}))},window.addEventListener("resize",this._resizeListener)},a.componentDidUpdate=function(e,t){var n=this;e!==this.props&&(this._clearNextFrame(),this._onNextFrameActionId=j(function(){return n._resizeComponent()})),this.state.height!==t.height&&this.props.onHeightChange(this.state.height,this)},a.componentWillUnmount=function(){this._clearNextFrame(),window.removeEventListener("resize",this._resizeListener),delete y[this._uid]},a._clearNextFrame=function(){R(this._onNextFrameActionId)},i}(t.Component);F.propTypes={inputRef:d.func,maxRows:d.number,minRows:d.number,onChange:d.func,onHeightChange:d.func,useCacheForDOMMeasurements:d.bool,value:d.string},F.defaultProps={inputRef:C,onChange:C,onHeightChange:C,useCacheForDOMMeasurements:!1},e.default=F,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.TextareaAutosize={},e.React)}(this,function(e,i){"use strict";function a(){return(a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}i=i&&i.hasOwnProperty("default")?i.default:i;var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;!function(){try{if(!Object.assign)return;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return;var n={};"abcdefghijklmnopqrst".split("").forEach(function(e){n[e]=e}),Object.keys(Object.assign({},n)).join("")}catch(e){return}}();var o="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",h=Object.freeze({default:o,__moduleExports:o}),p=h?o:h;function u(){}var l,d=function(){function e(e,t,r,n,o,i){if(i!==p){var a=Error("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");throw a.name="Invariant Violation",a}}function t(){return e}var r={array:e.isRequired=e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t};return r.checkPropTypes=u,r.PropTypes=r},c=Object.freeze({default:d,__moduleExports:d}),f=c&&d||c,g=(function(e){e.exports=f()}(l={exports:{}},l.exports),!!document.documentElement.currentStyle),m={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0"},b=["letter-spacing","line-height","font-family","font-weight","font-size","font-style","tab-size","text-rendering","text-transform","width","text-indent","padding-top","padding-right","padding-bottom","padding-left","border-top-width","border-right-width","border-bottom-width","border-left-width","box-sizing"],y={},v=document.createElement("textarea"),w=function(t){Object.keys(m).forEach(function(e){t.style.setProperty(e,m[e],"important")})};function _(e,t,r,n,o){void 0===r&&(r=!1),void 0===n&&(n=null),void 0===o&&(o=null),null===v.parentNode&&document.body.appendChild(v);var i=function(e,t,r){void 0===r&&(r=!1);if(r&&y[t])return y[t];var n=window.getComputedStyle(e);if(null===n)return null;var o=b.reduce(function(e,t){return e[t]=n.getPropertyValue(t),e},{}),i=o["box-sizing"];if(""===i)return null;g&&"border-box"===i&&(o.width=parseFloat(o.width)+parseFloat(n["border-right-width"])+parseFloat(n["border-left-width"])+parseFloat(n["padding-right"])+parseFloat(n["padding-left"])+"px");var a={sizingStyle:o,paddingSize:parseFloat(o["padding-bottom"])+parseFloat(o["padding-top"]),borderSize:parseFloat(o["border-bottom-width"])+parseFloat(o["border-top-width"]),boxSizing:i};r&&(y[t]=a);return a}(e,t,r);if(null===i)return null;var a=i.paddingSize,s=i.borderSize,h=i.boxSizing,p=i.sizingStyle;Object.keys(p).forEach(function(e){v.style[e]=p[e]}),w(v),v.value=e.value||e.placeholder||"x";var u=-1/0,l=1/0,d=v.scrollHeight;"border-box"===h?d+=s:"content-box"===h&&(d-=a),v.value="x";var c=v.scrollHeight-a,f=Math.floor(d/c);return null!==n&&(u=c*n,"border-box"===h&&(u=u+a+s),d=Math.max(u,d)),null!==o&&(l=c*o,"border-box"===h&&(l=l+a+s),d=Math.min(l,d)),{height:d,minHeight:u,maxHeight:l,rowCount:Math.floor(d/c),valueRowCount:f}}w(v);var x=function(){},O=window.requestAnimationFrame?[window.requestAnimationFrame,window.cancelAnimationFrame]:[setTimeout,clearTimeout],z=O[0],C=O[1],j=0,S=function(t){var e,r;function n(e){var a;return(a=t.call(this,e)||this)._onRef=function(e){a._ref=e,a.props.inputRef(e)},a._onChange=function(e){a._controlled||a._resizeComponent(),a.props.onChange(e,s(s(a)))},a._resizeComponent=function(e){void 0===e&&(e=x);var t=_(a._ref,a._uid,a.props.useCacheForDOMMeasurements,a.props.minRows,a.props.maxRows);if(null!==t){var r=t.height,n=t.minHeight,o=t.maxHeight,i=t.valueRowCount;a.rowCount=t.rowCount,a.valueRowCount=i,a.state.height===r&&a.state.minHeight===n&&a.state.maxHeight===o?e():a.setState({height:r,minHeight:n,maxHeight:o},e)}else e()},a.state={height:e.style&&e.style.height||0,minHeight:-1/0,maxHeight:1/0},a._uid=j++,a._controlled=void 0!==e.value,a._resizeLock=!1,a}(e=n).prototype=Object.create((r=t).prototype),(e.prototype.constructor=e).__proto__=r;var o=n.prototype;return o.render=function(){var e=this.props,t=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)t.indexOf(r=i[n])<0&&(o[r]=e[r]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,["inputRef","maxRows","minRows","onHeightChange","useCacheForDOMMeasurements"]);return t.style=a({},t.style,{height:this.state.height}),Math.max(t.style.maxHeight||1/0,this.state.maxHeight)<this.state.height&&(t.style.overflow="hidden"),i.createElement("textarea",a({},t,{onChange:this._onChange,ref:this._onRef}))},o.componentDidMount=function(){var e=this;this._resizeComponent(),this._resizeListener=function(){e._resizeLock||(e._resizeLock=!0,e._resizeComponent(function(){e._resizeLock=!1}))},window.addEventListener("resize",this._resizeListener)},o.componentDidUpdate=function(e,t){e!==this.props&&(C(this._rafId),this._rafId=z(this._resizeComponent)),this.state.height!==t.height&&this.props.onHeightChange(this.state.height,this)},o.componentWillUnmount=function(){C(this._rafId),window.removeEventListener("resize",this._resizeListener),delete y[this._uid]},n}(i.Component);S.defaultProps={inputRef:x,onChange:x,onHeightChange:x,useCacheForDOMMeasurements:!1},e.default=S,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "react-textarea-autosize", | ||
"description": "textarea component for React which grows with content", | ||
"version": "6.1.0", | ||
"version": "7.0.0", | ||
"keywords": "autosize, grow, react, react-component, textarea", | ||
@@ -9,4 +9,8 @@ "repository": "andreypopp/react-textarea-autosize", | ||
"main": "dist/react-textarea-autosize.cjs.js", | ||
"module": "dist/react-textarea-autosize.es.js", | ||
"jsnext:main": "dist/react-textarea-autosize.es.js", | ||
"module": "dist/react-textarea-autosize.esm.js", | ||
"browser": { | ||
"dist/react-textarea-autosize.cjs.js": "dist/react-textarea-autosize.cjs.browser.js", | ||
"dist/react-textarea-autosize.esm.js": "dist/react-textarea-autosize.esm.browser.js" | ||
}, | ||
"jsnext:main": "dist/react-textarea-autosize.esm.js", | ||
"unpkg": "dist/react-textarea-autosize.min.js", | ||
@@ -22,4 +26,5 @@ "sideEffects": false, | ||
"lint": "eslint src", | ||
"update:size": "npm run build && node scripts/update-size.js && git add README.md", | ||
"prepare": "npm run build", | ||
"precommit": "lint-staged", | ||
"precommit": "lint-staged && npm run update:size", | ||
"prerelease": "npm run lint", | ||
@@ -34,7 +39,11 @@ "release:patch": "npm run prerelease && npm version patch && npm publish && git push --follow-tags", | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.40", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.40", | ||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.40", | ||
"@babel/preset-env": "7.0.0-beta.40", | ||
"@babel/preset-react": "7.0.0-beta.40", | ||
"@babel/core": "7.0.0-beta.51", | ||
"@babel/helper-module-imports": "7.0.0-beta.52", | ||
"@babel/plugin-proposal-class-properties": "7.0.0-beta.51", | ||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-beta.51", | ||
"@babel/preset-env": "7.0.0-beta.51", | ||
"@babel/preset-react": "7.0.0-beta.51", | ||
"babel-plugin-macros": "^2.2.2", | ||
"babel-plugin-transform-define": "^1.3.0", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.13", | ||
"cross-env": "^5.0.1", | ||
@@ -44,14 +53,17 @@ "eslint": "^4.12.0", | ||
"eslint-plugin-react": "^7.5.1", | ||
"format-bytes": "^1.0.1", | ||
"gzip-size": "^4.1.0", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^5.0.0", | ||
"prettier": "^1.8.2", | ||
"prettier": "^1.13.7", | ||
"react": "^15.6.1", | ||
"react-dom": "^15.6.1", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-babel": "4.0.0-beta.2", | ||
"rollup": "^0.62.0", | ||
"rollup-plugin-babel": "4.0.0-beta.7", | ||
"rollup-plugin-commonjs": "^8.3.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^2.0.1" | ||
"rollup-plugin-uglify": "^2.0.1", | ||
"terser": "^3.7.6" | ||
}, | ||
@@ -58,0 +70,0 @@ "files": [ |
@@ -7,4 +7,5 @@ [![npm version](https://img.shields.io/npm/v/react-textarea-autosize.svg)](https://www.npmjs.com/package/react-textarea-autosize) | ||
Drop-in replacement for the textarea component which automatically resizes | ||
textarea as content changes. A native React version of the popular [jQuery | ||
Autosize](http://www.jacklmoore.com/autosize/)! | ||
textarea as content changes. A native React version of the popular | ||
[jQuery Autosize](http://www.jacklmoore.com/autosize/)! Weighs | ||
<span class="weight">1.92 KB</span> (minified & gzipped). | ||
@@ -87,3 +88,3 @@ This module supports IE9 and above. | ||
`package.json` and then create a new git commit with tag. If tests or linter | ||
fails — commit won't be created. If tasks succeed it publishes to npm and | ||
pushes a tag to github. | ||
fails — commit won't be created. If tasks succeed it publishes to npm and pushes | ||
a tag to github. |
99880
9
2278
89
28
9