Skip to content

Commit

Permalink
Merge pull request #2492 from zetkin/issue-2394/paste-into-email-editor
Browse files Browse the repository at this point in the history
Add pasting logic for spans in email editor
  • Loading branch information
richardolsson authored Jan 24, 2025
2 parents f9095a3 + beedde2 commit b7cb48e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
//@ts-ignore
import Header from '@editorjs/header';
//@ts-ignore
import Paragraph from '@editorjs/paragraph';
import { Box, useTheme } from '@mui/material';
import EditorJS, {
EditorConfig,
Expand All @@ -19,6 +17,7 @@ import messageIds from 'features/emails/l10n/messageIds';
import { useMessages } from 'core/i18n';
import { useNumericRouteParams } from 'core/hooks';
import variableToolFactory from './tools/inlineVariable';
import ParagraphWithSpanPaste from './tools/paragraphWithSpanPaste';

export type EmailEditorFrontendProps = {
apiRef: MutableRefObject<EditorJS | null>;
Expand Down Expand Up @@ -110,7 +109,7 @@ const EmailEditorFrontend: FC<EmailEditorFrontendProps> = ({
},
},
paragraph: {
class: Paragraph,
class: ParagraphWithSpanPaste as unknown as ToolConstructable,
},
variable: {
class: variableToolFactory(messages.editor.tools.variable.title()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
//@ts-ignore
import Paragraph from '@editorjs/paragraph';
import { BlockTool, HTMLPasteEvent } from '@editorjs/editorjs';

//@ts-ignore
export default class ParagraphWithSpanPaste
extends Paragraph
implements BlockTool
{
onPaste(event: HTMLPasteEvent) {
const text = event.detail.data.textContent;
event.detail.data = document.createElement('div');
event.detail.data.textContent = text;
return super.onPaste(event);
}

static get pasteConfig() {
return {
tags: ['P', 'SPAN'],
};
}
}

0 comments on commit b7cb48e

Please sign in to comment.