diff --git a/Makefile b/Makefile deleted file mode 100644 index 018f4677..00000000 --- a/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -BIN = node_modules/.bin -SRC = $(wildcard src/*.js) -LIB = $(SRC:src/%=lib/%) -ES = $(SRC:src/%=es/%) -TESTS = $(wildcard src/__tests__/*-test.js) - -BABEL_OPTS = \ - --sourceMaps=inline - -build: $(LIB) $(ES) build-min - -test:: - @echo No tests... - -lint:: - @$(BIN)/eslint $(SRC) - -clean: - @rm -rf $(LIB) $(ES) - -sloc: - @$(BIN)/sloc ./src - -release-patch: lint test build - @$(call release,patch) - -release-minor: lint test build - @$(call release,minor) - -release-major: lint test build - @$(call release,major) - -release = npm version $(1) - -publish: build - @git push --tags origin HEAD:master - @npm publish - -build-min: $(LIB) - @echo "building dist/TextareaAutosize.min.js" - @$(BIN)/cross-env BABEL_ENV=es NODE_ENV=production $(BIN)/rollup -c - -lib/%.js: src/%.js - @echo "building cjs $@" - @mkdir -p $(@D) - @$(BIN)/cross-env BABEL_ENV=cjs $(BIN)/babel $(BABEL_OPTS) -o $@ $< - -es/%.js: src/%.js - @echo "building es $@" - @mkdir -p $(@D) - @$(BIN)/cross-env BABEL_ENV=es $(BIN)/babel $(BABEL_OPTS) -o $@ $< diff --git a/dist/TextareaAutosize.min.js b/dist/react-textarea-autosize.js similarity index 100% rename from dist/TextareaAutosize.min.js rename to dist/react-textarea-autosize.js diff --git a/dist/react-textarea-autosize.min.js b/dist/react-textarea-autosize.min.js new file mode 100644 index 00000000..11f9c405 --- /dev/null +++ b/dist/react-textarea-autosize.min.js @@ -0,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 o(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null;p?null===p.parentNode&&document.body.appendChild(p):(p=document.createElement("textarea"),document.body.appendChild(p));var r=n(e,t),u=r.paddingSize,s=r.borderSize,l=r.boxSizing,h=r.sizingStyle;Object.keys(h).map(function(e){p.style[e]=h[e]}),Object.keys(a).map(function(e){p.style.setProperty(e,a[e],"important")}),p.value=e.value||e.placeholder||"x";var c=-1/0,d=1/0,f=p.scrollHeight;if("border-box"===l?f+=s:"content-box"===l&&(f-=u),null!==o||null!==i){p.value="x";var g=p.scrollHeight-u;null!==o&&(c=g*o,"border-box"===l&&(c=c+u+s),f=Math.max(c,f)),null!==i&&(d=g*i,"border-box"===l&&(d=d+u+s),f=Math.min(d,f))}return{height:f,minHeight:c,maxHeight:d}}function n(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=e.getAttribute("id")||e.getAttribute("data-reactid")||e.getAttribute("name");if(t&&s[o])return s[o];var n=window.getComputedStyle(e),i=n.getPropertyValue("box-sizing")||n.getPropertyValue("-moz-box-sizing")||n.getPropertyValue("-webkit-box-sizing"),r=parseFloat(n.getPropertyValue("padding-bottom"))+parseFloat(n.getPropertyValue("padding-top")),a=parseFloat(n.getPropertyValue("border-bottom-width"))+parseFloat(n.getPropertyValue("border-top-width")),p=u.reduce(function(e,t){return e[t]=n.getPropertyValue(t),e},{}),l={sizingStyle:p,paddingSize:r,borderSize:a,boxSizing:i};return t&&o&&(s[o]=l),l}function i(e){return window.requestAnimationFrame?window.requestAnimationFrame(e):window.setTimeout(e,1)}function r(e){window.cancelAnimationFrame?window.cancelAnimationFrame(e):window.clearTimeout(e)}e="default"in e?e.default:e,t="default"in t?t.default:t;var a={"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","padding-top","padding-bottom","font-family","font-weight","font-size","text-rendering","text-transform","width","text-indent","padding-left","padding-right","border-width","box-sizing"],s={},p=void 0,l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},h=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},c=function(){function e(e,t){for(var o=0;t.length>o;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),d=Object.assign||function(e){for(var t=1;arguments.length>t;t++){var o=arguments[t];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(e[n]=o[n])}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 o={};for(var n in e)0>t.indexOf(n)&&Object.prototype.hasOwnProperty.call(e,n)&&(o[n]=e[n]);return o},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=function(t){function n(e){h(this,n);var i=m(this,t.call(this,e));return i._onRootDOMNode=function(e){i._rootDOMNode=e,i.props.inputRef&&i.props.inputRef(e)},i._onChange=function(e){i._controlled||i._resizeComponent();var t=i.props,o=t.valueLink,n=t.onChange;o?o.requestChange(e.target.value):n(e)},i._resizeComponent=function(){if(i._rootDOMNode){var e=o(i._rootDOMNode,i.props.useCacheForDOMMeasurements,i.props.rows||i.props.minRows,i.props.maxRows),t=e.height,n=e.minHeight,r=e.maxHeight;i.state.height===t&&i.state.minHeight===n&&i.state.maxHeight===r||i.setState({height:t,minHeight:n,maxHeight:r})}},i.state={height:e.style&&e.style.height||0,minHeight:-1/0,maxHeight:1/0},i._controlled="string"==typeof e.value,i}return f(n,t),n.prototype.render=function(){var t=this.props,o=t.valueLink,n=g(t,["valueLink","minRows","maxRows","onHeightChange","useCacheForDOMMeasurements","inputRef"]);return"object"===(void 0===o?"undefined":l(o))&&(n.value=o.value),n.style=d({},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",d({},n,{onChange:this._onChange,ref:this._onRootDOMNode}))},n.prototype.componentDidMount=function(){this._resizeComponent(),window.addEventListener("resize",this._resizeComponent)},n.prototype.componentWillReceiveProps=function(){this._clearNextFrame(),this._onNextFrameActionId=i(this._resizeComponent)},n.prototype.componentDidUpdate=function(e,t){this.state.height!==t.height&&this.props.onHeightChange(this.state.height)},n.prototype.componentWillUnmount=function(){this._clearNextFrame(),window.removeEventListener("resize",this._resizeComponent)},n.prototype._clearNextFrame=function(){this._onNextFrameActionId&&r(this._onNextFrameActionId)},n.prototype.focus=function(){this._rootDOMNode.focus()},n.prototype.blur=function(){this._rootDOMNode.blur()},c(n,[{key:"value",get:function(){return this._rootDOMNode.value},set:function(e){this._rootDOMNode.value=e}},{key:"selectionStart",get:function(){return this._rootDOMNode.selectionStart},set:function(e){this._rootDOMNode.selectionStart=e}},{key:"selectionEnd",get:function(){return this._rootDOMNode.selectionEnd},set:function(e){this._rootDOMNode.selectionEnd=e}}]),n}(e.Component);return b.propTypes={value:t.string,onChange:t.func,onHeightChange:t.func,useCacheForDOMMeasurements:t.bool,rows:t.number,minRows:t.number,maxRows:t.number,inputRef:t.func},b.defaultProps={onChange:y,onHeightChange:y,useCacheForDOMMeasurements:!1},b}); diff --git a/package.json b/package.json index 2f165904..46e820c3 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,23 @@ "keywords": "autosize, grow, react, react-component, textarea", "repository": "andreypopp/react-textarea-autosize", "license": "MIT", - "main": "lib/TextareaAutosize.js", - "module": "es/TextareaAutosize.js", - "jsnext:main": "es/TextareaAutosize.js", + "main": "lib/index.js", + "module": "es/index.js", + "jsnext:main": "es/index.js", "author": "Andrey Popp <8mayday@gmail.com> (https://andreypopp.com/)", "scripts": { - "prepublish": "make clean build || true" + "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", + "clean": "rimraf es && rimraf lib && rimraf dist", + "lint": "eslint src", + "prerelease": "npm run lint && npm run build", + "release:patch": "npm run prerelease && npm version patch && git push --follow-tags && npm publish", + "release:minor": "npm run prerelease && npm version minor && git push --follow-tags && npm publish", + "release:major": "npm run prerelease && npm version major && git push --follow-tags && npm publish" }, "peerDependencies": { "react": ">=0.14.0 <16.0.0" @@ -27,8 +38,12 @@ "eslint-plugin-react": "^6.1.2", "react": "^15.3.1", "react-dom": "^15.3.1", + "rimraf": "^2.6.1", "rollup": "^0.36.3", "rollup-plugin-babel": "^2.7.1", + "rollup-plugin-node-resolve": "^3.0.0", + "rollup-plugin-replace": "^1.1.1", + "rollup-plugin-uglify": "^1.0.2", "watchify": "^3.7.0" }, "files": [ diff --git a/rollup.config.js b/rollup.config.js index 7d4056fd..c842973d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,15 +1,24 @@ +import nodeResolve from 'rollup-plugin-node-resolve'; import babel from 'rollup-plugin-babel'; +import replace from 'rollup-plugin-replace'; +import uglify from 'rollup-plugin-uglify'; -export default { - entry: 'src/TextareaAutosize.js', - dest: 'dist/TextareaAutosize.min.js', +const env = process.env.NODE_ENV; + +const config = { format: 'umd', moduleName: 'TextareaAutosize', plugins: [ + nodeResolve({ + jsnext: true + }), babel({ exclude: 'node_modules/**', plugins: ['external-helpers'], }), + replace({ + 'process.env.NODE_ENV': JSON.stringify(env) + }) ], external: [ 'react', 'prop-types' @@ -19,3 +28,25 @@ export default { 'prop-types': 'PropTypes' }, }; + +if (env === 'production') { + config.plugins.push( + uglify({ + compress: { + pure_getters: true, + unsafe: true, + unsafe_comps: true, + warnings: false, + screw_ie8: true + }, + mangle: { + screw_ie8: true + }, + output: { + screw_ie8: true + } + }) + ); +} + +export default config; diff --git a/src/TextareaAutosize.js b/src/index.js similarity index 100% rename from src/TextareaAutosize.js rename to src/index.js