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AAI,CAAC,KAAD,CAAjC,GAA2C,IAAzD;;AAEA,YAAI,OAAO,KAAP,KAAiB,QAArB,EAA+B;AAC7B,UAAA,WAAW,CAAC,IAAZ,CAAiB,KAAjB;AACD,SAFD,MAEO,IAAI,OAAO,KAAP,KAAiB,SAArB,EAAgC;AACrC,UAAA,YAAY,CAAC,sDAAsD,OAAO,KAAK,WAAnE,EAAgF,IAAhF,CAAZ;AACD;AACF;;AAED,WAAK,WAAL,GAAmB,WAAnB;AACA,WAAK,KAAL,GAAa,WAAW,CAAC,MAAZ,KAAuB,CAApC;AAEA,aAAO,KAAK,KAAZ;AACD;;AAvCM;AAhMF,CAJM,CAAf","sourcesContent":["// Mixins\nimport Colorable from '../colorable'\nimport Themeable from '../themeable'\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 | boolean\nexport type VuetifyMessage = string | string[]\nexport type VuetifyRuleValidations = (VuetifyRuleValidator | string)[]\n\n/* @vue/component */\nexport default mixins(\n Colorable,\n RegistrableInject('form'),\n Themeable\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<VuetifyMessage>,\n messages: {\n type: [String, Array],\n default: () => [],\n } as PropValidator<VuetifyMessage>,\n readonly: Boolean,\n rules: {\n type: Array,\n default: () => [],\n } as PropValidator<VuetifyRuleValidations>,\n success: Boolean,\n successMessages: {\n type: [String, Array],\n default: () => [],\n } as PropValidator<VuetifyMessage>,\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 computedColor (): string | undefined {\n if (this.disabled) return undefined\n if (this.color) return this.color\n // It's assumed that if the input is on a\n // dark background, the user will want to\n // have a white color. If the entire app\n // is setup to be dark, then they will\n // like want to use their primary color\n if (this.isDark && !this.appIsDark) return 'white'\n else return 'primary'\n },\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 if (this.disabled) return false\n\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.disabled) return undefined\n if (this.hasError && this.shouldValidate) return 'error'\n if (this.hasSuccess) return 'success'\n if (this.hasColor) return this.computedColor\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":"","file":"index.js"} |