Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pasting logic for spans in email editor #2492

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm realizing now that this filter is probably the reason why we only got span-related events in onPaste(). I wonder if there is some sort of wildcard that we could use, but for now, this is good enough because I believe it will solve the bug!

};
}
}
Loading