feat: Add the ability to paste images to editor (#10072)

This commit is contained in:
Muhsin Keloth
2024-09-11 09:44:13 +05:30
committed by GitHub
parent bb74c621b5
commit 2c17c95eab
8 changed files with 160 additions and 47 deletions

View File

@@ -8,6 +8,7 @@ import {
EditorState,
Selection,
} from '@chatwoot/prosemirror-schema';
import imagePastePlugin from '@chatwoot/prosemirror-schema/src/plugins/image';
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
import { useAlert } from 'dashboard/composables';
import { useUISettings } from 'dashboard/composables/useUISettings';
@@ -55,7 +56,7 @@ export default {
return {
editorView: null,
state: undefined,
plugins: [],
plugins: [imagePastePlugin(this.handleImageUpload)],
};
},
computed: {
@@ -76,6 +77,7 @@ export default {
this.reloadState();
},
},
created() {
this.state = createState(
this.value,
@@ -95,6 +97,24 @@ export default {
openFileBrowser() {
this.$refs.imageUploadInput.click();
},
async handleImageUpload(url) {
try {
const fileUrl = await this.$store.dispatch(
'articles/uploadExternalImage',
{
portalSlug: this.$route.params.portalSlug,
url,
}
);
return fileUrl;
} catch (error) {
useAlert(
this.$t('HELP_CENTER.ARTICLE_EDITOR.IMAGE_UPLOAD.UN_AUTHORIZED_ERROR')
);
return '';
}
},
onFileChange() {
const file = this.$refs.imageUploadInput.files[0];