UNPKG

front-ui-product

Version:

Front UI

2 lines 6.46 kB
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["front-ui-product"]=t():e["front-ui-product"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var s=t[i]={i:i,l:!1,exports:{}};return e[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(i,s,function(t){return e[t]}.bind(null,s));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s="fb15")}({b0bc:function(e,t,n){},e524:function(e,t,n){"use strict";n("b0bc")},fb15:function(e,t,n){"use strict";if(n.r(t),n.d(t,"PMobileInput",(function(){return c})),"undefined"!==typeof window){var i=window.document.currentScript,s=i&&i.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);s&&(n.p=s[1])}var r=function(){var e=this,t=e._self._c;return t("div",{staticClass:"p-mobile-input"},[t("div",{staticClass:"content",style:e.classStyle},[e.$slots.label?t("div",{style:e.labelStyle},[e._t("label")],2):e._e(),t("div",{key:e.inputKey,staticClass:"input-wrp",class:{error:e.hasErrors,showBorders:e.showBorder},style:e.containerStyle},[t("input",{directives:[{name:"model",rawName:"v-model",value:e.inputValue,expression:"inputValue"}],key:e.inputKey,ref:"newInput",staticClass:"p-input",staticStyle:{padding:"0 !important",border:"none !important",outline:"none !important","-webkit-appearance":"none !important","-moz-appearance":"none !important",appearance:"none !important"},style:e.inputStyle,attrs:{maxlength:e.formatMaxlength,placeholder:e.placeholder},domProps:{value:e.inputValue},on:{input:[function(t){t.target.composing||(e.inputValue=t.target.value)},e.inputHandler],focus:function(t){e.hasErrors=!1},blur:e.handleBlur,compositionstart:function(t){e.isComposing=!0},compositionend:e.onCompositionEnd}}),e.$slots.prefix?t("div",{style:e.prefixStyle},[e._t("prefix")],2):e._e()])]),e.hasErrors?t("div",{style:e.warningStyle},[e._t("error")],2):e._e()])},o=[],l={name:"p-mobile-input",data(){return{inputValue:"",selectionStart:-1,selectionEnd:-1,oldValue:"",type:null,hasErrors:!1,inputKey:"inputKey",isComposing:!1}},watch:{defaultValue:{handler(e){this.inputValue||e&&(this.inputValue=e,this.$nextTick(()=>{this.inputHandler(null,!0)}))},immediate:!0},inputValue:{handler(e){this.$emit("input",e.replace(/^\+1\s*/,"").replace(/\D/g,""))},immediate:!0}},props:{maxlength:{type:Number,default:10},classStyle:{type:Object,default:()=>{}},placeholder:{type:String,default:""},labelStyle:{type:Object,default:()=>{}},prefixStyle:{type:Object,default:()=>{}},defaultValue:{type:String,default:""},warningStyle:{type:Object,default:()=>{}},containerStyle:{type:Object,default:()=>{}},showBorder:{type:Boolean,default:!1},inputStyle:{type:Object,default:()=>{}}},computed:{formatMaxlength(){return this.maxlength+7}},methods:{formatInput(e){let t="";if(e>0){let n="";if(n=e.length<=3?"("+e:e.length<=6?`(${e.slice(0,3)}) ${e.slice(3)}`:`(${e.slice(0,3)}) ${e.slice(3,6)}-${e.slice(6,10)}`,e.startsWith("+1")){const e="+1 ";t=e+n}else t="+1 "+n}else t="";return t},onCompositionEnd(e){this.isComposing=!1,this.inputHandler(e)},inputHandler(e,t){if(this.isComposing)return;let n=t?this.defaultValue:this.inputValue.replace(/^\+1\s*/,"").replace(/\D/g,"");if(!n.length)return this.$refs.newInput.value="",this.inputValue="",this.oldValue="",void this.$emit("input","");const i=this.oldValue.replace(/^\+1\s*/,"").replace(/\D/g,"");this.type=i==n?"char":i&&n&&i.length-n.length==1?"delete":"add",this.oldValue=this.inputValue,this.selectionStart=this.$refs.newInput.selectionStart,this.selectionEnd=this.$refs.newInput.selectionEnd,console.log("type",this.type,this.inputValue,i,n),this.$nextTick(()=>{if("delete"==this.type){let e=this.formatInput(n);this.$refs.newInput.value=e,this.$refs.newInput.setSelectionRange(this.selectionStart,this.selectionEnd)}else if("add"==this.type){let e=this.formatInput(n);this.$refs.newInput.value=e;const t={1:5,4:10,7:15},i={1:1,2:6,3:7,4:8,5:11,6:12,7:13,8:15,9:16,10:17},s=()=>i[n.length]==this.selectionStart&&[1,4,7].includes(n.length)?t[n.length]:this.selectionStart;this.$refs.newInput.setSelectionRange(s(),s())}else{const e={7:()=>{const e=this.formatInput(n.slice(0,2)+n.slice(3));this.$refs.newInput.value=e,this.$refs.newInput.setSelectionRange(7,7)},8:()=>{const e=this.formatInput(n.slice(0,2)+n.slice(3));this.$refs.newInput.value=e,this.$refs.newInput.setSelectionRange(7,7)},12:()=>{const e=this.formatInput(n.slice(0,5)+n.slice(6));this.$refs.newInput.value=e,this.$refs.newInput.setSelectionRange(12,12)}};if([7,8,12].includes(this.selectionStart))e[this.selectionStart]();else{let e=this.formatInput(n);this.$refs.newInput.value=e}}})},handleBlur(){const e=this.inputValue.replace(/^\+1\s*/,"").replace(/\D/g,"");console.log("blur"),this.hasErrors=0==e.length}}},a=l;n("e524");function u(e,t,n,i,s,r,o,l){var a,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=n,u._compiled=!0),i&&(u.functional=!0),r&&(u._scopeId="data-v-"+r),o?(a=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),s&&s.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(o)},u._ssrRegister=a):s&&(a=l?function(){s.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:s),a)if(u.functional){u._injectStyles=a;var p=u.render;u.render=function(e,t){return a.call(t),p(e,t)}}else{var c=u.beforeCreate;u.beforeCreate=c?[].concat(c,a):[a]}return{exports:e,options:u}}var p=u(a,r,o,!1,null,"1ba2d048",null),c=p.exports;const f=[c],d=function(e){f.forEach(t=>{e.component(t.name,t)})};var h=d;t["default"]=h}})})); //# sourceMappingURL=front-ui-product.umd.min.js.map