feat(editor-ext): add BaseEmbed TipTap node with pageId attribute

This commit is contained in:
Philipinho
2026-04-27 01:52:58 +01:00
parent 69e7bd73f2
commit 4a15c805f1
3 changed files with 64 additions and 1 deletions
+1 -1
View File
@@ -30,4 +30,4 @@ export * from "./lib/columns";
export * from "./lib/status";
export * from "./lib/pdf";
export * from "./lib/resizable-nodeview";
export * from "./lib/base-embed";
@@ -0,0 +1,61 @@
import { Node, mergeAttributes } from '@tiptap/core';
export interface BaseEmbedOptions {
HTMLAttributes: Record<string, any>;
}
declare module '@tiptap/core' {
interface Commands<ReturnType> {
baseEmbed: {
insertBaseEmbed: (attrs: { pageId: string }) => ReturnType;
};
}
}
export const BaseEmbed = Node.create<BaseEmbedOptions>({
name: 'baseEmbed',
group: 'block',
atom: true,
selectable: true,
draggable: true,
addOptions() {
return { HTMLAttributes: {} };
},
addAttributes() {
return {
pageId: {
default: null,
parseHTML: (el) => el.getAttribute('data-page-id'),
renderHTML: (attrs) =>
attrs.pageId ? { 'data-page-id': attrs.pageId } : {},
},
};
},
parseHTML() {
return [{ tag: 'div[data-type="base-embed"]' }];
},
renderHTML({ HTMLAttributes }) {
return [
'div',
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {
'data-type': 'base-embed',
}),
];
},
addCommands() {
return {
insertBaseEmbed:
(attrs) =>
({ commands }) =>
commands.insertContent({
type: this.name,
attrs,
}),
};
},
});
@@ -0,0 +1,2 @@
export { BaseEmbed } from './base-embed';
export type { BaseEmbedOptions } from './base-embed';