feat: added custom blockquote extension for resolving enter key behaviour (#2997)

This commit is contained in:
Henit Chobisa 2023-12-06 19:17:47 +05:30 committed by sriram veeraghanta
parent 4c53157b0e
commit 7a96e12523
4 changed files with 47 additions and 11 deletions

View file

@ -20,6 +20,7 @@ import { Mentions } from "../mentions";
import { CustomKeymap } from "./keymap";
import { CustomCodeBlock } from "./code";
import { CustomQuoteExtension } from "./quote";
import { ListKeymap } from "./custom-list-keymap";
import {
IMentionSuggestion,
@ -34,7 +35,7 @@ export const CoreEditorExtensions = (
},
deleteFile: DeleteImage,
restoreFile: RestoreImage,
cancelUploadImage?: () => any,
cancelUploadImage?: () => any
) => [
StarterKit.configure({
bulletList: {
@ -52,11 +53,11 @@ export const CoreEditorExtensions = (
class: "leading-normal -mb-2",
},
},
blockquote: {
HTMLAttributes: {
class: "border-l-4 border-custom-border-300",
},
},
// blockquote: {
// HTMLAttributes: {
// class: "border-l-4 border-custom-border-300",
// },
// },
code: false,
codeBlock: false,
horizontalRule: false,
@ -65,6 +66,9 @@ export const CoreEditorExtensions = (
width: 2,
},
}),
CustomQuoteExtension.configure({
HTMLAttributes: { className: "border-l-4 border-custom-border-300" },
}),
CustomKeymap,
ListKeymap,
TiptapLink.configure({
@ -108,6 +112,6 @@ export const CoreEditorExtensions = (
Mentions(
mentionConfig.mentionSuggestions,
mentionConfig.mentionHighlights,
false,
false
),
];

View file

@ -0,0 +1,26 @@
import { isAtStartOfNode } from "@tiptap/core";
import Blockquote from "@tiptap/extension-blockquote";
export const CustomQuoteExtension = Blockquote.extend({
addKeyboardShortcuts() {
return {
Enter: ({ editor }) => {
const { $from, $to, $head } = this.editor.state.selection;
const parent = $head.node(-1);
if (!parent) return false;
if (parent.type.name !== "blockquote") {
return false;
}
if ($from.pos !== $to.pos) return false;
// if ($head.parentOffset < $head.parent.content.size) return false;
// this.editor.commands.insertContentAt(parent.ne);
this.editor.chain().splitBlock().lift(this.name).run();
return true;
},
};
},
});