Socket
Socket
Sign inDemoInstall

react-textarea-autosize

Package Overview
Dependencies
Maintainers
4
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-textarea-autosize - npm Package Compare versions

Comparing version 5.0.7 to 5.1.0

57

dist/react-textarea-autosize.js
(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));
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';
React = 'default' in React ? React['default'] : React;
PropTypes = 'default' in PropTypes ? PropTypes['default'] : PropTypes;
React = React && React.hasOwnProperty('default') ? React['default'] : React;
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes;

@@ -189,27 +189,4 @@ var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';

var get = function get(object, property, receiver) {
if (object === null) object = Function.prototype;
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var inherits = function (subClass, superClass) {

@@ -259,26 +236,2 @@ if (typeof superClass !== "function" && superClass !== null) {

var set = function set(object, property, value, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent !== null) {
set(parent, property, value, receiver);
}
} else if ("value" in desc && desc.writable) {
desc.value = value;
} else {
var setter = desc.set;
if (setter !== undefined) {
setter.call(receiver, value);
}
}
return value;
};
/**

@@ -285,0 +238,0 @@ * <TextareaAutosize />

2

dist/react-textarea-autosize.min.js

@@ -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],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;null===a.parentNode&&document.body.appendChild(a);var u=o(e,t,n);if(null===u)return null;var h=u.paddingSize,l=u.borderSize,d=u.boxSizing,p=u.sizingStyle;Object.keys(p).forEach(function(e){a.style[e]=p[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"===d?g+=l:"content-box"===d&&(g-=h),a.value="x";var m=a.scrollHeight-h;return null===i&&null===r||(null!==i&&(c=m*i,"border-box"===d&&(c=c+h+l),g=Math.max(c,g)),null!==r&&(f=m*r,"border-box"===d&&(f=f+h+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&&h[t])return h[t];var o=window.getComputedStyle(e);if(null===o)return null;var i=u.reduce(function(e,t){return e[t]=o.getPropertyValue(t),e},{}),a=i["box-sizing"];r&&"border-box"===a&&(i.width=parseFloat(i.width)+parseFloat(o["border-right-width"])+parseFloat(o["border-left-width"])+parseFloat(o["padding-right"])+parseFloat(o["padding-left"])+"px");var s=parseFloat(i["padding-bottom"])+parseFloat(i["padding-top"]),l=parseFloat(i["border-bottom-width"])+parseFloat(i["border-top-width"]),d={sizingStyle:i,paddingSize:s,borderSize:l,boxSizing:a};return n&&(h[t]=d),d}e="default"in e?e.default:e,t="default"in t?t.default:t;var i="undefined"!=typeof window&&"undefined"!=typeof document,r=!!i&&!!document.documentElement.currentStyle,a=i&&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"},u=["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"],h={},l=function(e){return delete h[e]},d=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return function(){return++e}}(),p=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=i&&window.requestAnimationFrame?[window.requestAnimationFrame,window.cancelAnimationFrame]:[setTimeout,clearTimeout],v=b[0],w=b[1],x=function(t){function o(e){p(this,o);var i=m(this,t.call(this,e));return i._resizeLock=!1,i._onRootDOMNode=function(e){i._rootDOMNode=e,i.props.inputRef&&i.props.inputRef(e)},i._onChange=function(e){i._controlled||i._resizeComponent(),i.props.onChange(e)},i._resizeComponent=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:y;if(void 0===i._rootDOMNode)return void e();var t=n(i._rootDOMNode,i._uid,i.props.useCacheForDOMMeasurements,i.props.minRows,i.props.maxRows);if(null===t)return void e();var o=t.height,r=t.minHeight,a=t.maxHeight;if(i.rowCount=t.rowCount,i.state.height!==o||i.state.minHeight!==r||i.state.maxHeight!==a)return void i.setState({height:o,minHeight:r,maxHeight:a},e);e()},i.state={height:e.style&&e.style.height||0,minHeight:-1/0,maxHeight:1/0},i._uid=d(),i._controlled="string"==typeof e.value,i}return f(o,t),o.prototype.render=function(){var t=this.props,n=g(t,["minRows","maxRows","onHeightChange","useCacheForDOMMeasurements","inputRef"]);return n.style=c({},n.style,{height:this.state.height}),this.state.height>Math.max(n.style.maxHeight||1/0,this.state.maxHeight)&&(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=v(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(){w(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?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]:[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});

@@ -1,11 +0,229 @@

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; };
import React from 'react';
import PropTypes from 'prop-types';
function _objectWithoutProperties(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 isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var isIE = isBrowser ? !!document.documentElement.currentStyle : false;
var hiddenTextarea = isBrowser && document.createElement('textarea');
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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'
};
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
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 computedStyleCache = {};
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;
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
var nodeStyling = calculateNodeStyling(uiTextNode, uid, useCache);
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
Object.keys(sizingStyle).forEach(function (key) {
hiddenTextarea.style[key] = sizingStyle[key];
});
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) {
hiddenTextarea.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important');
});
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || 'x';
var minHeight = -Infinity;
var maxHeight = Infinity;
var height = hiddenTextarea.scrollHeight;
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
hiddenTextarea.value = 'x';
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize;
if (minRows !== null || maxRows !== null) {
if (minRows !== null) {
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);
}
}
var rowCount = Math.floor(height / singleRowHeight);
return { height: height, minHeight: minHeight, maxHeight: maxHeight, rowCount: rowCount };
}
function calculateNodeStyling(node, uid) {
var useCache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (useCache && computedStyleCache[uid]) {
return computedStyleCache[uid];
}
var style = window.getComputedStyle(node);
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'];
// 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';
}
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 purgeCache = function purgeCache(uid) {
return delete computedStyleCache[uid];
};
function autoInc() {
var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return function () {
return ++seed;
};
}
var uid = autoInc();
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;
};
/**

@@ -15,21 +233,15 @@ * <TextareaAutosize />

import React from 'react';
import PropTypes from 'prop-types';
import calculateNodeHeight, { purgeCache } from './calculateNodeHeight';
import isBrowser from './isBrowser';
import uid from './uid';
var noop = function noop() {};
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [setTimeout, clearTimeout],
onNextFrame = _ref[0],
clearNextFrameAction = _ref[1];
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [setTimeout, clearTimeout];
var onNextFrame = _ref[0];
var clearNextFrameAction = _ref[1];
var TextareaAutosize = function (_React$Component) {
_inherits(TextareaAutosize, _React$Component);
inherits(TextareaAutosize, _React$Component);
function TextareaAutosize(props) {
_classCallCheck(this, TextareaAutosize);
classCallCheck(this, TextareaAutosize);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
var _this = possibleConstructorReturn(this, _React$Component.call(this, props));

@@ -102,4 +314,5 @@ _this._resizeLock = false;

_inputRef = _props.inputRef,
props = _objectWithoutProperties(_props, ['minRows', 'maxRows', 'onHeightChange', 'useCacheForDOMMeasurements', 'inputRef']);
props = objectWithoutProperties(_props, ['minRows', 'maxRows', 'onHeightChange', 'useCacheForDOMMeasurements', 'inputRef']);
props.style = _extends({}, props.style, {

@@ -182,2 +395,3 @@ height: this.state.height

};
export default TextareaAutosize;
export default TextareaAutosize;
'use strict';
exports.__esModule = true;
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
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 React = _interopDefault(require('react'));
var PropTypes = _interopDefault(require('prop-types'));
var _react = require('react');
var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
var _react2 = _interopRequireDefault(_react);
var isIE = isBrowser ? !!document.documentElement.currentStyle : false;
var hiddenTextarea = isBrowser && document.createElement('textarea');
var _propTypes = require('prop-types');
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 _propTypes2 = _interopRequireDefault(_propTypes);
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 _calculateNodeHeight = require('./calculateNodeHeight');
var computedStyleCache = {};
var _calculateNodeHeight2 = _interopRequireDefault(_calculateNodeHeight);
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;
var _isBrowser = require('./isBrowser');
if (hiddenTextarea.parentNode === null) {
document.body.appendChild(hiddenTextarea);
}
var _isBrowser2 = _interopRequireDefault(_isBrowser);
// Copy all CSS properties that have an impact on the height of the content in
// the textbox
var nodeStyling = calculateNodeStyling(uiTextNode, uid, useCache);
var _uid = require('./uid');
if (nodeStyling === null) {
return null;
}
var _uid2 = _interopRequireDefault(_uid);
var paddingSize = nodeStyling.paddingSize,
borderSize = nodeStyling.borderSize,
boxSizing = nodeStyling.boxSizing,
sizingStyle = nodeStyling.sizingStyle;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// 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
function _objectWithoutProperties(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; }
Object.keys(sizingStyle).forEach(function (key) {
hiddenTextarea.style[key] = sizingStyle[key];
});
Object.keys(HIDDEN_TEXTAREA_STYLE).forEach(function (key) {
hiddenTextarea.style.setProperty(key, HIDDEN_TEXTAREA_STYLE[key], 'important');
});
hiddenTextarea.value = uiTextNode.value || uiTextNode.placeholder || 'x';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var minHeight = -Infinity;
var maxHeight = Infinity;
var height = hiddenTextarea.scrollHeight;
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
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;
}
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /**
* <TextareaAutosize />
*/
// measure height of a textarea with a single row
hiddenTextarea.value = 'x';
var singleRowHeight = hiddenTextarea.scrollHeight - paddingSize;
if (minRows !== null || maxRows !== null) {
if (minRows !== null) {
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);
}
}
var rowCount = Math.floor(height / singleRowHeight);
return { height: height, minHeight: minHeight, maxHeight: maxHeight, rowCount: rowCount };
}
function calculateNodeStyling(node, uid) {
var useCache = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (useCache && computedStyleCache[uid]) {
return computedStyleCache[uid];
}
var style = window.getComputedStyle(node);
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'];
// 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';
}
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 purgeCache = function purgeCache(uid) {
return delete computedStyleCache[uid];
};
function autoInc() {
var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return function () {
return ++seed;
};
}
var uid = autoInc();
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() {};
var _ref = _isBrowser2.default && window.requestAnimationFrame ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [setTimeout, clearTimeout],
onNextFrame = _ref[0],
clearNextFrameAction = _ref[1];
var _ref = isBrowser && window.requestAnimationFrame ? [window.requestAnimationFrame, window.cancelAnimationFrame] : [setTimeout, clearTimeout];
var onNextFrame = _ref[0];
var clearNextFrameAction = _ref[1];
var TextareaAutosize = function (_React$Component) {
_inherits(TextareaAutosize, _React$Component);
inherits(TextareaAutosize, _React$Component);
function TextareaAutosize(props) {
_classCallCheck(this, TextareaAutosize);
classCallCheck(this, TextareaAutosize);
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
var _this = possibleConstructorReturn(this, _React$Component.call(this, props));

@@ -78,3 +276,3 @@ _this._resizeLock = false;

var nodeHeight = (0, _calculateNodeHeight2.default)(_this._rootDOMNode, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows);
var nodeHeight = calculateNodeHeight(_this._rootDOMNode, _this._uid, _this.props.useCacheForDOMMeasurements, _this.props.minRows, _this.props.maxRows);

@@ -108,3 +306,3 @@ if (nodeHeight === null) {

_this._uid = (0, _uid2.default)();
_this._uid = uid();
_this._controlled = typeof props.value === 'string';

@@ -121,4 +319,5 @@ return _this;

_inputRef = _props.inputRef,
props = _objectWithoutProperties(_props, ['minRows', 'maxRows', 'onHeightChange', 'useCacheForDOMMeasurements', 'inputRef']);
props = objectWithoutProperties(_props, ['minRows', 'maxRows', 'onHeightChange', 'useCacheForDOMMeasurements', 'inputRef']);
props.style = _extends({}, props.style, {

@@ -134,3 +333,3 @@ height: this.state.height

return _react2.default.createElement('textarea', _extends({}, props, {
return React.createElement('textarea', _extends({}, props, {
onChange: this._onChange,

@@ -178,3 +377,3 @@ ref: this._onRootDOMNode

window.removeEventListener('resize', this._resizeListener);
(0, _calculateNodeHeight.purgeCache)(this._uid);
purgeCache(this._uid);
};

@@ -187,12 +386,12 @@

return TextareaAutosize;
}(_react2.default.Component);
}(React.Component);
TextareaAutosize.propTypes = {
value: _propTypes2.default.string,
onChange: _propTypes2.default.func,
onHeightChange: _propTypes2.default.func,
useCacheForDOMMeasurements: _propTypes2.default.bool,
minRows: _propTypes2.default.number,
maxRows: _propTypes2.default.number,
inputRef: _propTypes2.default.func
value: PropTypes.string,
onChange: PropTypes.func,
onHeightChange: PropTypes.func,
useCacheForDOMMeasurements: PropTypes.bool,
minRows: PropTypes.number,
maxRows: PropTypes.number,
inputRef: PropTypes.func
};

@@ -204,2 +403,3 @@ TextareaAutosize.defaultProps = {

};
exports.default = TextareaAutosize;
module.exports = TextareaAutosize;
{
"name": "react-textarea-autosize",
"description": "textarea component for React which grows with content",
"version": "5.0.7",
"version": "5.1.0",
"keywords": "autosize, grow, react, react-component, textarea",

@@ -13,8 +13,8 @@ "repository": "andreypopp/react-textarea-autosize",

"scripts": {
"build": "npm run build:es && npm run build:cjs && npm run build:umd",
"build:es": "rimraf es && cross-env BABEL_ENV=es babel src --out-dir es --sourceMaps=inline",
"build:cjs": "rimraf lib && cross-env BABEL_ENV=cjs babel src --out-dir lib --sourceMaps=inline",
"build:umd": "rimraf dist && npm run build:umd:prod && npm run build:umd:dev",
"build:umd:prod": "cross-env BABEL_ENV=es NODE_ENV=production rollup -c -i src/index.js -o dist/react-textarea-autosize.min.js",
"build:umd:dev": "cross-env BABEL_ENV=es NODE_ENV=development rollup -c -i src/index.js -o dist/react-textarea-autosize.js",
"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",

@@ -25,4 +25,4 @@ "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",

"prepare": "npm run build",
"precommit": "lint-staged",
"prerelease": "npm run lint && npm run prepare",
"precommit": "lint-staged && run-p build:umd:** && git add dist",
"prerelease": "npm run lint",
"release:patch": "npm run prerelease && npm version patch && git push --follow-tags && npm publish",

@@ -33,3 +33,3 @@ "release:minor": "npm run prerelease && npm version minor && git push --follow-tags && npm publish",

"peerDependencies": {
"react": ">=0.14.0 <16.0.0"
"react": ">=0.14.0 <17.0.0"
},

@@ -42,13 +42,14 @@ "devDependencies": {

"babel-preset-stage-2": "^6.24.1",
"cross-env": "^4.0.0",
"cross-env": "^5.0.1",
"eslint": "^3.3.1",
"eslint-config-prometheusresearch": "^0.2.0",
"eslint-plugin-react": "^6.1.2",
"husky": "^0.13.3",
"lint-staged": "^3.4.2",
"prettier": "^1.4.1",
"react": "^15.3.1",
"react-dom": "^15.3.1",
"husky": "^0.14.3",
"lint-staged": "^4.0.2",
"npm-run-all": "^4.0.2",
"prettier": "^1.5.3",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"rimraf": "^2.6.1",
"rollup": "^0.36.3",
"rollup": "^0.45.2",
"rollup-plugin-babel": "^2.7.1",

@@ -58,3 +59,3 @@ "rollup-plugin-commonjs": "^8.0.2",

"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.2"
"rollup-plugin-uglify": "^2.0.1"
},

@@ -67,4 +68,4 @@ "files": [

"dependencies": {
"prop-types": "^15.5.8"
"prop-types": "^15.5.10"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc