Skip to content

The open alternative to Salesforce, designed for AI.

GH-3090 Add ability to paste image in activity body editor (#3119)

Deepak Kumar58a62e8d17c7
diff --git a/packages/twenty-front/src/modules/activities/components/ActivityBodyEditor.tsx b/packages/twenty-front/src/modules/activities/components/ActivityBodyEditor.tsx
index c90a05c3af1..08c801fc955 100644
--- a/packages/twenty-front/src/modules/activities/components/ActivityBodyEditor.tsx
+++ b/packages/twenty-front/src/modules/activities/components/ActivityBodyEditor.tsx
@@ -83,13 +83,50 @@ export const ActivityBodyEditor = ({
? JSON.parse(activity.body)
: undefined,
domAttributes: { editor: { class: 'editor' } },
- onEditorContentChange: (editor) => {
+ onEditorContentChange: (editor: BlockNoteEditor) => {
debounceOnChange(JSON.stringify(editor.topLevelBlocks) ?? '');
},
slashMenuItems,
uploadFile: imagesActivated ? handleUploadAttachment : undefined,
+ onEditorReady: (editor: BlockNoteEditor) => {
+ editor.domElement.addEventListener('paste', handleImagePaste);
+ },
});
+ const handleImagePaste = async (event: ClipboardEvent) => {
+ const clipboardItems = event.clipboardData?.items;
+
+ if (clipboardItems) {
+ for (let i = 0; i < clipboardItems.length; i++) {
+ if (
+ clipboardItems[i].kind === 'file' &&
+ clipboardItems[i].type.match('^image/')
+ ) {
+ const pastedFile = clipboardItems[i].getAsFile();
+ if (!pastedFile) {
+ return;
+ }
+
+ const imageUrl = await handleUploadAttachment(pastedFile);
+ if (imageUrl) {
+ editor?.insertBlocks(
+ [
+ {
+ type: 'image',
+ props: {
+ url: imageUrl,
+ },
+ },
+ ],
+ editor?.getTextCursorPosition().block,
+ 'after',
+ );
+ }
+ }
+ }
+ }
+ };
+
return (
<StyledBlockNoteStyledContainer>
<BlockEditor editor={editor} />