mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-04 03:57:03 +00:00
feat(editor): add figure block with placement and caption
This commit is contained in:
1 parent
e76558fe1f
commit
50bde45d65
3 files changed
+78
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
import { Node, mergeAttributes } from "@tiptap/core";
|
||||
import { ReactNodeViewRenderer } from "@tiptap/react";
|
||||
import { FigureView } from "./FigureView";
|
||||
|
||||
export const Figure = Node.create({
|
||||
name: "figure",
|
||||
group: "block",
|
||||
atom: true,
|
||||
draggable: true,
|
||||
selectable: true,
|
||||
|
||||
addAttributes() {
|
||||
return {
|
||||
src: { default: "" },
|
||||
alt: { default: "" },
|
||||
caption: { default: "" },
|
||||
placement: { default: "full-width" },
|
||||
};
|
||||
},
|
||||
|
||||
parseHTML() {
|
||||
return [{ tag: "figure[data-figure]" }];
|
||||
},
|
||||
|
||||
renderHTML({ HTMLAttributes }) {
|
||||
const { src, alt, caption, placement } = HTMLAttributes;
|
||||
return [
|
||||
"figure",
|
||||
mergeAttributes({ "data-figure": "", "data-placement": placement }),
|
||||
["img", { src, alt }],
|
||||
["figcaption", {}, caption ?? ""],
|
||||
];
|
||||
},
|
||||
|
||||
addNodeView() {
|
||||
return ReactNodeViewRenderer(FigureView);
|
||||
},
|
||||
});
|
||||
Reference in new issue
Block a user