Created
July 20, 2022 15:29
-
-
Save seeARMS/e41f35064ba3a6550420e5f2b27b2e84 to your computer and use it in GitHub Desktop.
Tweet node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mergeAttributes, Node } from "@tiptap/core" | |
import { ReactNodeViewRenderer } from "@tiptap/react" | |
import Component from "./StaticTwitter" | |
export default Node.create({ | |
name: "tweet-embed", | |
group: "block", | |
addAttributes() { | |
return { | |
tweetId: { | |
default: "", | |
parseHTML: (element) => element.getAttribute("data-tweetId"), | |
renderHTML: (attributes) => { | |
return { | |
"data-tweetId": attributes.tweetId, | |
} | |
}, | |
}, | |
} | |
}, | |
parseHTML() { | |
return [ | |
{ | |
tag: "tweet-embed", | |
}, | |
] | |
}, | |
renderHTML(props) { | |
return ["tweet-embed", mergeAttributes(props.HTMLAttributes)] | |
}, | |
addNodeView() { | |
console.log("Adding node view!") | |
return ReactNodeViewRenderer(Component) | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment