Add image button to toolbar

This commit is contained in:
Maximilian Harz 2025-05-29 19:25:01 +02:00
parent 5f29969acb
commit 20fbb26716
2 changed files with 23 additions and 0 deletions

View File

@ -60,6 +60,10 @@
icon="minus"
/>
<menu-bar-button :isActive="isActive.image()" icon="image" :onClick="openFileDialog" />
<input id="fileInput" type="file" @change="fileChange" ref="file" hidden multiple />
<menu-legend class="legend-button" />
</div>
</editor-menu-bar>
@ -80,6 +84,23 @@ export default {
editor: Object,
toggleLinkInput: Function,
},
methods: {
openFileDialog() {
this.$refs.file.click()
},
fileChange(event) {
const files = event.target.files
if (files.length === 0) return
for (const file of files) {
this.editor.commands.image({
src: URL.createObjectURL(file),
alt: file.name,
})
}
// Reset the input value
event.target.value = ''
},
},
}
</script>

View File

@ -15,6 +15,7 @@ import {
HorizontalRule,
Placeholder,
Underline,
Image,
} from 'tiptap-extensions'
export default function defaultExtensions(component) {
@ -53,5 +54,6 @@ export default function defaultExtensions(component) {
return embed
},
}),
new Image(),
]
}