What is the difference between decoration and NodeView in tiptap?! #2865
-
So tiptap doesn't have decoration API. I'm kind of new to both tiptap and ProseMirror and can't completely distinguish decorations and NodeViews in my head. My definition of decorations is "things that are in the editor but not in the document". tiptap doesn't have decoration API but we can get kind of the same result using NodeViews.
Is that a correct mindset? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
In fact, you can create decoration with tiptap by using the
NodeViews force you to have a node in the schema. If you have a node in the schema, you NEED to render html for the browser or the Let's take the example of the placeholder extension: https://github.com/ueberdosis/tiptap/blob/main/packages/extension-placeholder/src/placeholder.ts. This extension is a decoration because you don't want a Another example, let's say you want a counter with the number of images in the current document, no need to create a node in the schema for that, just a decoration will do the trick. Difference is always subtle, the more you'll use them, the most you'll understand them. |
Beta Was this translation helpful? Give feedback.
-
@pointnet thanks for sharing this. However, is using the |
Beta Was this translation helpful? Give feedback.
In fact, you can create decoration with tiptap by using the
addProseMirrorPlugins
method onExtension.create
. This will be a prosemirror decoration so you won't be able to render react components easily.NodeViews force you to have a node in the schema. If you have a node in the schema, you NEED to render html for the browser or the
getHTML()
method, either a text node or a dom element.Let's take the example of the placeholder extension: https://github.com/ueberdosis/tiptap/blob/main/packages/extension-placeholder/src/placeholder.ts.
This extension is a decoration because you don't want a
<…