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
|
<script>
import { GlButton, GlTooltipDirective as GlTooltip } from '@gitlab/ui';
import { __ } from '~/locale';
import Link from '../extensions/link';
export default {
i18n: {
inputLabel: __('Attach a file or image'),
},
components: {
GlButton,
},
directives: {
GlTooltip,
},
inject: ['tiptapEditor'],
data() {
return {
linkHref: '',
};
},
methods: {
emitExecute(source = 'url') {
this.$emit('execute', { contentType: Link.name, value: source });
},
openFileUpload() {
this.$refs.fileSelector.click();
},
onFileSelect(e) {
for (const file of e.target.files) {
this.tiptapEditor.chain().focus().uploadAttachment({ file }).run();
}
// Reset the file input so that the same file can be uploaded again
this.$refs.fileSelector.value = '';
this.emitExecute('upload');
},
},
};
</script>
<template>
<span class="gl-display-inline-flex">
<gl-button
v-gl-tooltip
:aria-label="$options.i18n.inputLabel"
:title="$options.i18n.inputLabel"
category="tertiary"
icon="paperclip"
size="small"
class="gl-mr-2"
lazy
@click="openFileUpload"
/>
<input
ref="fileSelector"
type="file"
multiple
name="content_editor_image"
class="gl-display-none"
:aria-label="$options.i18n.inputLabel"
data-testid="file-upload-field"
@change="onFileSelect"
/>
</span>
</template>
|