<commit_before><template>
    <label class="upload control">
        <template v-if="!dragDrop">
            <slot></slot>
        </template>

        <div v-else
            class="upload-draggable"
            :class="[type, {
                'is-loading': loading,
                'is-disabled': disabled,
                'is-hovered': dragDropFocus
            }]"
            @dragover.prevent="updateDragDropFocus(true)"
            @dragleave.prevent="updateDragDropFocus(false)"
            @dragenter.prevent="updateDragDropFocus(true)"
            @drop.prevent="onFileChange">
            <slot></slot>
        </div>

        <input ref="input"
            type="file"
            v-bind="$attrs"
            :multiple="multiple"
            :disabled="disabled"
            @change="onFileChange">
    </label>
</template>

<script>
    import FormElementMixin from '../../utils/FormElementMixin'

    export default {
        name: 'bUpload',
        inheritAttrs: false,
        mixins: [FormElementMixin],
        props: {
            value: {
                type: Array,
                default: () => []
            },
            multiple: Boolean,
            disabled: Boolean,
            dragDrop: Boolean,
            type: {
                type: String,
                default: 'is-primary'
            }
        },
        data() {
            return {
                newValue: this.value || [],
                dragDropFocus: false,
                _elementRef: 'input'
            }
        },
        watch: {
            /**
             * When v-model is changed:
             *   1. Set internal value.
             *   2. If it's invalid, validate again.
             */
            value(value) {
                this.newValue = value
                !this.isValid && !this.dragDrop && this.checkHtml5Validity()
            }
        },
        methods: {
            /**
             * Listen change event on input type 'file',
             * emit 'input' event and validate
             */
            onFileChange(event) {
                if (!this.disabled && !this.loading) {
                    if (this.dragDrop) {
                        this.updateDragDropFocus(false)
                    }
                    const value = event.target.files || event.dataTransfer.files
                    if (value && value.length) {
                        if (!this.multiple) {
                            // only one element in case drag drop mode and isn't multiple
                            if (this.dragDrop) {
                                if (value.length === 1) {
                                    this.newValue = []
                                } else {
                                    return false
                                }
                            } else {
                                this.newValue = []
                            }
                        }
                        for (let i = 0; i < value.length; i++) {
                            this.newValue.push(value[i])
                        }
                    }
                    this.$emit('input', this.newValue)
                    !this.dragDrop && this.checkHtml5Validity()
                }
            },

            /**
             * Listen drag-drop to update internal variable
             */
            updateDragDropFocus(focus) {
                if (!this.disabled && !this.loading) {
                    this.dragDropFocus = focus
                }
            }
        }
    }
</script>
<commit_msg>Fix #405 Reset input file<commit_after><template>
    <label class="upload control">
        <template v-if="!dragDrop">
            <slot></slot>
        </template>

        <div v-else
            class="upload-draggable"
            :class="[type, {
                'is-loading': loading,
                'is-disabled': disabled,
                'is-hovered': dragDropFocus
            }]"
            @dragover.prevent="updateDragDropFocus(true)"
            @dragleave.prevent="updateDragDropFocus(false)"
            @dragenter.prevent="updateDragDropFocus(true)"
            @drop.prevent="onFileChange">
            <slot></slot>
        </div>

        <input ref="input"
            type="file"
            v-bind="$attrs"
            :multiple="multiple"
            :disabled="disabled"
            @click="upload"
            @change="onFileChange">
    </label>
</template>

<script>
    import FormElementMixin from '../../utils/FormElementMixin'

    export default {
        name: 'bUpload',
        inheritAttrs: false,
        mixins: [FormElementMixin],
        props: {
            value: {
                type: Array,
                default: () => []
            },
            multiple: Boolean,
            disabled: Boolean,
            dragDrop: Boolean,
            type: {
                type: String,
                default: 'is-primary'
            }
        },
        data() {
            return {
                newValue: this.value || [],
                dragDropFocus: false,
                _elementRef: 'input'
            }
        },
        watch: {
            /**
             * When v-model is changed:
             *   1. Set internal value.
             *   2. If it's invalid, validate again.
             */
            value(value) {
                this.newValue = value
                !this.isValid && !this.dragDrop && this.checkHtml5Validity()
            }
        },
        methods: {

            /**
             * Reset input value
             */
            upload() {
                if (!this.disabled && !this.loading) {
                    this.$refs.input.value = null
                }
            },

            /**
             * Listen change event on input type 'file',
             * emit 'input' event and validate
             */
            onFileChange(event) {
                alert('event')
                if (!this.disabled && !this.loading) {
                    if (this.dragDrop) {
                        this.updateDragDropFocus(false)
                    }
                    const value = event.target.files || event.dataTransfer.files
                    if (value && value.length) {
                        if (!this.multiple) {
                            // only one element in case drag drop mode and isn't multiple
                            if (this.dragDrop) {
                                if (value.length === 1) {
                                    this.newValue = []
                                } else {
                                    return false
                                }
                            } else {
                                this.newValue = []
                            }
                        }
                        for (let i = 0; i < value.length; i++) {
                            this.newValue.push(value[i])
                        }
                    }
                    this.$emit('input', this.newValue)
                    !this.dragDrop && this.checkHtml5Validity()
                }
            },

            /**
             * Listen drag-drop to update internal variable
             */
            updateDragDropFocus(focus) {
                if (!this.disabled && !this.loading) {
                    this.dragDropFocus = focus
                }
            }
        }
    }
</script>

{'fraction_non_alphanumeric': 0.10572390572390572, 'fraction_numerical': 0.00202020202020202, 'mean_word_length': 0.9168817759421787, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '342531', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1710, 'n_words': 349}