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IAAsB,CAA1B,EAA6B;AAC7B,oCAAgB,SAAS,KAAT,CAAhB,KAAoC,KAAK,aAAL,EAApC;AACA;AACD;AACF;AAED,iBAAK,gBAAL,CAAsB,SAAtB;AACA;AACA,iBAAK,KAAL,CAAW,OAAX,EAAoB,KAAK,iBAAL,GAAyB,KAAK,KAAL,CAAW,KAAX,CAAiB,KAA1C,GAAkD,KAAK,SAA3E;AACD,SA1BM;AA2BP,gBA3BO,oBA2BG,IA3BH,EA2BO;AACZ,mBAAO,KAAK,IAAL,GAAY,UAAS,IAAT,EAAe,KAAK,MAApB,EAA4B,KAAK,kBAAjC,CAAZ,GAAmE,IAA1E;AACD,SA7BM;AA8BP,kBA9BO,sBA8BK,IA9BL,EA8BS;AACd,mBAAO,KAAK,IAAL,IAAa,CAAC,KAAK,iBAAnB,GAAuC,YAAW,IAAX,CAAvC,GAA0D,IAAjE;AACD,SAhCM;;AAiCP;AACA;AACA;AACA,yBApCO,+BAoCU;AACf,iBAAK,SAAL,CAAe,KAAK,WAApB;AACD,SAtCM;AAuCP,uBAvCO,2BAuCU,KAvCV,EAuCe;AACpB,gBAAI,CAAC,MAAM,YAAX,EAAyB;AACzB,iBAAK,SAAL,GAAiB,MAAM,YAAvB;AACA,iBAAK,aAAL,GAAqB,CAArB;AAEA,iBAAK,IAAI,QAAQ,CAAjB,EAAoB,QAAQ,KAAK,SAAjC,EAA4C,OAA5C,EAAqD;AACnD,gCAAgB,MAAM,KAAN,CAAY,KAAZ,CAAhB,KAAuC,KAAK,aAAL,EAAvC;AACD;AACF;AA/CM;AArFI,CAAf","sourcesContent":["/**\n * Maskable\n *\n * @mixin\n *\n * Creates an input mask that is\n * generated from a masked str\n *\n * Example: mask=\"#### #### #### ####\"\n */\n\nimport {\n isMaskDelimiter,\n maskText,\n unmaskText\n} from '../util/mask'\n\n/* @vue/component */\nexport default {\n name: 'maskable',\n\n props: {\n dontFillMaskBlanks: Boolean,\n mask: {\n type: [Object, String],\n default: null\n },\n returnMaskedValue: Boolean,\n value: { required: false }\n },\n\n data: vm => ({\n selection: 0,\n lazySelection: 0,\n lazyValue: vm.value,\n preDefined: {\n 'credit-card': '#### - #### - #### - ####',\n 'date': '##/##/####',\n 'date-with-time': '##/##/#### ##:##',\n 'phone': '(###) ### - ####',\n 'social': '###-##-####',\n 'time': '##:##',\n 'time-with-seconds': '##:##:##'\n }\n }),\n\n computed: {\n masked () {\n const preDefined = this.preDefined[this.mask]\n const mask = preDefined || this.mask || ''\n\n return mask.split('')\n }\n },\n\n watch: {\n /**\n * Make sure the cursor is in the correct\n * location when the mask changes\n */\n mask () {\n if (!this.$refs.input) return\n\n const oldValue = this.$refs.input.value\n const newValue = this.maskText(unmaskText(this.lazyValue))\n let position = 0\n let selection = this.selection\n\n for (let index = 0; index < selection; index++) {\n isMaskDelimiter(oldValue[index]) || position++\n }\n\n selection = 0\n if (newValue) {\n for (let index = 0; index < newValue.length; index++) {\n isMaskDelimiter(newValue[index]) || position--\n selection++\n if (position <= 0) break\n }\n }\n\n this.$nextTick(() => {\n this.$refs.input.value = newValue\n this.setCaretPosition(selection)\n })\n }\n },\n\n beforeMount () {\n if (!this.mask ||\n this.value == null ||\n !this.returnMaskedValue\n ) return\n\n const value = this.maskText(this.value)\n\n // See if masked value does not\n // match the user given value\n if (value === this.value) return\n\n this.$emit('input', value)\n },\n\n methods: {\n setCaretPosition (selection) {\n this.selection = selection\n window.setTimeout(() => {\n this.$refs.input && this.$refs.input.setSelectionRange(this.selection, this.selection)\n }, 0)\n },\n updateRange () {\n /* istanbul ignore next */\n if (!this.$refs.input) return\n\n const newValue = this.maskText(this.lazyValue)\n let selection = 0\n\n this.$refs.input.value = newValue\n if (newValue) {\n for (let index = 0; index < newValue.length; index++) {\n if (this.lazySelection <= 0) break\n isMaskDelimiter(newValue[index]) || this.lazySelection--\n selection++\n }\n }\n\n this.setCaretPosition(selection)\n // this.$emit() must occur only when all internal values are correct\n this.$emit('input', this.returnMaskedValue ? this.$refs.input.value : this.lazyValue)\n },\n maskText (text) {\n return this.mask ? maskText(text, this.masked, this.dontFillMaskBlanks) : text\n },\n unmaskText (text) {\n return this.mask && !this.returnMaskedValue ? unmaskText(text) : text\n },\n // When the input changes and is\n // re-created, ensure that the\n // caret location is correct\n setSelectionRange () {\n this.$nextTick(this.updateRange)\n },\n resetSelections (input) {\n if (!input.selectionEnd) return\n this.selection = input.selectionEnd\n this.lazySelection = 0\n\n for (let index = 0; index < this.selection; index++) {\n isMaskDelimiter(input.value[index]) || this.lazySelection++\n }\n }\n }\n}\n"],"sourceRoot":""}
|