tfrere's picture
tfrere HF Staff
refactor: store pre-computed attrs in citation/bibliography nodes
905f030
Raw
History Blame Contribute Delete
1.02 kB
import { Node, mergeAttributes } from "@tiptap/core";
import { ReactNodeViewRenderer } from "@tiptap/react";
import { BibliographyView } from "../BibliographyView";
declare module "@tiptap/core" {
interface Commands<ReturnType> {
bibliography: {
insertBibliography: () => ReturnType;
};
}
}
export const Bibliography = Node.create({
name: "bibliography",
group: "block",
atom: true,
draggable: false,
selectable: true,
addAttributes() {
return {
renderedHtml: { default: "" },
};
},
parseHTML() {
return [{ tag: 'div[data-type="bibliography"]' }];
},
renderHTML({ HTMLAttributes }) {
return [
"div",
mergeAttributes(HTMLAttributes, { "data-type": "bibliography" }),
];
},
addCommands() {
return {
insertBibliography:
() =>
({ commands }) => {
return commands.insertContent({ type: this.name });
},
};
},
addNodeView() {
return ReactNodeViewRenderer(BibliographyView);
},
});