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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,0GAA0E,KAA1E,iBAA4F,IAA5F;AACD;AACF;;AAED,WAAK,WAAL,GAAmB,WAAnB;AACA,WAAK,KAAL,GAAa,WAAW,CAAC,MAAZ,KAAuB,CAApC;AAEA,aAAO,KAAK,KAAZ;AACD;AAvCM;AAhMF,CAJM,C","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"} |