What is @tiptap/vue-2?
@tiptap/vue-2 is a renderless and extensible rich-text editor for Vue 2. It is built on top of ProseMirror and provides a highly customizable and flexible way to create rich-text editing experiences in Vue.js applications.
What are @tiptap/vue-2's main functionalities?
Basic Setup
This code sets up a basic Tiptap editor with the StarterKit extension, which includes common features like bold, italic, and bullet lists. The editor is rendered using the `EditorContent` and `EditorMenuBar` components.
```javascript
import Vue from 'vue';
import { EditorContent, EditorMenuBar, Editor } from '@tiptap/vue-2';
import StarterKit from '@tiptap/starter-kit';
new Vue({
el: '#app',
components: {
EditorContent,
EditorMenuBar
},
data() {
return {
editor: new Editor({
extensions: [StarterKit],
content: '<p>Hello World!</p>',
}),
};
},
beforeDestroy() {
this.editor.destroy();
},
template: `
<div>
<editor-menu-bar :editor="editor" />
<editor-content :editor="editor" />
</div>
`,
});
```
Custom Extensions
This code demonstrates how to create a custom extension for Tiptap. The `CustomExtension` is a simple block node that renders a `div` with a custom data attribute.
```javascript
import { Node, mergeAttributes } from '@tiptap/core';
const CustomExtension = Node.create({
name: 'customExtension',
group: 'block',
content: 'inline*',
parseHTML() {
return [
{
tag: 'div[data-type="customExtension"]',
},
];
},
renderHTML({ HTMLAttributes }) {
return ['div', mergeAttributes(HTMLAttributes, { 'data-type': 'customExtension' }), 0];
},
});
new Vue({
el: '#app',
data() {
return {
editor: new Editor({
extensions: [StarterKit, CustomExtension],
content: '<div data-type="customExtension">Custom Content</div>',
}),
};
},
beforeDestroy() {
this.editor.destroy();
},
template: `
<div>
<editor-content :editor="editor" />
</div>
`,
});
```
Using Plugins
This code shows how to add a custom ProseMirror plugin to the Tiptap editor. The `customPlugin` logs a message to the console whenever the Enter key is pressed.
```javascript
import { Plugin } from 'prosemirror-state';
const customPlugin = new Plugin({
props: {
handleKeyDown(view, event) {
if (event.key === 'Enter') {
console.log('Enter key pressed');
return true;
}
return false;
},
},
});
new Vue({
el: '#app',
data() {
return {
editor: new Editor({
extensions: [StarterKit],
content: '<p>Press Enter</p>',
plugins: [customPlugin],
}),
};
},
beforeDestroy() {
this.editor.destroy();
},
template: `
<div>
<editor-content :editor="editor" />
</div>
`,
});
```
Other packages similar to @tiptap/vue-2
quill
Quill is a modern WYSIWYG editor built for compatibility and extensibility. It provides a rich API and a wide range of features out of the box. Compared to @tiptap/vue-2, Quill is more opinionated and less flexible in terms of customization and extending functionality.
slate
Slate is a completely customizable framework for building rich text editors. It provides a lot of flexibility and control over the editor's behavior and appearance. Slate is more low-level compared to @tiptap/vue-2, requiring more effort to set up and customize.
draft-js
Draft.js is a framework for building rich text editors in React, developed by Facebook. It offers a lot of control and customization options. However, it is React-specific and may require more boilerplate code compared to @tiptap/vue-2.
@tiptap/vue-2
Introduction
tiptap is a headless wrapper around ProseMirror – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as New York Times, The Guardian or Atlassian.
Official Documentation
Documentation can be found on the tiptap website.
License
tiptap is open sourced software licensed under the MIT license.