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IAAI,QAAQ,CAAjB,EAAoB,QAAQ,KAAK,KAAL,CAAW,MAAvC,EAA+C,OAA/C,EAAwD;AACtD,oBAAM,OAAO,KAAK,KAAL,CAAW,KAAX,CAAb;AACA,oBAAM,QAAQ,OAAO,IAAP,KAAgB,UAAhB,GAA6B,KAAK,KAAL,CAA7B,GAA2C,IAAzD;AAEA,oBAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AAC7B,gCAAY,IAAZ,CAAiB,KAAjB;AACD,iBAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,SAArB,EAAgC;AACrC,gHAA0E,KAA1E,yCAA0E,KAA1E,mBAA4F,IAA5F;AACD;AACF;AAED,iBAAK,WAAL,GAAmB,WAAnB;AACA,iBAAK,KAAL,GAAa,YAAY,MAAZ,KAAuB,CAApC;AAEA,mBAAO,KAAK,KAAZ;AACD;AAvCM;AAlLF,CAHM,C","sourcesContent":["// Mixins\nimport Colorable from './colorable'\nimport { inject as RegistrableInject } from './registrable'\n\n// Utilities\nimport { deepEqual } from '../util/helpers'\nimport { consoleError } from '../util/console'\nimport mixins from '../util/mixins'\n\n// Types\nimport { PropValidator } from 'vue/types/options'\nexport type VuetifyRuleValidator = (value: any) => string | false\nexport type VuetifyMessage = string | string[]\nexport type VuetifyRuleValidations = (VuetifyRuleValidator | string)[]\n\n/* @vue/component */\nexport default mixins(\n Colorable,\n RegistrableInject('form')\n).extend({\n name: 'validatable',\n\n props: {\n disabled: Boolean,\n error: Boolean,\n errorCount: {\n type: [Number, String],\n default: 1\n },\n errorMessages: {\n type: [String, Array],\n default: () => []\n } as PropValidator,\n messages: {\n type: [String, Array],\n default: () => []\n } as PropValidator,\n readonly: Boolean,\n rules: {\n type: Array,\n default: () => []\n } as PropValidator,\n success: Boolean,\n successMessages: {\n type: [String, Array],\n default: () => []\n } as PropValidator,\n validateOnBlur: Boolean,\n value: { required: false }\n },\n\n data () {\n return {\n errorBucket: [] as string[],\n hasColor: false,\n hasFocused: false,\n hasInput: false,\n isFocused: false,\n isResetting: false,\n lazyValue: this.value,\n valid: false\n }\n },\n\n computed: {\n hasError (): boolean {\n return (\n this.internalErrorMessages.length > 0 ||\n this.errorBucket.length > 0 ||\n this.error\n )\n },\n // TODO: Add logic that allows the user to enable based\n // upon a good validation\n hasSuccess (): boolean {\n return (\n this.internalSuccessMessages.length > 0 ||\n this.success\n )\n },\n externalError (): boolean {\n return this.internalErrorMessages.length > 0 || this.error\n },\n hasMessages (): boolean {\n return this.validationTarget.length > 0\n },\n hasState (): boolean {\n return (\n this.hasSuccess ||\n (this.shouldValidate && this.hasError)\n )\n },\n internalErrorMessages (): VuetifyRuleValidations {\n return this.genInternalMessages(this.errorMessages)\n },\n internalMessages (): VuetifyRuleValidations {\n return this.genInternalMessages(this.messages)\n },\n internalSuccessMessages (): VuetifyRuleValidations {\n return this.genInternalMessages(this.successMessages)\n },\n internalValue: {\n get (): unknown {\n return this.lazyValue\n },\n set (val: any) {\n this.lazyValue = val\n\n this.$emit('input', val)\n }\n },\n shouldValidate (): boolean {\n if (this.externalError) return true\n if (this.isResetting) return false\n\n return this.validateOnBlur\n ? this.hasFocused && !this.isFocused\n : (this.hasInput || this.hasFocused)\n },\n validations (): VuetifyRuleValidations {\n return this.validationTarget.slice(0, Number(this.errorCount))\n },\n validationState (): string | undefined {\n if (this.hasError && this.shouldValidate) return 'error'\n if (this.hasSuccess) return 'success'\n if (this.hasColor) return this.color\n return undefined\n },\n validationTarget (): VuetifyRuleValidations {\n if (this.internalErrorMessages.length > 0) {\n return this.internalErrorMessages\n } else if (this.successMessages.length > 0) {\n return this.internalSuccessMessages\n } else if (this.messages.length > 0) {\n return this.internalMessages\n } else if (this.shouldValidate) {\n return this.errorBucket\n } else return []\n }\n },\n\n watch: {\n rules: {\n handler (newVal, oldVal) {\n if (deepEqual(newVal, oldVal)) return\n this.validate()\n },\n deep: true\n },\n internalValue () {\n // If it's the first time we're setting input,\n // mark it with hasInput\n this.hasInput = true\n this.validateOnBlur || this.$nextTick(this.validate)\n },\n isFocused (val) {\n // Should not check validation\n // if disabled or readonly\n if (\n !val &&\n !this.disabled &&\n !this.readonly\n ) {\n this.hasFocused = true\n this.validateOnBlur && this.validate()\n }\n },\n isResetting () {\n setTimeout(() => {\n this.hasInput = false\n this.hasFocused = false\n this.isResetting = false\n this.validate()\n }, 0)\n },\n hasError (val) {\n if (this.shouldValidate) {\n this.$emit('update:error', val)\n }\n },\n value (val) {\n this.lazyValue = val\n }\n },\n\n beforeMount () {\n this.validate()\n },\n\n created () {\n this.form && this.form.register(this)\n },\n\n beforeDestroy () {\n this.form && this.form.unregister(this)\n },\n\n methods: {\n genInternalMessages (messages: VuetifyMessage): VuetifyRuleValidations {\n if (!messages) return []\n else if (Array.isArray(messages)) return messages\n else return [messages]\n },\n /** @public */\n reset () {\n this.isResetting = true\n this.internalValue = Array.isArray(this.internalValue)\n ? []\n : undefined\n },\n /** @public */\n resetValidation () {\n this.isResetting = true\n },\n /** @public */\n validate (force = false, value?: any): boolean {\n const errorBucket = []\n value = value || this.internalValue\n\n if (force) this.hasInput = this.hasFocused = true\n\n for (let index = 0; index < this.rules.length; index++) {\n const rule = this.rules[index]\n const valid = typeof rule === 'function' ? rule(value) : rule\n\n if (typeof valid === 'string') {\n errorBucket.push(valid)\n } else if (typeof valid !== 'boolean') {\n consoleError(`Rules should return a string or boolean, received '${typeof valid}' instead`, this)\n }\n }\n\n this.errorBucket = errorBucket\n this.valid = errorBucket.length === 0\n\n return this.valid\n }\n }\n})\n"],"sourceRoot":""}