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AACF,UAAA,KAAK,EAAE;AAAA,mBAAM,MAAI,CAAC,KAAL,CAAW,KAAX,CAAiB,KAAjB,EAAN;AAAA;AADL;AAN4B,OAA3B,EASJ,QATI,CAAP;AAUD,KAvEM;AAwEP,IAAA,OAxEO,mBAwEE,CAxEF,EAwEU;AACf,UAAM,KAAK,sBAAQ,CAAC,CAAC,MAAF,CAA8B,KAA9B,IAAuC,EAA/C,CAAX;;AAEA,WAAK,aAAL,GAAqB,KAAK,UAAL,GAAkB,KAAlB,GAA0B,KAAK,CAAC,CAAD,CAApD;AACD,KA5EM;AA6EP,IAAA,YA7EO,wBA6EO,GA7EP,EA6EkB;AACvB,UAAI,GAAG,CAAC,MAAJ,GAAa,MAAM,CAAC,KAAK,cAAN,CAAvB,EAA8C,OAAO,GAAP;AAC9C,uBAAU,GAAG,CAAC,KAAJ,CAAU,CAAV,EAAa,EAAb,CAAV,mBAA8B,GAAG,CAAC,KAAJ,CAAU,CAAC,EAAX,CAA9B;AACD;AAhFM;AAxHsB,CAAlB,C","sourcesContent":["// Styles\nimport './VFileInput.sass'\n\n// Extensions\nimport VTextField from '../VTextField'\n\n// Components\nimport { VChip } from '../VChip'\n\n// Types\nimport { PropValidator } from 'vue/types/options'\n\n// Utilities\nimport { humanReadableFileSize, wrapInArray } from '../../util/helpers'\n\nexport default VTextField.extend({\n name: 'v-file-input',\n\n model: {\n prop: 'value',\n event: 'change',\n },\n\n props: {\n chips: Boolean,\n clearable: {\n type: Boolean,\n default: true,\n },\n counterSizeString: {\n type: String,\n default: '$vuetify.fileInput.counterSize',\n },\n counterString: {\n type: String,\n default: '$vuetify.fileInput.counter',\n },\n placeholder: String,\n prependIcon: {\n type: String,\n default: '$vuetify.icons.file',\n },\n readonly: {\n type: Boolean,\n default: true,\n },\n showSize: {\n type: [Boolean, Number],\n default: false,\n validator: (v: boolean | number) => {\n return (\n typeof v === 'boolean' ||\n [1000, 1024].includes(v)\n )\n },\n } as PropValidator<boolean | 1000 | 1024>,\n smallChips: Boolean,\n truncateLength: {\n type: [Number, String],\n default: 22,\n },\n type: {\n type: String,\n default: 'file',\n },\n value: {\n default: () => [],\n validator: val => {\n return typeof val === 'object' || Array.isArray(val)\n },\n } as PropValidator<File | File[]>,\n },\n\n data: () => ({\n internalFileInput: null,\n }),\n\n computed: {\n classes (): object {\n return {\n ...VTextField.options.computed.classes.call(this),\n 'v-file-input': true,\n }\n },\n counterValue (): string {\n if (!this.showSize) return this.$vuetify.lang.t(this.counterString, this.lazyValue.length)\n\n const bytes = this.internalArrayValue.reduce((size: number, file: File) => size + file.size, 0)\n\n return this.$vuetify.lang.t(\n this.counterSizeString,\n this.lazyValue.length,\n humanReadableFileSize(bytes, this.base === 1024)\n )\n },\n internalArrayValue (): File[] {\n return Array.isArray(this.internalValue)\n ? this.internalValue\n : wrapInArray(this.internalValue)\n },\n internalValue: {\n get (): File[] {\n return this.lazyValue\n },\n set (val: File | File[]) {\n this.lazyValue = val\n this.$emit('change', this.lazyValue)\n },\n },\n isDirty (): boolean {\n return this.internalArrayValue.length > 0\n },\n isLabelActive (): boolean {\n return this.isDirty\n },\n isMultiple (): boolean {\n return this.$attrs.hasOwnProperty('multiple')\n },\n text (): string[] {\n if (!this.isDirty) return [this.placeholder]\n\n return this.internalArrayValue.map((file: File) => {\n const name = this.truncateText(file.name)\n\n return !this.showSize ? name : `${name} (${humanReadableFileSize(file.size, this.base === 1024)})`\n })\n },\n base (): 1000 | 1024 | undefined {\n return typeof this.showSize !== 'boolean' ? this.showSize : undefined\n },\n hasChips (): boolean {\n return this.chips || this.smallChips\n },\n },\n\n methods: {\n clearableCallback () {\n this.internalValue = this.isMultiple ? [] : null\n this.internalFileInput = null\n },\n genChips () {\n if (!this.isDirty) return []\n\n return this.text.map((text, index) => this.$createElement(VChip, {\n props: { small: this.smallChips },\n on: {\n 'click:close': () => {\n const internalValue = this.internalValue\n internalValue.splice(index, 1)\n this.internalValue = internalValue // Trigger the watcher\n },\n },\n }, [text]))\n },\n genInput () {\n const input = VTextField.options.methods.genInput.call(this)\n\n input.data!.domProps!.value = this.internalFileInput\n\n return [this.genSelections(), input]\n },\n genPrependSlot () {\n const icon = this.genIcon('prepend', () => {\n this.$refs.input.click()\n })\n\n icon.data!.attrs = { tabindex: 0 }\n\n return this.genSlot('prepend', 'outer', [icon])\n },\n genSelectionText (): string[] {\n const length = this.text.length\n\n if (length < 2) return this.text\n if (this.showSize && !this.counter) return [this.counterValue]\n return [this.$vuetify.lang.t(this.counterString, length)]\n },\n genSelections () {\n const children = []\n\n if (this.isDirty && this.$scopedSlots.selection) {\n this.internalValue.forEach((file: File, index: number) => {\n if (!this.$scopedSlots.selection) return\n\n children.push(\n this.$scopedSlots.selection({\n text: this.text[index],\n file,\n index,\n })\n )\n })\n } else {\n children.push(this.hasChips && this.isDirty ? this.genChips() : this.genSelectionText())\n }\n\n return this.$createElement('div', {\n staticClass: 'v-file-input__text',\n class: {\n 'v-file-input__text--placeholder': this.placeholder && !this.isDirty,\n 'v-file-input__text--chips': this.hasChips && !this.$scopedSlots.selection,\n },\n on: {\n click: () => this.$refs.input.click(),\n },\n }, children)\n },\n onInput (e: Event) {\n const files = [...(e.target as HTMLInputElement).files || []]\n\n this.internalValue = this.isMultiple ? files : files[0]\n },\n truncateText (str: string) {\n if (str.length < Number(this.truncateLength)) return str\n return `${str.slice(0, 10)}…${str.slice(-10)}`\n },\n },\n})\n"],"sourceRoot":"","file":"VFileInput.js"} |