Files
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

58 lines
979 B
TypeScript
Executable File

import {mergeAttributes, Node} from '@tiptap/react';
declare module '@tiptap/core' {
interface Commands<ReturnType> {
embed: {
setEmbed: (options: {src: string}) => ReturnType;
};
}
}
export const Embed = Node.create({
name: 'embed',
group: 'block',
atom: true,
addAttributes() {
return {
allowfullscreen: {
default: null,
},
allow: {
default: 'autoplay; fullscreen; picture-in-picture',
},
src: {
default: null,
},
};
},
parseHTML() {
return [
{
tag: 'iframe',
},
];
},
renderHTML({HTMLAttributes}) {
return [
'iframe',
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
];
},
addCommands() {
return {
setEmbed:
options =>
({commands}) => {
return commands.insertContent({
type: this.name,
attrs: options,
});
},
};
},
});