[WIKI-576] fix: trail node (#7527)
* fix : trail node * remove flagged * refactor : add disable flagging * refactor:update disabled extension * refactor: additional disabled * refactor: update enum * chore: add description key to page response type * chore: update base page instance --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
This commit is contained in:
parent
c3273b1a85
commit
fa150c2b47
8 changed files with 70 additions and 19 deletions
|
|
@ -50,17 +50,16 @@ export const EditorContainer: FC<Props> = (props) => {
|
|||
return;
|
||||
}
|
||||
|
||||
// Get the last node in the document
|
||||
const docSize = editor.state.doc.content.size;
|
||||
const lastNodePos = editor.state.doc.resolve(Math.max(0, docSize - 2));
|
||||
const lastNode = lastNodePos.node();
|
||||
// Get the last child node in the document
|
||||
const doc = editor.state.doc;
|
||||
const lastNode = doc.lastChild;
|
||||
|
||||
// Check if its last node and add new node
|
||||
if (lastNode) {
|
||||
const isLastNodeEmptyParagraph =
|
||||
lastNode.type.name === CORE_EXTENSIONS.PARAGRAPH && lastNode.content.size === 0;
|
||||
// Only insert a new paragraph if the last node is not an empty paragraph and not a doc node
|
||||
if (!isLastNodeEmptyParagraph && lastNode.type.name !== "doc") {
|
||||
const isLastNodeParagraph = lastNode.type.name === CORE_EXTENSIONS.PARAGRAPH;
|
||||
// Insert a new paragraph if the last node is not a paragraph and not a doc node
|
||||
if (!isLastNodeParagraph && lastNode.type.name !== CORE_EXTENSIONS.DOCUMENT) {
|
||||
// Only insert a new paragraph if the last node is not an empty paragraph and not a doc node
|
||||
const endPosition = editor?.state.doc.content.size;
|
||||
editor?.chain().insertContentAt(endPosition, { type: "paragraph" }).focus("end").run();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export const CommandMenuItem: React.FC<Props> = (props) => {
|
|||
{item.icon}
|
||||
</span>
|
||||
<p className="flex-grow truncate">{item.title}</p>
|
||||
{item.badge}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import type { Editor, Range } from "@tiptap/core";
|
||||
import type { CSSProperties } from "react";
|
||||
// types
|
||||
import { TEditorCommands } from "@/types";
|
||||
import type { TEditorCommands } from "@/types";
|
||||
|
||||
export type CommandProps = {
|
||||
editor: Editor;
|
||||
|
|
@ -19,4 +18,5 @@ export type ISlashCommandItem = {
|
|||
icon: React.ReactNode;
|
||||
iconContainerStyle?: CSSProperties;
|
||||
command: ({ editor, range }: CommandProps) => void;
|
||||
badge?: React.ReactNode;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue