UNPKG

@tarojs/components

Version:
1 lines 5.09 kB
var __awaiter=this&&this.__awaiter||function(e,t,n,i){function o(e){return e instanceof n?e:new n((function(t){t(e)}))}return new(n||(n=Promise))((function(n,a){function r(e){try{l(i.next(e))}catch(e){a(e)}}function u(e){try{l(i["throw"](e))}catch(e){a(e)}}function l(e){e.done?n(e.value):o(e.value).then(r,u)}l((i=i.apply(e,t||[])).next())}))};var __generator=this&&this.__generator||function(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,o,a,r;return r={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function u(e){return function(t){return l([e,t])}}function l(u){if(i)throw new TypeError("Generator is already executing.");while(r&&(r=0,u[0]&&(n=0)),n)try{if(i=1,o&&(a=u[0]&2?o["return"]:u[0]?o["throw"]||((a=o["return"])&&a.call(o),0):o.next)&&!(a=a.call(o,u[1])).done)return a;if(o=0,a)u=[u[0]&2,a.value];switch(u[0]){case 0:case 1:a=u;break;case 4:n.label++;return{value:u[1],done:false};case 5:n.label++;o=u[1];u=[0];continue;case 7:u=n.ops.pop();n.trys.pop();continue;default:if(!(a=n.trys,a=a.length>0&&a[a.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!a||u[1]>a[0]&&u[1]<a[3])){n.label=u[1];break}if(u[0]===6&&n.label<a[1]){n.label=a[1];a=u;break}if(a&&n.label<a[2]){n.label=a[2];n.ops.push(u);break}if(a[2])n.ops.pop();n.trys.pop();continue}u=t.call(e,n)}catch(e){u=[6,e];o=0}finally{i=a=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}};System.register(["./p-2b70c348.system.js"],(function(e){"use strict";var t,n,i,o;return{setters:[function(e){t=e.r;n=e.c;i=e.h;o=e.g}],execute:function(){var a="taro-textarea-core{width:300px;display:block}taro-textarea-core .auto-height{height:auto}.taro-textarea{height:inherit;-webkit-appearance:none;-moz-appearance:none;appearance:none;cursor:auto;border:0;width:100%;line-height:1.5;display:block;position:relative}.taro-textarea:focus{outline:none}";function r(e){return e!==null&&e!==void 0?e:""}var u=e("taro_textarea_core",function(){function e(e){var i=this;t(this,e);this.onInput=n(this,"input",7);this.onFocus=n(this,"focus",7);this.onBlur=n(this,"blur",7);this.onConfirm=n(this,"confirm",7);this.onChange=n(this,"change",7);this.onLineChange=n(this,"linechange",7);this.onKeyDown=n(this,"keydown",7);this.handleInput=function(e){e.stopPropagation();i.handleLineChange();var t=e.target.value||"";i.value=t;i.onInput.emit({value:t,cursor:t.length})};this.handleFocus=function(e){e.stopPropagation();i.onFocus.emit({value:e.target.value})};this.handleBlur=function(e){e.stopPropagation();i.onBlur.emit({value:e.target.value})};this.handleChange=function(e){e.stopPropagation();i.onChange.emit({value:e.target.value})};this.handleLineChange=function(){var e=i.getNumberOfLines();if(e!==i.line){i.line=e;i.onLineChange.emit({height:i.textareaRef.clientHeight,lineCount:i.line})}};this.handleKeyDown=function(e){e.stopPropagation();var t=e.target.value;var n=e.keyCode||e.code;i.onKeyDown.emit({value:t,cursor:t.length,keyCode:n});n===13&&i.onConfirm.emit({value:t})};this.calculateContentHeight=function(e,t){var n=e.style.height,i=e.offsetHeight,o=e.scrollHeight,a=e.style.overflow,r=e.style.minHeight||null;if(i>=o){e.style.minHeight=0;e.style.height=i+t+"px";e.style.overflow="hidden";if(o<e.scrollHeight){while(e.offsetHeight>=e.scrollHeight){e.style.height=(i-=t)+"px"}while(e.offsetHeight<e.scrollHeight){e.style.height=i+++"px"}e.style.height=n;e.style.overflow=a;e.style.minHeight=r;return i}}else{return o}};this.getNumberOfLines=function(){var e=i.textareaRef,t=window.getComputedStyle?window.getComputedStyle(e):e.style,n=parseInt(t.lineHeight,10),o=i.calculateContentHeight(e,n),a=Math.floor(o/n);return a};this.value="";this.placeholder=undefined;this.disabled=false;this.maxlength=140;this.autoFocus=false;this.autoHeight=false;this.name=undefined;this.nativeProps={};this.line=1}e.prototype.watchAutoFocus=function(e,t){var n;if(!t&&e){(n=this.textareaRef)===null||n===void 0?void 0:n.focus()}};e.prototype.watchValue=function(e){var t=r(e);if(this.textareaRef.value!==t){this.textareaRef.value=t}};e.prototype.focus=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(e){this.textareaRef.focus();return[2]}))}))};e.prototype.render=function(){var e=this;var t=this,n=t.value,o=t.placeholder,a=t.disabled,u=t.maxlength,l=t.autoFocus,h=t.autoHeight,s=t.name,c=t.nativeProps,f=t.handleInput,g=t.handleFocus,p=t.handleBlur,d=t.handleChange;var v={};if(h){v.rows=this.line}return i("textarea",Object.assign({ref:function(t){if(t){e.textareaRef=t;if(l&&t)t.focus()}},class:"taro-textarea ".concat(h?"auto-height":""),value:r(n),placeholder:o,name:s,disabled:a,maxlength:u,autofocus:l,onInput:f,onFocus:g,onBlur:p,onChange:d,onKeyDown:this.handleKeyDown},c,v))};Object.defineProperty(e.prototype,"el",{get:function(){return o(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{autoFocus:["watchAutoFocus"],value:["watchValue"]}},enumerable:false,configurable:true});return e}());u.style=a}}}));