UNPKG

@tarojs/components

Version:
1 lines 6.98 kB
var __awaiter=this&&this.__awaiter||function(t,e,n,i){function o(t){return t instanceof n?t:new n((function(e){e(t)}))}return new(n||(n=Promise))((function(n,a){function r(t){try{s(i.next(t))}catch(t){a(t)}}function u(t){try{s(i["throw"](t))}catch(t){a(t)}}function s(t){t.done?n(t.value):o(t.value).then(r,u)}s((i=i.apply(t,e||[])).next())}))};var __generator=this&&this.__generator||function(t,e){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(t){return function(e){return s([t,e])}}function s(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=e.call(t,n)}catch(t){u=[6,t];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(t){"use strict";var e,n,i,o;return{setters:[function(t){e=t.r;n=t.c;i=t.h;o=t.g}],execute:function(){var a=".weui-input{-webkit-appearance:none;font-size:inherit;color:inherit;background-color:transparent;border:0;outline:0;width:100%;height:1.47059em;line-height:1.47059}.weui-input::-webkit-outer-spin-button,.weui-input::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}taro-input-core{display:block}input{text-overflow:clip;text-align:inherit;white-space:nowrap;height:1.4rem;display:block;overflow:hidden}";function r(t,e,n){if(e==="search")t="search";if(n)t="password";if(typeof t==="undefined"){return"text"}if(!t){throw new Error("unexpected type")}if(t==="digit")t="number";return t}function u(t){return t!==null&&t!==void 0?t:""}var s=t("taro_input_core",function(){function t(t){var i=this;e(this,t);this.onInput=n(this,"input",7);this.onPaste=n(this,"paste",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.onKeyDown=n(this,"keydown",7);this.isOnComposition=false;this.isOnPaste=false;this.onInputExcuted=false;this.handleInput=function(t){t.stopPropagation();var e=i,n=e.type,o=e.maxlength,a=e.confirmType,u=e.password;if(!i.isOnComposition&&!i.onInputExcuted){var s=t.target.value;var l=r(n,a,u);i.onInputExcuted=true;if(l==="number"&&s&&o>-1&&o<=s.length){s=s.substring(0,o);t.target.value=s}i.value=s;i.onInput.emit({value:s,cursor:s.length});i.onInputExcuted=false}};this.handlePaste=function(t){t.stopPropagation();i.isOnPaste=true;i.onPaste.emit({value:t.target.value})};this.handleFocus=function(t){t.stopPropagation();i.onInputExcuted=false;i.onFocus.emit({value:t.target.value})};this.handleBlur=function(t){t.stopPropagation();i.onBlur.emit({value:t.target.value})};this.handleChange=function(t){t.stopPropagation();i.onChange.emit({value:t.target.value});if(i.isOnPaste){i.isOnPaste=false;i.value=t.target.value;i.onInput.emit({value:t.target.value,cursor:t.target.value.length})}};this.handleKeyDown=function(t){t.stopPropagation();var e=t.target.value;var n=t.keyCode||t.code;i.onInputExcuted=false;i.onKeyDown.emit({value:e,cursor:e.length,keyCode:n});n===13&&i.onConfirm.emit({value:e})};this.handleComposition=function(t){t.stopPropagation();if(!(t.target instanceof HTMLInputElement))return;if(t.type==="compositionend"){i.isOnComposition=false;i.value=t.target.value;i.onInput.emit({value:t.target.value,cursor:t.target.value.length})}else{i.isOnComposition=true}};this.handleBeforeInput=function(t){if(!t.data)return;var e=t.data&&/[0-9]/.test(t.data);if(i.type==="number"&&!e){t.preventDefault()}if(i.type==="digit"&&!e){if(t.data!=="."||t.data==="."&&t.target.value.indexOf(".")>-1){t.preventDefault()}}};this.value="";this.type=undefined;this.password=false;this.placeholder=undefined;this.disabled=false;this.maxlength=140;this.autoFocus=false;this.confirmType="done";this.name=undefined;this.nativeProps={}}t.prototype.focus=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){this.inputRef.focus();return[2]}))}))};t.prototype.watchAutoFocus=function(t,e){var n;if(!e&&t){(n=this.inputRef)===null||n===void 0?void 0:n.focus()}};t.prototype.watchValue=function(t){var e=u(t);if(this.inputRef.value!==e){this.inputRef.value=e}};t.prototype.componentDidLoad=function(){var t=this;var e,n,i,o,a;if(this.type==="file"){this.fileListener=function(){t.onInput.emit()};(e=this.inputRef)===null||e===void 0?void 0:e.addEventListener("change",this.fileListener)}else{(n=this.inputRef)===null||n===void 0?void 0:n.addEventListener("compositionstart",this.handleComposition);(i=this.inputRef)===null||i===void 0?void 0:i.addEventListener("compositionend",this.handleComposition);(o=this.inputRef)===null||o===void 0?void 0:o.addEventListener("beforeinput",this.handleBeforeInput);(a=this.inputRef)===null||a===void 0?void 0:a.addEventListener("textInput",this.handleBeforeInput)}};t.prototype.disconnectedCallback=function(){var t,e,n,i,o;if(this.type==="file"){(t=this.inputRef)===null||t===void 0?void 0:t.removeEventListener("change",this.fileListener)}else{(e=this.inputRef)===null||e===void 0?void 0:e.removeEventListener("compositionstart",this.handleComposition);(n=this.inputRef)===null||n===void 0?void 0:n.removeEventListener("compositionend",this.handleComposition);(i=this.inputRef)===null||i===void 0?void 0:i.removeEventListener("beforeinput",this.handleBeforeInput);(o=this.inputRef)===null||o===void 0?void 0:o.removeEventListener("textInput",this.handleBeforeInput)}};t.prototype.render=function(){var t=this;var e=this,n=e.value,o=e.type,a=e.password,s=e.placeholder,l=e.autoFocus,h=e.disabled,p=e.maxlength,f=e.confirmType,c=e.name,d=e.nativeProps;return i("input",Object.assign({ref:function(e){t.inputRef=e;if(l&&e)e.focus()},class:"weui-input",type:r(o,f,a),placeholder:s,autoFocus:l,disabled:h,maxlength:p,name:c,onInput:this.handleInput,onFocus:this.handleFocus,onBlur:this.handleBlur,onChange:this.handleChange,onKeyDown:this.handleKeyDown,onPaste:this.handlePaste,onCompositionStart:this.handleComposition,onCompositionEnd:this.handleComposition},d,{value:u(n)}))};Object.defineProperty(t.prototype,"el",{get:function(){return o(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{autoFocus:["watchAutoFocus"],value:["watchValue"]}},enumerable:false,configurable:true});return t}());s.style=a}}}));