Skip to content
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
2 changes: 1 addition & 1 deletion packages/editor/src/ce/extensions/rich-text-extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IEditorProps, TExtensions } from "@/types";

export type TRichTextEditorAdditionalExtensionsProps = Pick<
IEditorProps,
"disabledExtensions" | "flaggedExtensions" | "fileHandler"
"disabledExtensions" | "flaggedExtensions" | "fileHandler" | "extendedEditorProps"
>;

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/ce/types/editor-extended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export type IEditorExtensionOptions = unknown;

export type IEditorPropsExtended = unknown;

export type ICollaborativeDocumentEditorPropsExtended = unknown;

export type TExtendedEditorCommands = never;

export type TExtendedCommandExtraProps = unknown;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const RichTextEditor: React.FC<IRichTextEditorProps> = (props) => {
extensions: externalExtensions = [],
fileHandler,
flaggedExtensions,
extendedEditorProps,
} = props;

const getExtensions = useCallback(() => {
Expand All @@ -30,11 +31,12 @@ const RichTextEditor: React.FC<IRichTextEditorProps> = (props) => {
disabledExtensions,
fileHandler,
flaggedExtensions,
extendedEditorProps,
}),
];

return extensions;
}, [dragDropEnabled, disabledExtensions, externalExtensions, fileHandler, flaggedExtensions]);
}, [dragDropEnabled, disabledExtensions, externalExtensions, fileHandler, flaggedExtensions, extendedEditorProps]);

return (
<EditorWrapper {...props} extensions={getExtensions()}>
Expand Down
69 changes: 69 additions & 0 deletions packages/editor/src/core/extensions/trailing-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Extension } from "@tiptap/core";
import { NodeType, Node as ProseMirrorNode } from "@tiptap/pm/model";
import { Plugin, PluginKey } from "@tiptap/pm/state";
// constants
import { CORE_EXTENSIONS } from "@/constants/extension";

function nodeEqualsType({ types, node }: { types: NodeType[]; node: ProseMirrorNode | null }) {
// TODO: check this logic, might be wrong
// @ts-expect-error - logic might be wrong
return (Array.isArray(types) && types.includes(node?.type)) || node?.type === types;
}

export interface TrailingNodeOptions {
node: string;
notAfter: string[];
}

export const TrailingNode = Extension.create<TrailingNodeOptions>({
name: "trailingNode",

addOptions() {
return {
node: CORE_EXTENSIONS.PARAGRAPH,
notAfter: [CORE_EXTENSIONS.PARAGRAPH],
};
},

addProseMirrorPlugins() {
const plugin = new PluginKey(this.name);
const disabledNodes = Object.entries(this.editor.schema.nodes)
.map(([, value]) => value)
.filter((node) => this.options.notAfter.includes(node.name));

return [
new Plugin({
key: plugin,
appendTransaction: (_, __, state) => {
const { doc, tr, schema } = state;
const shouldInsertNodeAtEnd = plugin.getState(state);
const endPosition = doc.content.size;
const type = schema.nodes[this.options.node];

if (!shouldInsertNodeAtEnd) {
return;
}

// eslint-disable-next-line consistent-return
Comment on lines +44 to +47
Copy link

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The eslint-disable comment suggests inconsistent return patterns. Consider refactoring to have consistent return behavior throughout the function.

Suggested change
return;
}
// eslint-disable-next-line consistent-return
return null;
}

Copilot uses AI. Check for mistakes.
return tr.insert(endPosition, type.create());
},
state: {
init: (_, state) => {
const lastNode = state.tr.doc.lastChild;

return !nodeEqualsType({ node: lastNode, types: disabledNodes });
},
apply: (tr, value) => {
if (!tr.docChanged) {
return value;
}

const lastNode = tr.doc.lastChild;

return !nodeEqualsType({ node: lastNode, types: disabledNodes });
},
},
}),
];
},
});
7 changes: 6 additions & 1 deletion packages/editor/src/core/types/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type { NodeViewProps as TNodeViewProps } from "@tiptap/react";
// extension types
import type { TTextAlign } from "@/extensions";
// plane editor imports
import type { IEditorPropsExtended, TExtendedEditorCommands } from "@/plane-editor/types/editor-extended";
import type {
IEditorPropsExtended,
TExtendedEditorCommands,
ICollaborativeDocumentEditorPropsExtended,
} from "@/plane-editor/types/editor-extended";
// types
import type {
IMarking,
Expand Down Expand Up @@ -176,6 +180,7 @@ export type ICollaborativeDocumentEditorProps = Omit<IEditorProps, "initialValue
realtimeConfig: TRealtimeConfig;
serverHandler?: TServerHandler;
user: TUserDetails;
extendedDocumentEditorProps?: ICollaborativeDocumentEditorPropsExtended;
};

export type IDocumentEditorProps = Omit<IEditorProps, "initialValue" | "onEnterKeyPress" | "value"> & {
Expand Down
3 changes: 3 additions & 0 deletions packages/editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ export { ADDITIONAL_EXTENSIONS } from "@/plane-editor/constants/extensions";

// types
export * from "@/types";

// additional exports
export { TrailingNode } from "./core/extensions/trailing-node";
Loading