tt-react-textarea-autosize
Advanced tools
Comparing version 5.1.0-tt3 to 6.1.0-tt1
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('prop-types')) : | ||
typeof define === 'function' && define.amd ? define(['react', 'prop-types'], factory) : | ||
(global.TextareaAutosize = factory(global.React,global.PropTypes)); | ||
}(this, (function (React,PropTypes) { 'use strict'; | ||
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; | ||
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes; | ||
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]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
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]; | ||
} | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
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]; | ||
} | ||
} | ||
return target; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
/** | ||
* 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 makeEmptyFunction(arg) { | ||
return function () { | ||
return arg; | ||
}; | ||
} | ||
/** | ||
* 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() {}; | ||
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; | ||
}; | ||
var emptyFunction_1 = emptyFunction; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
/** | ||
* Use 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. | ||
*/ | ||
var validateFormat = function validateFormat(format) {}; | ||
{ | ||
validateFormat = function validateFormat(format) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
}; | ||
} | ||
function invariant(condition, format, a, b, c, d, e, f) { | ||
validateFormat(format); | ||
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'; | ||
} | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
} | ||
} | ||
var invariant_1 = invariant; | ||
/** | ||
* 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. | ||
*/ | ||
var warning = emptyFunction_1; | ||
{ | ||
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]; | ||
} | ||
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) {} | ||
}; | ||
warning = function warning(condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
if (format.indexOf('Failed Composite propType: ') === 0) { | ||
return; // Ignore CompositeComponent proptype check. | ||
} | ||
if (!condition) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
printWarning.apply(undefined, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
var warning_1 = warning; | ||
/* | ||
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; | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
return Object(val); | ||
} | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
// Detect buggy property enumeration order in older V8 versions. | ||
// 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; | ||
} | ||
// 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; | ||
} | ||
// 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 objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[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]]; | ||
} | ||
} | ||
} | ||
} | ||
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 : ''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
var checkPropTypes_1 = checkPropTypes; | ||
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; | ||
} | ||
} | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
var ANONYMOUS = '<<anonymous>>'; | ||
// Important! | ||
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`. | ||
var ReactPropTypes = { | ||
array: createPrimitiveTypeChecker('array'), | ||
bool: createPrimitiveTypeChecker('boolean'), | ||
func: createPrimitiveTypeChecker('function'), | ||
number: createPrimitiveTypeChecker('number'), | ||
object: createPrimitiveTypeChecker('object'), | ||
string: createPrimitiveTypeChecker('string'), | ||
symbol: createPrimitiveTypeChecker('symbol'), | ||
any: createAnyTypeChecker(), | ||
arrayOf: createArrayOfTypeChecker, | ||
element: createElementTypeChecker(), | ||
instanceOf: createInstanceTypeChecker, | ||
node: createNodeChecker(), | ||
objectOf: createObjectOfTypeChecker, | ||
oneOf: createEnumTypeChecker, | ||
oneOfType: createUnionTypeChecker, | ||
shape: createShapeTypeChecker, | ||
exact: createStrictShapeTypeChecker, | ||
}; | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
/*eslint-disable no-self-compare*/ | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
return x !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
} | ||
} | ||
/*eslint-enable no-self-compare*/ | ||
/** | ||
* We use an Error-like object for backward compatibility as people may call | ||
* PropTypes directly and inspect their output. However, we don't use real | ||
* Errors anymore. We don't inspect their stack anyway, and creating them | ||
* is prohibitively expensive if they are created too often, such as what | ||
* happens in oneOfType() for any type before the one that matched. | ||
*/ | ||
function PropTypeError(message) { | ||
this.message = message; | ||
this.stack = ''; | ||
} | ||
// Make `instanceof Error` still work for returned errors. | ||
PropTypeError.prototype = Error.prototype; | ||
function createChainableTypeChecker(validate) { | ||
{ | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
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 | ||
); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
} | ||
} | ||
} | ||
if (props[propName] == null) { | ||
if (isRequired) { | ||
if (props[propName] === null) { | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); | ||
} | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); | ||
} | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
return chainedCheckType; | ||
} | ||
function createPrimitiveTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== expectedType) { | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunction_1.thatReturnsNull); | ||
} | ||
function createArrayOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); | ||
} | ||
var propValue = props[propName]; | ||
if (!Array.isArray(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); | ||
} | ||
for (var i = 0; i < propValue.length; i++) { | ||
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createElementTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!isValidElement(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createInstanceTypeChecker(expectedClass) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!(props[propName] instanceof expectedClass)) { | ||
var expectedClassName = expectedClass.name || ANONYMOUS; | ||
var actualClassName = getClassName(props[propName]); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
warning_1(false, 'Invalid argument supplied to oneOf, expected an instance of array.'); | ||
return emptyFunction_1.thatReturnsNull; | ||
} | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
for (var i = 0; i < expectedValues.length; i++) { | ||
if (is(propValue, expectedValues[i])) { | ||
return null; | ||
} | ||
} | ||
var valuesString = JSON.stringify(expectedValues); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createObjectOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); | ||
} | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); | ||
} | ||
for (var key in propValue) { | ||
if (propValue.hasOwnProperty(key)) { | ||
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
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 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; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createNodeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!isNode(props[propName])) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
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; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
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, ' ') | ||
); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
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)) { | ||
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])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
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; | ||
} | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
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'; | ||
} | ||
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'; | ||
} | ||
} | ||
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 class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
ReactPropTypes.checkPropTypes = checkPropTypes_1; | ||
ReactPropTypes.PropTypes = 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 REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = factoryWithTypeCheckers(isValidElement, throwOnDirectAccess); | ||
} | ||
}); | ||
var shallowequal = function shallowEqual(objA, objB, compare, compareContext) { | ||
var ret = compare ? compare.call(compareContext, objA, objB) : void 0; | ||
if(ret !== void 0) { | ||
return !!ret; | ||
} | ||
if(objA === objB) { | ||
return true; | ||
} | ||
if(typeof objA !== 'object' || !objA || | ||
typeof objB !== 'object' || !objB) { | ||
return false; | ||
} | ||
var keysA = Object.keys(objA); | ||
var keysB = Object.keys(objB); | ||
if(keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
var bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB); | ||
// Test for A's keys different from B. | ||
for(var idx = 0; idx < keysA.length; idx++) { | ||
var key = keysA[idx]; | ||
if(!bHasOwnProperty(key)) { | ||
return false; | ||
} | ||
var valueA = objA[key]; | ||
var valueB = objB[key]; | ||
ret = compare ? compare.call(compareContext, valueA, valueB, key) : void 0; | ||
if(ret === false || | ||
ret === void 0 && valueA !== valueB) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; | ||
var isIE = isBrowser ? !!document.documentElement.currentStyle : false; | ||
var hiddenTextarea = isBrowser && document.createElement('textarea'); | ||
var HIDDEN_TEXTAREA_STYLE = { | ||
@@ -26,18 +984,35 @@ 'min-height': '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 SIZING_STYLE = ['letter-spacing', 'line-height', 'font-family', 'font-weight', 'font-size', 'font-style', '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 forceHiddenStyles = function forceHiddenStyles(node) { | ||
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) { | ||
node.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important'); | ||
}); | ||
}; | ||
var computedStyleCache = {}; | ||
if (isBrowser) { | ||
forceHiddenStyles(hiddenTextarea); | ||
} | ||
function calculateNodeHeight(uiTextNode, uid) { | ||
var useCache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var minRows = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; | ||
var maxRows = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; | ||
function calculateNodeHeight(uiTextNode, uid, useCache, minRows, maxRows) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
if (minRows === void 0) { | ||
minRows = null; | ||
} | ||
if (maxRows === void 0) { | ||
maxRows = null; | ||
} | ||
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 | ||
// Copy all CSS properties that have an impact on the height of the content in | ||
// the textbox | ||
var nodeStyling = calculateNodeStyling(uiTextNode, uid, useCache); | ||
@@ -52,5 +1027,3 @@ | ||
boxSizing = nodeStyling.boxSizing, | ||
sizingStyle = nodeStyling.sizingStyle; | ||
// Need to have the overflow attribute to hide the scrollbar otherwise | ||
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 | ||
@@ -62,7 +1035,4 @@ // narrower for content | ||
}); | ||
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) { | ||
hiddenTextarea.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important'); | ||
}); | ||
forceHiddenStyles(hiddenTextarea); | ||
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || 'x'; | ||
var minHeight = -Infinity; | ||
@@ -78,5 +1048,5 @@ var maxHeight = Infinity; | ||
height = height - paddingSize; | ||
} | ||
} // measure height of a textarea with a single row | ||
// measure height of a textarea with a single row | ||
hiddenTextarea.value = 'x'; | ||
@@ -88,12 +1058,17 @@ var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize; | ||
minHeight = singleRowHeight * minRows; | ||
if (boxSizing === 'border-box') { | ||
minHeight = minHeight + paddingSize + borderSize; | ||
} | ||
height = Math.max(minHeight, height); | ||
} | ||
if (maxRows !== null) { | ||
maxHeight = singleRowHeight * maxRows; | ||
if (boxSizing === 'border-box') { | ||
maxHeight = maxHeight + paddingSize + borderSize; | ||
} | ||
height = Math.min(maxHeight, height); | ||
@@ -104,8 +1079,14 @@ } | ||
var rowCount = Math.floor(height / singleRowHeight); | ||
return { height: height, minHeight: minHeight, maxHeight: maxHeight, rowCount: rowCount }; | ||
return { | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight, | ||
rowCount: rowCount | ||
}; | ||
} | ||
function calculateNodeStyling(node, uid) { | ||
var useCache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
function calculateNodeStyling(node, uid, useCache) { | ||
if (useCache === void 0) { | ||
useCache = false; | ||
} | ||
@@ -126,7 +1107,10 @@ if (useCache && computedStyleCache[uid]) { | ||
}, {}); | ||
var boxSizing = sizingStyle['box-sizing']; // probably node is detached from DOM, can't read computed dimensions | ||
var boxSizing = sizingStyle['box-sizing']; | ||
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 | ||
// 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') { | ||
@@ -137,5 +1121,3 @@ 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 = { | ||
@@ -159,4 +1141,6 @@ sizingStyle: sizingStyle, | ||
function autoInc() { | ||
var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
function autoInc(seed) { | ||
if (seed === void 0) { | ||
seed = 0; | ||
} | ||
@@ -170,97 +1154,25 @@ return function () { | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var _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]; | ||
} | ||
} | ||
} | ||
return target; | ||
}; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
enumerable: false, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; | ||
}; | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
} | ||
return target; | ||
}; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
/** | ||
* <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 | ||
var noop = function noop() {}; | ||
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame, window.cancelAnimationFrame].map(function (f) { | ||
return f.bind(window); | ||
}) : [setTimeout, clearTimeout]; | ||
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame.bind(window), window.cancelAnimationFrame.bind(window)] : [setTimeout, clearTimeout]; | ||
var onNextFrame = _ref[0]; | ||
var clearNextFrameAction = _ref[1]; | ||
var TextareaAutosize = function (_React$Component) { | ||
inherits(TextareaAutosize, _React$Component); | ||
var TextareaAutosize = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(TextareaAutosize, _React$Component); | ||
function TextareaAutosize(props) { | ||
classCallCheck(this, TextareaAutosize); | ||
var _this; | ||
var _this = possibleConstructorReturn(this, _React$Component.call(this, props)); | ||
_this = _React$Component.call(this, props) || this; | ||
_this._resizeLock = false; | ||
_this._style = null; | ||
@@ -270,5 +1182,3 @@ _this._onRootDOMNode = function (node) { | ||
if (_this.props.inputRef) { | ||
_this.props.inputRef(node); | ||
} | ||
_this.props.inputRef(node); | ||
}; | ||
@@ -280,7 +1190,10 @@ | ||
} | ||
_this.props.onChange(event); | ||
}; | ||
_this._resizeComponent = function () { | ||
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : noop; | ||
_this._resizeComponent = function (callback) { | ||
if (callback === void 0) { | ||
callback = noop; | ||
} | ||
@@ -303,8 +1216,11 @@ if (typeof _this._rootDOMNode === 'undefined') { | ||
rowCount = nodeHeight.rowCount; | ||
_this.rowCount = rowCount; | ||
if (_this.state.height !== height || _this.state.minHeight !== minHeight || _this.state.maxHeight !== maxHeight) { | ||
_this.setState({ height: height, minHeight: minHeight, maxHeight: maxHeight }, callback); | ||
_this.setState({ | ||
height: height, | ||
minHeight: minHeight, | ||
maxHeight: maxHeight | ||
}, callback); | ||
return; | ||
@@ -321,3 +1237,2 @@ } | ||
}; | ||
_this._uid = uid(); | ||
@@ -328,23 +1243,29 @@ _this._controlled = typeof props.value === 'string'; | ||
TextareaAutosize.prototype.render = function render() { | ||
var _proto = TextareaAutosize.prototype; | ||
_proto.render = function render() { | ||
var _props = this.props, | ||
_inputRef = _props.inputRef, | ||
_maxRows = _props.maxRows, | ||
_minRows = _props.minRows, | ||
_maxRows = _props.maxRows, | ||
_onHeightChange = _props.onHeightChange, | ||
_useCacheForDOMMeasurements = _props.useCacheForDOMMeasurements, | ||
_inputRef = _props.inputRef, | ||
props = objectWithoutProperties(_props, ['minRows', 'maxRows', 'onHeightChange', 'useCacheForDOMMeasurements', 'inputRef']); | ||
props = _objectWithoutProperties(_props, ["inputRef", "maxRows", "minRows", "onHeightChange", "useCacheForDOMMeasurements"]); | ||
props.style = _extends({}, props.style, { | ||
var newStyle = _extends({}, props.style, { | ||
height: this.state.height | ||
}); | ||
var maxHeight = Math.max(props.style.maxHeight || Infinity, this.state.maxHeight); | ||
var maxHeight = Math.max(newStyle.maxHeight || Infinity, this.state.maxHeight); | ||
if (maxHeight < this.state.height) { | ||
props.style.overflow = 'hidden'; | ||
newStyle.overflow = 'hidden'; | ||
} | ||
return React.createElement('textarea', _extends({}, props, { | ||
if (!shallowequal(this._style, newStyle)) { | ||
this._style = newStyle; | ||
} | ||
props.style = this._style; | ||
return React.createElement("textarea", _extends({}, props, { | ||
onChange: this._onChange, | ||
@@ -355,9 +1276,10 @@ ref: this._onRootDOMNode | ||
TextareaAutosize.prototype.componentDidMount = function componentDidMount() { | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
this._resizeComponent(); | ||
// Working around Firefox bug which runs resize listeners even when other JS is running at the same moment | ||
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 | ||
this._resizeListener = function () { | ||
@@ -367,3 +1289,5 @@ if (_this2._resizeLock) { | ||
} | ||
_this2._resizeLock = true; | ||
_this2._resizeComponent(function () { | ||
@@ -373,15 +1297,17 @@ return _this2._resizeLock = false; | ||
}; | ||
window.addEventListener('resize', this._resizeListener); | ||
}; | ||
TextareaAutosize.prototype.componentWillReceiveProps = function componentWillReceiveProps() { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
var _this3 = this; | ||
this._clearNextFrame(); | ||
this._onNextFrameActionId = onNextFrame(function () { | ||
return _this3._resizeComponent(); | ||
}); | ||
}; | ||
if (prevProps !== this.props) { | ||
this._clearNextFrame(); | ||
TextareaAutosize.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState) { | ||
this._onNextFrameActionId = onNextFrame(function () { | ||
return _this3._resizeComponent(); | ||
}); | ||
} | ||
if (this.state.height !== prevState.height) { | ||
@@ -392,4 +1318,5 @@ this.props.onHeightChange(this.state.height, this); | ||
TextareaAutosize.prototype.componentWillUnmount = function componentWillUnmount() { | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._clearNextFrame(); | ||
window.removeEventListener('resize', this._resizeListener); | ||
@@ -399,3 +1326,3 @@ purgeCache(this._uid); | ||
TextareaAutosize.prototype._clearNextFrame = function _clearNextFrame() { | ||
_proto._clearNextFrame = function _clearNextFrame() { | ||
clearNextFrameAction(this._onNextFrameActionId); | ||
@@ -408,11 +1335,12 @@ }; | ||
TextareaAutosize.propTypes = { | ||
value: PropTypes.string, | ||
onChange: PropTypes.func, | ||
onHeightChange: PropTypes.func, | ||
useCacheForDOMMeasurements: PropTypes.bool, | ||
minRows: PropTypes.number, | ||
maxRows: PropTypes.number, | ||
inputRef: PropTypes.func | ||
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, | ||
@@ -423,4 +1351,6 @@ onHeightChange: noop, | ||
return TextareaAutosize; | ||
exports['default'] = TextareaAutosize; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["react","prop-types"],t):e.TextareaAutosize=t(e.React,e.PropTypes)}(this,function(e,t){"use strict";function n(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,i=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;null===a.parentNode&&document.body.appendChild(a);var h=o(e,t,n);if(null===h)return null;var u=h.paddingSize,l=h.borderSize,p=h.boxSizing,d=h.sizingStyle;Object.keys(d).forEach(function(e){a.style[e]=d[e]}),Object.keys(s).forEach(function(e){a.style.setProperty(e,s[e],"important")}),a.value=e.value||e.placeholder||"x";var c=-1/0,f=1/0,g=a.scrollHeight;"border-box"===p?g+=l:"content-box"===p&&(g-=u),a.value="x";var m=a.scrollHeight-u;return null===r&&null===i||(null!==r&&(c=m*r,"border-box"===p&&(c=c+u+l),g=Math.max(c,g)),null!==i&&(f=m*i,"border-box"===p&&(f=f+u+l),g=Math.min(f,g))),{height:g,minHeight:c,maxHeight:f,rowCount:Math.floor(g/m)}}function o(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(n&&u[t])return u[t];var o=window.getComputedStyle(e);if(null===o)return null;var r=h.reduce(function(e,t){return e[t]=o.getPropertyValue(t),e},{}),a=r["box-sizing"];i&&"border-box"===a&&(r.width=parseFloat(r.width)+parseFloat(o["border-right-width"])+parseFloat(o["border-left-width"])+parseFloat(o["padding-right"])+parseFloat(o["padding-left"])+"px");var s={sizingStyle:r,paddingSize:parseFloat(r["padding-bottom"])+parseFloat(r["padding-top"]),borderSize:parseFloat(r["border-bottom-width"])+parseFloat(r["border-top-width"]),boxSizing:a};return n&&(u[t]=s),s}e=e&&e.hasOwnProperty("default")?e.default:e,t=t&&t.hasOwnProperty("default")?t.default:t;var r="undefined"!=typeof window&&"undefined"!=typeof document,i=!!r&&!!document.documentElement.currentStyle,a=r&&document.createElement("textarea"),s={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0"},h=["letter-spacing","line-height","font-family","font-weight","font-size","font-style","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"],u={},l=function(e){return delete u[e]},p=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return function(){return++e}}(),d=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},f=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},g=function(e,t){var n={};for(var o in e)0>t.indexOf(o)&&Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},m=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},y=function(){},b=r&&window.requestAnimationFrame?[window.requestAnimationFrame,window.cancelAnimationFrame].map(function(e){return e.bind(window)}):[setTimeout,clearTimeout],w=b[0],v=b[1],x=function(t){function o(e){d(this,o);var r=m(this,t.call(this,e));return r._resizeLock=!1,r._onRootDOMNode=function(e){r._rootDOMNode=e,r.props.inputRef&&r.props.inputRef(e)},r._onChange=function(e){r._controlled||r._resizeComponent(),r.props.onChange(e)},r._resizeComponent=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y;if(void 0!==r._rootDOMNode){var t=n(r._rootDOMNode,r._uid,r.props.useCacheForDOMMeasurements,r.props.minRows,r.props.maxRows);if(null!==t){var o=t.height,i=t.minHeight,a=t.maxHeight,s=t.rowCount;r.rowCount=s,r.state.height===o&&r.state.minHeight===i&&r.state.maxHeight===a?e():r.setState({height:o,minHeight:i,maxHeight:a},e)}else e()}else e()},r.state={height:e.style&&e.style.height||0,minHeight:-1/0,maxHeight:1/0},r._uid=p(),r._controlled="string"==typeof e.value,r}return f(o,t),o.prototype.render=function(){var t=this.props,n=g(t,["minRows","maxRows","onHeightChange","useCacheForDOMMeasurements","inputRef"]);n.style=c({},n.style,{height:this.state.height});var o=Math.max(n.style.maxHeight||1/0,this.state.maxHeight);return this.state.height>o&&(n.style.overflow="hidden"),e.createElement("textarea",c({},n,{onChange:this._onChange,ref:this._onRootDOMNode}))},o.prototype.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)},o.prototype.componentWillReceiveProps=function(){var e=this;this._clearNextFrame(),this._onNextFrameActionId=w(function(){return e._resizeComponent()})},o.prototype.componentDidUpdate=function(e,t){this.state.height!==t.height&&this.props.onHeightChange(this.state.height,this)},o.prototype.componentWillUnmount=function(){this._clearNextFrame(),window.removeEventListener("resize",this._resizeListener),l(this._uid)},o.prototype._clearNextFrame=function(){v(this._onNextFrameActionId)},o}(e.Component);return x.propTypes={value:t.string,onChange:t.func,onHeightChange:t.func,useCacheForDOMMeasurements:t.bool,minRows:t.number,maxRows:t.number,inputRef:t.func},x.defaultProps={onChange:y,onHeightChange:y,useCacheForDOMMeasurements:!1},x}); | ||
!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 n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}i=i&&i.hasOwnProperty("default")?i.default:i;var t=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e};"object"==typeof Reflect&&Reflect;function n(e){return function(){return e}}var r=function(){};r.thatReturns=n,r.thatReturnsFalse=n(!1),r.thatReturnsTrue=n(!0),r.thatReturnsNull=n(null),r.thatReturnsThis=function(){return this},r.thatReturnsArgument=function(e){return e};var o=r;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],l=0;(u=Error(t.replace(/%s/g,function(){return h[l++]}))).name="Invariant Violation"}throw u.framesToPop=1,u}},u=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,l=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={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map(function(e){return t[e]}).join(""))return;var r={};"abcdefghijklmnopqrst".split("").forEach(function(e){r[e]=e}),Object.keys(Object.assign({},r)).join("")}catch(e){return}}();var p,c=(function(e){e.exports=function(){function e(e,t,n,r,o,i){"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"!==i&&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}var n={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 n.checkPropTypes=o,n.PropTypes=n}()}(p={exports:{}},p.exports),p.exports),d="undefined"!=typeof window&&"undefined"!=typeof document,f=!!d&&!!document.documentElement.currentStyle,g={"min-height":"0","max-height":"none",height:"0",visibility:"hidden",overflow:"hidden",position:"absolute","z-index":"-1000",top:"0",right:"0"},m=["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"],b={},y=d&&document.createElement("textarea"),v=function(t){Object.keys(g).forEach(function(e){t.style.setProperty(e,g[e],"important")})};function w(e,t,n,r,o){void 0===n&&(n=!1),void 0===r&&(r=null),void 0===o&&(o=null),null===y.parentNode&&document.body.appendChild(y);var i=function(e,t,n){void 0===n&&(n=!1);if(n&&b[t])return b[t];var r=window.getComputedStyle(e);if(null===r)return null;var o=m.reduce(function(e,t){return e[t]=r.getPropertyValue(t),e},{}),i=o["box-sizing"];if(""===i)return null;f&&"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&&(b[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){y.style[e]=h[e]}),v(y),y.value=e.value||e.placeholder||"x";var l=-1/0,p=1/0,c=y.scrollHeight;"border-box"===u?c+=s:"content-box"===u&&(c-=a),y.value="x";var d=y.scrollHeight-a;return null===r&&null===o||(null!==r&&(l=d*r,"border-box"===u&&(l=l+a+s),c=Math.max(l,c)),null!==o&&(p=d*o,"border-box"===u&&(p=p+a+s),c=Math.min(p,c))),{height:c,minHeight:l,maxHeight:p,rowCount:Math.floor(c/d)}}d&&v(y);var _,O=(void 0===_&&(_=0),function(){return++_}),x=function(){},j=d&&window.requestAnimationFrame?[window.requestAnimationFrame.bind(window),window.cancelAnimationFrame.bind(window)]:[setTimeout,clearTimeout],C=j[0],z=j[1],R=function(t){var e,n;function r(e){var i;return(i=t.call(this,e)||this)._resizeLock=!1,i._style=null,i._onRootDOMNode=function(e){i._rootDOMNode=e,i.props.inputRef(e)},i._onChange=function(e){i._controlled||i._resizeComponent(),i.props.onChange(e)},i._resizeComponent=function(e){if(void 0===e&&(e=x),void 0!==i._rootDOMNode){var t=w(i._rootDOMNode,i._uid,i.props.useCacheForDOMMeasurements,i.props.minRows,i.props.maxRows);if(null!==t){var n=t.height,r=t.minHeight,o=t.maxHeight;i.rowCount=t.rowCount,i.state.height===n&&i.state.minHeight===r&&i.state.maxHeight===o?e():i.setState({height:n,minHeight:r,maxHeight:o},e)}else e()}else e()},i.state={height:e.style&&e.style.height||0,minHeight:-1/0,maxHeight:1/0},i._uid=O(),i._controlled="string"==typeof e.value,i}(e=r).prototype=Object.create((n=t).prototype),(e.prototype.constructor=e).__proto__=n;var o=r.prototype;return o.render=function(){var e=this.props,t=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)t.indexOf(n=i[r])<0&&(o[n]=e[n]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t.indexOf(n=a[r])<0&&Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}(e,["inputRef","maxRows","minRows","onHeightChange","useCacheForDOMMeasurements"]),n=a({},t.style,{height:this.state.height});return Math.max(n.maxHeight||1/0,this.state.maxHeight)<this.state.height&&(n.overflow="hidden"),function(e,t,n,r){var o=n?n.call(r,e,t):void 0;if(void 0!==o)return!!o;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(var a=Object.prototype.hasOwnProperty.bind(t),s=0;s<i.length;s++){var u=i[s];if(!a(u))return!1;var h=e[u],l=t[u];if(!1===(o=n?n.call(r,h,l,u):void 0)||void 0===o&&h!==l)return!1}return!0}(this._style,n)||(this._style=n),t.style=this._style,i.createElement("textarea",a({},t,{onChange:this._onChange,ref:this._onRootDOMNode}))},o.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)},o.componentDidUpdate=function(e,t){var n=this;e!==this.props&&(this._clearNextFrame(),this._onNextFrameActionId=C(function(){return n._resizeComponent()})),this.state.height!==t.height&&this.props.onHeightChange(this.state.height,this)},o.componentWillUnmount=function(){this._clearNextFrame(),window.removeEventListener("resize",this._resizeListener),delete b[this._uid]},o._clearNextFrame=function(){z(this._onNextFrameActionId)},r}(i.Component);R.propTypes={inputRef:c.func,maxRows:c.number,minRows:c.number,onChange:c.func,onHeightChange:c.func,useCacheForDOMMeasurements:c.bool,value:c.string},R.defaultProps={inputRef:x,onChange:x,onHeightChange:x,useCacheForDOMMeasurements:!1},e.default=R,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "tt-react-textarea-autosize", | ||
"description": "textarea component for React which grows with content", | ||
"version": "5.1.0-tt3", | ||
"version": "6.1.0-tt1", | ||
"keywords": "autosize, grow, react, react-component, textarea", | ||
"repository": "mwolson/react-textarea-autosize", | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"module": "es/index.js", | ||
"jsnext:main": "es/index.js", | ||
"author": "Andrey Popp <8mayday@gmail.com> (https://andreypopp.com/)", | ||
"main": "dist/react-textarea-autosize.cjs.js", | ||
"module": "dist/react-textarea-autosize.es.js", | ||
"jsnext:main": "dist/react-textarea-autosize.es.js", | ||
"unpkg": "dist/react-textarea-autosize.min.js", | ||
"sideEffects": false, | ||
"author": "Andrey Popp <8mayday@gmail.com> (httsps://andreypopp.com/)", | ||
"scripts": { | ||
"prebuild": "npm run clean", | ||
"build": "run-p build:**", | ||
"build:es": "cross-env BABEL_ENV=es rollup -c -i src/index.js -o es/index.js", | ||
"build:cjs": "cross-env BABEL_ENV=cjs rollup -c -i src/index.js -o lib/index.js", | ||
"build:umd:prod": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c rollup.umd.config.js -i src/index.js -o dist/react-textarea-autosize.min.js", | ||
"build:umd:dev": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c rollup.umd.config.js -i src/index.js -o dist/react-textarea-autosize.js", | ||
"docs:build": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c example/rollup.config.js -i example/index.js -o example/bundle.js", | ||
"build": "rollup -c", | ||
"docs:build": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c example/rollup.config.js", | ||
"docs:publish": "npm run docs:build && cd example && rimraf .git && git init && git commit --allow-empty -m 'update docs' && git checkout -b gh-pages && touch .nojekyll && git add . && git commit -am 'update docs' && git push git@github.com:andreypopp/react-textarea-autosize gh-pages --force", | ||
"clean": "rimraf es && rimraf lib && rimraf dist", | ||
"clean": "rimraf dist", | ||
"lint": "eslint src", | ||
"prepare": "npm run build", | ||
"precommit": "lint-staged && run-p build:umd:** && git add dist", | ||
"precommit": "lint-staged", | ||
"prerelease": "npm run lint", | ||
@@ -34,33 +32,31 @@ "release:patch": "npm run prerelease && npm version patch && npm publish && git push --follow-tags", | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"@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", | ||
"cross-env": "^5.0.1", | ||
"eslint": "^3.3.1", | ||
"eslint-config-prometheusresearch": "^0.2.0", | ||
"eslint-plugin-react": "^6.1.2", | ||
"eslint": "^4.12.0", | ||
"eslint-config-prometheusresearch": "^0.4.0", | ||
"eslint-plugin-react": "^7.5.1", | ||
"husky": "^0.14.3", | ||
"lint-staged": "^4.0.2", | ||
"npm-run-all": "^4.0.2", | ||
"prettier": "^1.5.3", | ||
"lint-staged": "^5.0.0", | ||
"prettier": "^1.8.2", | ||
"react": "^15.6.1", | ||
"react-dom": "^15.6.1", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.45.2", | ||
"rollup-plugin-babel": "^2.7.1", | ||
"rollup-plugin-commonjs": "^8.0.2", | ||
"rollup": "^0.52.0", | ||
"rollup-plugin-babel": "4.0.0-beta.2", | ||
"rollup-plugin-commonjs": "^8.3.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"rollup-plugin-replace": "^1.1.1", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"rollup-plugin-uglify": "^2.0.1" | ||
}, | ||
"files": [ | ||
"es", | ||
"lib", | ||
"dist" | ||
], | ||
"dependencies": { | ||
"prop-types": "^15.5.10" | ||
"prop-types": "^15.6.0", | ||
"shallowequal": "^1.0.2" | ||
} | ||
} |
@@ -6,4 +6,4 @@ [![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 | ||
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/)! | ||
@@ -14,6 +14,5 @@ | ||
```javascript | ||
import Textarea from 'react-textarea-autosize'; | ||
import Textarea from "react-textarea-autosize"; | ||
// If you use CommonJS syntax: | ||
// | ||
// var Textarea = require('react-textarea-autosize').default; | ||
@@ -23,5 +22,6 @@ | ||
<div> | ||
<Textarea></Textarea> | ||
<Textarea /> | ||
</div>, | ||
document.getElementById('element')); | ||
document.getElementById("element") | ||
); | ||
``` | ||
@@ -35,3 +35,4 @@ | ||
* Fix 'InvalidCallingObject' issue with IE 11 | ||
- Fix 'InvalidCallingObject' issue with IE 11 | ||
- Performance: Use same `style` reference if no style changes occurred | ||
@@ -44,2 +45,44 @@ Original project: https://github.com/andreypopp/react-textarea-autosize | ||
## FAQ | ||
### How to focus | ||
Get a ref to inner textarea: | ||
```js | ||
<Textarea inputRef={tag => (this.textarea = tag)} /> | ||
``` | ||
And then call a focus on that ref: | ||
```js | ||
this.textarea.focus(); | ||
``` | ||
To autofocus: | ||
```js | ||
<Textarea autoFocus /> | ||
``` | ||
(all HTML attributes are passed to inner textarea) | ||
### How to test it with jest and react-test-renderer | ||
Because [jest](https://github.com/facebook/jest) provides polyfills for DOM | ||
objects by requiring [jsdom](https://github.com/tmpvar/jsdom) and | ||
[react-test-renderer](https://www.npmjs.com/package/react-test-renderer) doesn't | ||
provide refs for rendered components out of the box (calling ref callbacks with | ||
`null`), you need to supply a mocked ref in your tests. You can do it like this | ||
(more can be read | ||
[here](https://github.com/facebook/react/issues/7740#issuecomment-247335106)): | ||
```js | ||
const tree = renderer | ||
.create(<Textarea />, { | ||
createNodeMock: () => document.createElement("textarea") | ||
}) | ||
.toJSON(); | ||
``` | ||
## Development | ||
@@ -53,4 +96,5 @@ | ||
This will run eslint, compile sources from `src/` to `lib/`, `es/` and `dist/`, bump a | ||
version in `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. | ||
This will run eslint, compile sources from `src/` to `dist/`, bump a version in | ||
`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. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80135
21
1834
95
3
1
+ Addedshallowequal@^1.0.2
+ Addedshallowequal@1.1.0(transitive)
Updatedprop-types@^15.6.0