Skip to content

Commit b7cb48e

Browse files
Merge pull request #2492 from zetkin/issue-2394/paste-into-email-editor
Add pasting logic for spans in email editor
2 parents f9095a3 + beedde2 commit b7cb48e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/features/emails/components/EmailEditor/EmailEditorFrontend.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22
//@ts-ignore
33
import Header from '@editorjs/header';
4-
//@ts-ignore
5-
import Paragraph from '@editorjs/paragraph';
64
import { Box, useTheme } from '@mui/material';
75
import EditorJS, {
86
EditorConfig,
@@ -19,6 +17,7 @@ import messageIds from 'features/emails/l10n/messageIds';
1917
import { useMessages } from 'core/i18n';
2018
import { useNumericRouteParams } from 'core/hooks';
2119
import variableToolFactory from './tools/inlineVariable';
20+
import ParagraphWithSpanPaste from './tools/paragraphWithSpanPaste';
2221

2322
export type EmailEditorFrontendProps = {
2423
apiRef: MutableRefObject<EditorJS | null>;
@@ -110,7 +109,7 @@ const EmailEditorFrontend: FC<EmailEditorFrontendProps> = ({
110109
},
111110
},
112111
paragraph: {
113-
class: Paragraph,
112+
class: ParagraphWithSpanPaste as unknown as ToolConstructable,
114113
},
115114
variable: {
116115
class: variableToolFactory(messages.editor.tools.variable.title()),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
//@ts-ignore
3+
import Paragraph from '@editorjs/paragraph';
4+
import { BlockTool, HTMLPasteEvent } from '@editorjs/editorjs';
5+
6+
//@ts-ignore
7+
export default class ParagraphWithSpanPaste
8+
extends Paragraph
9+
implements BlockTool
10+
{
11+
onPaste(event: HTMLPasteEvent) {
12+
const text = event.detail.data.textContent;
13+
event.detail.data = document.createElement('div');
14+
event.detail.data.textContent = text;
15+
return super.onPaste(event);
16+
}
17+
18+
static get pasteConfig() {
19+
return {
20+
tags: ['P', 'SPAN'],
21+
};
22+
}
23+
}

0 commit comments

Comments
 (0)