mirror of
https://github.com/twentyhq/twenty.git
synced 2024-10-04 21:07:21 +03:00
GH-3090 Add ability to paste image in activity body editor (#3119)
This commit is contained in:
parent
00ab07ea62
commit
58a62e8d17
@ -83,13 +83,50 @@ export const ActivityBodyEditor = ({
|
|||||||
? JSON.parse(activity.body)
|
? JSON.parse(activity.body)
|
||||||
: undefined,
|
: undefined,
|
||||||
domAttributes: { editor: { class: 'editor' } },
|
domAttributes: { editor: { class: 'editor' } },
|
||||||
onEditorContentChange: (editor) => {
|
onEditorContentChange: (editor: BlockNoteEditor) => {
|
||||||
debounceOnChange(JSON.stringify(editor.topLevelBlocks) ?? '');
|
debounceOnChange(JSON.stringify(editor.topLevelBlocks) ?? '');
|
||||||
},
|
},
|
||||||
slashMenuItems,
|
slashMenuItems,
|
||||||
uploadFile: imagesActivated ? handleUploadAttachment : undefined,
|
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 (
|
return (
|
||||||
<StyledBlockNoteStyledContainer>
|
<StyledBlockNoteStyledContainer>
|
||||||
<BlockEditor editor={editor} />
|
<BlockEditor editor={editor} />
|
||||||
|
Loading…
Reference in New Issue
Block a user