Created
June 19, 2023 14:26
-
-
Save steveruizok/0a2466ad3c5adeb998756f5386c3267a to your computer and use it in GitHub Desktop.
tldraw x tiptap
This file contains hidden or 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 { Node, mergeAttributes } from "@tiptap/core"; | |
import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react"; | |
import { Tldraw } from "@tldraw/tldraw"; // use @tldraw/tldraw@canary | |
import "@tldraw/tldraw/tldraw.css"; | |
function Component() { | |
return ( | |
<NodeViewWrapper className="react-component"> | |
<div style={{ width: "100%", height: 500 }}> | |
<Tldraw /> | |
</div> | |
</NodeViewWrapper> | |
); | |
} | |
export const TldrawNode = Node.create({ | |
name: "tldraw", | |
group: "block", | |
atom: true, | |
addAttributes() { | |
return { | |
lines: { | |
default: [], | |
}, | |
}; | |
}, | |
parseHTML() { | |
return [ | |
{ | |
tag: 'div[data-type="tldraw"]', | |
}, | |
]; | |
}, | |
renderHTML({ HTMLAttributes }) { | |
return ["div", mergeAttributes(HTMLAttributes, { "data-type": "tldraw" })]; | |
}, | |
addNodeView() { | |
return ReactNodeViewRenderer(Component); | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment