aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/stock-images/MetadataBox.vue
blob: 172e9ad833ab9367dcbebafea42bc957d1dd4f90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template>
    <div class="upload-metadata-box">
        <div>
            <ThumbnailCard
                v-if="fileURL"
                :height="height ?? 0"
                :mime-type="file.type"
                :size="file.size"
                :url="fileURL"
                :width="width ?? 0"
            />
        </div>
        <div>
            <AttributesFieldset :metadata="metadata" :suggested-tags="suggestedTags" @change="metadata => onChange(metadata)" />
        </div>
    </div>
</template>

<script>
import ThumbnailCard from './ThumbnailCard.vue';
import AttributesFieldset from './AttributesFieldset.vue';

export default {
    props: ['file', 'metadata', 'suggestedTags'],

    components: { AttributesFieldset, ThumbnailCard },

    emits: ['change'],

    data: () => ({
        fileURL: null,
        height: null,
        image: null,
        width: null,
    }),

    computed: {
        tags: {
            get() {
                return this.metadata.tags;
            },
            set(tags) {
                this.$emit('change', { ...this.metadata, tags });
            },
        },
    },

    methods: {
        onChange(metadata) {
            this.$emit('change', metadata);
        },
    },

    mounted() {
        this.fileURL = URL.createObjectURL(this.file);
        this.image = new Image();
        this.image.onload = ({ target }) => {
            this.height = target.height;
            this.width = target.width;
        };
        this.image.src = this.fileURL;
        this.$emit('change', { ...this.metadata, title: this.file.name });
    },

    beforeUnmount() {
        if (this.fileURL) {
            URL.revokeObjectURL(this.fileURL);
        }
    },
};
</script>

<style scoped>
.upload-metadata-box {
    display: flex;
    gap: 1em;
}
.upload-metadata-box > div:first-child {
    flex-basis: 200px;
    flex-grow: 0;
    overflow: hidden;
}
.upload-metadata-box > div:last-child {
    flex-basis: 30em;
    flex-grow: 1;
}
.upload-metadata-box div:first-child ul {
    font-size: 0.9em;
    line-height: 1.5;
    margin-block-start: 1em;
    padding-inline-start: 0;
}
</style>