remove gridsome
This commit is contained in:
132
docs/installation/alpine.md
Normal file
132
docs/installation/alpine.md
Normal file
@@ -0,0 +1,132 @@
|
||||
---
|
||||
title: Alpine WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Alpine.js
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [Alpine.js](https://github.com/alpinejs/alpine) project.
|
||||
|
||||
For the sake of this guide we’ll use [Vite](https://vitejs.dev/) to quickly set up a project, but you can use whatever you’re used to. Vite is just really fast and we love it.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* Experience with [Alpine.js](https://github.com/alpinejs/alpine)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing Alpine.js project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh [Vite](https://vitejs.dev/) project called `tiptap-example`. Vite sets up everything we need, just select the Vanilla JavaScript template.
|
||||
|
||||
```bash
|
||||
npm init vite@latest tiptap-example -- --template vanilla
|
||||
cd tiptap-example
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need `alpinejs`, the `@tiptap/core` package and the `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install alpinejs @tiptap/core @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add alpinejs @tiptap/core @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1, you can now start your project with `npm run dev` or `yarn dev`, and open [http://localhost:3000](http://localhost:3000) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Initialize the editor
|
||||
To actually start using tiptap, you’ll need to write a little bit of JavaScript. Let’s put the following example code in a file called `main.js`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with Alpine.js. It will give you a very basic version of tiptap. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```js
|
||||
import Alpine from 'alpinejs'
|
||||
import { Editor } from '@tiptap/core'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
window.setupEditor = function(content) {
|
||||
return {
|
||||
editor: null,
|
||||
content: content,
|
||||
updatedAt: Date.now(), // force Alpine to rerender on selection change
|
||||
init(element) {
|
||||
this.editor = new Editor({
|
||||
element: element,
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
content: this.content,
|
||||
onUpdate: ({ editor }) => {
|
||||
this.content = editor.getHTML()
|
||||
},
|
||||
onSelectionUpdate: () => {
|
||||
this.updatedAt = Date.now()
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
window.Alpine = Alpine
|
||||
Alpine.start()
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of the `index.html` with the following example code to use the editor in our app.
|
||||
|
||||
```html
|
||||
<!-- index.html -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<div x-data="setupEditor('<p>Hello World! :-)</p>')" x-init="() => init($refs.element)">
|
||||
|
||||
<template x-if="editor">
|
||||
<div class="menu">
|
||||
<button
|
||||
@click="editor.chain().toggleHeading({ level: 1 }).focus().run()"
|
||||
:class="{ 'is-active': editor.isActive('heading', { level: 1 }) }"
|
||||
>
|
||||
H1
|
||||
</button>
|
||||
<button
|
||||
@click="editor.chain().toggleBold().focus().run()"
|
||||
:class="{ 'is-active': editor.isActive('bold') }"
|
||||
>
|
||||
Bold
|
||||
</button>
|
||||
<button
|
||||
@click="editor.chain().toggleItalic().focus().run()"
|
||||
:class="{ 'is-active': editor.isActive('italic') }"
|
||||
>
|
||||
Italic
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div x-ref="element"></div>
|
||||
</div>
|
||||
|
||||
<script type="module" src="/main.js"></script>
|
||||
|
||||
<style>
|
||||
body { margin: 2rem; font-family: sans-serif; }
|
||||
button.is-active { background: black; color: white; }
|
||||
.ProseMirror { padding: 0.5rem 1rem; margin: 1rem 0; border: 1px solid #ccc; }
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
27
docs/installation/cdn.md
Normal file
27
docs/installation/cdn.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# CDN
|
||||
For testing purposes or demos, use our [Skypack](https://www.skypack.dev/) CDN builds. Here are the few lines of code you need to get started:
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<div class="element"></div>
|
||||
<script type="module">
|
||||
import { Editor } from 'https://cdn.skypack.dev/@tiptap/core?min'
|
||||
import StarterKit from 'https://cdn.skypack.dev/@tiptap/starter-kit?min'
|
||||
const editor = new Editor({
|
||||
element: document.querySelector('.element'),
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
content: '<p>Hello World!</p>',
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
14
docs/installation/codesandbox.md
Normal file
14
docs/installation/codesandbox.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# CodeSandbox
|
||||
CodeSandbox is an online coding environment. It’s great to fiddle around without setting up a local project. You can also use it to share your code and collaborate with others.
|
||||
|
||||
<iframe
|
||||
src="https://codesandbox.io/embed/tiptap-issue-template-b83rr?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fcomponents%2FTiptap.vue&theme=dark"
|
||||
style="width:100%; height:400px; border:0; border-radius: 4px; overflow:hidden;"
|
||||
title="tiptap-issue-template"
|
||||
sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts"
|
||||
></iframe>
|
||||
|
||||
## Issue template
|
||||
It’s also amazing for bug reports. Try to recreate a bug there and share it with us before you [file an issue on GitHub](https://github.com/ueberdosis/tiptap/issues/new/choose).
|
||||
|
||||
That helps us to reproduce the bug easily, and release a fix faster.
|
||||
82
docs/installation/livewire.md
Normal file
82
docs/installation/livewire.md
Normal file
@@ -0,0 +1,82 @@
|
||||
---
|
||||
title: Livewire WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Livewire
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [Livewire](https://laravel-livewire.com/) project.
|
||||
|
||||
TODO
|
||||
|
||||
## editor.blade.php
|
||||
```html
|
||||
<!--
|
||||
In your livewire component you could add an
|
||||
autosave method to handle saving the content
|
||||
from the editor every 10 seconds if you wanted
|
||||
-->
|
||||
<x-editor
|
||||
wire:model="foo"
|
||||
wire:poll.10000ms="autosave"
|
||||
></x-editor>
|
||||
```
|
||||
|
||||
## my-livewire-component.blade.php
|
||||
```html
|
||||
<div
|
||||
x-data="setupEditor(
|
||||
$wire.entangle('{{ $attributes->wire('model') }}').defer
|
||||
)"
|
||||
x-init="() => init($refs.editor)"
|
||||
wire:ignore
|
||||
{{ $attributes->whereDoesntStartWith('wire:model') }}
|
||||
>
|
||||
<div x-ref="editor"></div>
|
||||
</div>
|
||||
```
|
||||
|
||||
## index.js
|
||||
```js
|
||||
import { Editor } from '@tiptap/core'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
window.setupEditor = function (content) {
|
||||
return {
|
||||
editor: null,
|
||||
content: content,
|
||||
|
||||
init(element) {
|
||||
this.editor = new Editor({
|
||||
element: element,
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
content: this.content,
|
||||
onUpdate: ({ editor }) => {
|
||||
this.content = editor.getHTML()
|
||||
}
|
||||
})
|
||||
|
||||
this.$watch('content', (content) => {
|
||||
// If the new content matches TipTap's then we just skip.
|
||||
if (content === this.editor.getHTML()) return
|
||||
|
||||
/*
|
||||
Otherwise, it means that a force external to TipTap
|
||||
is modifying the data on this Alpine component,
|
||||
which could be Livewire itself.
|
||||
In this case, we just need to update TipTap's
|
||||
content and we're good to do.
|
||||
For more information on the `setContent()` method, see:
|
||||
https://www.tiptap.dev/api/commands/set-content
|
||||
*/
|
||||
this.editor.commands.setContent(content, false)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
104
docs/installation/nuxt.md
Normal file
104
docs/installation/nuxt.md
Normal file
@@ -0,0 +1,104 @@
|
||||
---
|
||||
title: Nuxt.js WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Nuxt.js
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [Nuxt.js](https://nuxtjs.org/) project.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* Experience with [Vue](https://vuejs.org/v2/guide/#Getting-Started)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing Vue project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh Nuxt.js project called `tiptap-example`. The following command sets up everything we need. It asks a lot of questions, but just use what floats your boat or use the defaults.
|
||||
|
||||
```bash
|
||||
# create a project
|
||||
npm init nuxt-app tiptap-example
|
||||
|
||||
# change directory
|
||||
cd tiptap-example
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need the `@tiptap/vue-2` package, with a few components, and `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/vue-2 @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/vue-2 @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1 and 2, you can now start your project with `npm run serve` or `yarn serve`, and open [http://localhost:8080/](http://localhost:8080/) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Create a new component
|
||||
To actually start using tiptap, you’ll need to add a new component to your app. Let’s call it `Tiptap` and put the following example code in `src/components/Tiptap.vue`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with Vue. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent } from '@tiptap/vue-2'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
content: '<p>I’m running tiptap with Vue.js. 🎉</p>',
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
})
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of `pages/index.vue` with the following example code to use our new `Tiptap` component in our app.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div id="app">
|
||||
<client-only>
|
||||
<tiptap />
|
||||
</client-only>
|
||||
</div>
|
||||
</template>
|
||||
```
|
||||
|
||||
Note that tiptap needs to run in the client, not on the server. It’s required to wrap the editor in a `<client-only>` tag. [Read more about cient-only components.](https://nuxtjs.org/api/components-client-only)
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
|
||||
## 5. Use v-model (optional)
|
||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with tiptap. Here is a working example component, that you can integrate in your project:
|
||||
|
||||
<tiptap-demo name="GuideGettingStarted/VModel"></tiptap-demo>
|
||||
90
docs/installation/react.md
Normal file
90
docs/installation/react.md
Normal file
@@ -0,0 +1,90 @@
|
||||
---
|
||||
title: React WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# React
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [React](https://reactjs.org/) project.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* Experience with [React](https://reactjs.org/docs/getting-started.html)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing React project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh React project called `tiptap-example`. [*Create React App*](https://reactjs.org/docs/getting-started.html) sets up everything we need.
|
||||
|
||||
```bash
|
||||
# create a project
|
||||
npx create-react-app tiptap-example
|
||||
|
||||
# change directory
|
||||
cd tiptap-example
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need the `@tiptap/react` package, with a few components, and `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/react @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/react @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1 and 2, you can now start your project with `npm run start` or `yarn start`, and open [http://localhost:3000](http://localhost:3000) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Create a new component
|
||||
To actually start using tiptap, you’ll need to add a new component to your app. Let’s call it `Tiptap` and put the following example code in `src/Tiptap.jsx`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with React. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```jsx
|
||||
import { useEditor, EditorContent } from '@tiptap/react'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
const Tiptap = () => {
|
||||
const editor = useEditor({
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
content: '<p>Hello World! 🌎️</p>',
|
||||
})
|
||||
|
||||
return (
|
||||
<EditorContent editor={editor} />
|
||||
)
|
||||
}
|
||||
|
||||
export default Tiptap
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of `src/App.js` with the following example code to use our new `Tiptap` component in our app.
|
||||
|
||||
```jsx
|
||||
import Tiptap from './Tiptap.jsx'
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<div className="App">
|
||||
<Tiptap />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
|
||||
## 5. The complete setup (optional)
|
||||
Ready to add more? Below is a demo that shows how you could set up what we call the default editor. Feel free to take this and start customizing it then:
|
||||
|
||||
<tiptap-demo name="Examples/Default"></tiptap-demo>
|
||||
122
docs/installation/svelte.md
Normal file
122
docs/installation/svelte.md
Normal file
@@ -0,0 +1,122 @@
|
||||
---
|
||||
title: Svelte WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Svelte
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [SvelteKit](https://kit.svelte.dev/) project.
|
||||
|
||||
## Take a shortcut: Svelte REPL with tiptap
|
||||
If you just want to jump into it right-away, here is a [Svelte REPL with tiptap](https://svelte.dev/repl/798f1b81b9184780aca18d9a005487d2?version=3.31.2) installed.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* Experience with [Svelte](https://vuejs.org/v2/guide/#Getting-Started)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing SvelteKit project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh SvelteKit project called `tiptap-example`. The following commands set up everything we need. It asks a lot of questions, but just use what floats your boat or use the defaults.
|
||||
|
||||
```bash
|
||||
mkdir tiptap-example
|
||||
cd tiptap-example
|
||||
npm init svelte@next
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need the `@tiptap/core` package, with a few components, and `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/core @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/core @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1 and 2, you can now start your project with `npm run dev` or `yarn dev`, and open [http://localhost:3000/](http://localhost:3000/) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Create a new component
|
||||
To actually start using tiptap, you’ll need to add a new component to your app. Let’s call it `Tiptap` and put the following example code in `src/lib/Tiptap.svelte`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with SvelteKit. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import { onMount, onDestroy } from 'svelte'
|
||||
import { Editor } from '@tiptap/core'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
let element
|
||||
let editor
|
||||
|
||||
onMount(() => {
|
||||
editor = new Editor({
|
||||
element: element,
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
content: '<p>Hello World! 🌍️ </p>',
|
||||
onTransaction: () => {
|
||||
// force re-render so `editor.isActive` works as expected
|
||||
editor = editor
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
onDestroy(() => {
|
||||
if (editor) {
|
||||
editor.destroy()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if editor}
|
||||
<button
|
||||
on:click={() => editor.chain().focus().toggleHeading({ level: 1}).run()}
|
||||
class:active={editor.isActive('heading', { level: 1 })}
|
||||
>
|
||||
H1
|
||||
</button>
|
||||
<button
|
||||
on:click={() => editor.chain().focus().toggleHeading({ level: 2 }).run()}
|
||||
class:active={editor.isActive('heading', { level: 2 })}
|
||||
>
|
||||
H2
|
||||
</button>
|
||||
<button on:click={() => editor.chain().focus().setParagraph().run()} class:active={editor.isActive('paragraph')}>
|
||||
P
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
<div bind:this={element} />
|
||||
|
||||
<style>
|
||||
button.active {
|
||||
background: black;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of `src/routes/index.svelte` with the following example code to use our new `Tiptap` component in our app.
|
||||
|
||||
```html
|
||||
<script>
|
||||
import Tiptap from '$lib/Tiptap.svelte'
|
||||
</script>
|
||||
|
||||
<main>
|
||||
<Tiptap />
|
||||
</main>
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
112
docs/installation/vue2.md
Normal file
112
docs/installation/vue2.md
Normal file
@@ -0,0 +1,112 @@
|
||||
---
|
||||
title: Vue.js 2 WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Vue.js 2
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [Vue](https://vuejs.org/) CLI project.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* [Vue CLI](https://cli.vuejs.org/) installed on your machine
|
||||
* Experience with [Vue](https://vuejs.org/v2/guide/#Getting-Started)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing Vue project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh Vue project called `tiptap-example`. The Vue CLI sets up everything we need, just select the default Vue 2 template.
|
||||
|
||||
```bash
|
||||
# create a project
|
||||
vue create tiptap-example
|
||||
|
||||
# change directory
|
||||
cd tiptap-example
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need the `@tiptap/vue-2` package, with a few components, and `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/vue-2 @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/vue-2 @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1 and 2, you can now start your project with `npm run dev` or `yarn dev`, and open [http://localhost:8080](http://localhost:8080) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Create a new component
|
||||
To actually start using tiptap, you’ll need to add a new component to your app. Let’s call it `Tiptap` and put the following example code in `components/Tiptap.vue`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with Vue. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent } from '@tiptap/vue-2'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
content: '<p>I’m running tiptap with Vue.js. 🎉</p>',
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
})
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of `src/App.vue` with the following example code to use our new `Tiptap` component in our app.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div id="app">
|
||||
<tiptap />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Tiptap from './components/Tiptap.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
Tiptap
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
|
||||
## 5. Use v-model (optional)
|
||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with tiptap. Here is a working example component, that you can integrate in your project:
|
||||
|
||||
<tiptap-demo name="GuideGettingStarted/VModel"></tiptap-demo>
|
||||
198
docs/installation/vue3.md
Normal file
198
docs/installation/vue3.md
Normal file
@@ -0,0 +1,198 @@
|
||||
---
|
||||
title: Vue.js 3 WYSIWYG
|
||||
tableOfContents: true
|
||||
---
|
||||
|
||||
# Vue.js 3
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
The following guide describes how to integrate tiptap with your [Vue](https://vuejs.org/) CLI project.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* [Vue CLI](https://cli.vuejs.org/) installed on your machine
|
||||
* Experience with [Vue](https://v3.vuejs.org/guide/introduction.html)
|
||||
|
||||
## 1. Create a project (optional)
|
||||
If you already have an existing Vue project, that’s fine too. Just skip this step and proceed with the next step.
|
||||
|
||||
For the sake of this guide, let’s start with a fresh Vue project called `tiptap-example`. The Vue CLI sets up everything we need, just select the Vue 3 template.
|
||||
|
||||
```bash
|
||||
# create a project
|
||||
vue create tiptap-example
|
||||
|
||||
# change directory
|
||||
cd tiptap-example
|
||||
```
|
||||
|
||||
## 2. Install the dependencies
|
||||
Okay, enough of the boring boilerplate work. Let’s finally install tiptap! For the following example you’ll need the `@tiptap/vue-3` package, with a few components, and `@tiptap/starter-kit` which has the most common extensions to get started quickly.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/vue-3 @tiptap/starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/vue-3 @tiptap/starter-kit
|
||||
```
|
||||
|
||||
If you followed step 1 and 2, you can now start your project with `npm run dev` or `yarn dev`, and open [http://localhost:8080](http://localhost:8080) in your favorite browser. This might be different, if you’re working with an existing project.
|
||||
|
||||
## 3. Create a new component
|
||||
To actually start using tiptap, you’ll need to add a new component to your app. Let’s call it `Tiptap` and put the following example code in `components/Tiptap.vue`.
|
||||
|
||||
This is the fastest way to get tiptap up and running with Vue. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent } from '@tiptap/vue-3'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
content: '<p>I’m running tiptap with Vue.js. 🎉</p>',
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
})
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
Alternatively, you can use the Composition API with the `useEditor` method.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useEditor, EditorContent } from '@tiptap/vue-3'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
setup() {
|
||||
const editor = useEditor({
|
||||
content: '<p>I’m running tiptap with Vue.js. 🎉</p>',
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
})
|
||||
|
||||
return { editor }
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
## 4. Add it to your app
|
||||
Now, let’s replace the content of `src/App.vue` with the following example code to use our new `Tiptap` component in our app.
|
||||
|
||||
```html
|
||||
<template>
|
||||
<div id="app">
|
||||
<tiptap />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Tiptap from './components/Tiptap.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
Tiptap
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
You should now see tiptap in your browser. Time to give yourself a pat on the back! :)
|
||||
|
||||
## 5. Use v-model (optional)
|
||||
You’re probably used to bind your data with `v-model` in forms, that’s also possible with tiptap. Here is how that would work with tiptap:
|
||||
|
||||
```html
|
||||
<template>
|
||||
<editor-content :editor="editor" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { Editor, EditorContent } from '@tiptap/vue-3'
|
||||
import StarterKit from '@tiptap/starter-kit'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
EditorContent,
|
||||
},
|
||||
|
||||
props: {
|
||||
modelValue: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
editor: null,
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
modelValue(value) {
|
||||
const isSame = this.editor.getHTML() === value
|
||||
|
||||
if (isSame) {
|
||||
return
|
||||
}
|
||||
|
||||
this.editor.commands.setContent(value, false)
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.editor = new Editor({
|
||||
content: this.modelValue,
|
||||
extensions: [
|
||||
StarterKit,
|
||||
],
|
||||
onUpdate: () => {
|
||||
this.$emit('update:modelValue', this.editor.getHTML())
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.editor.destroy()
|
||||
},
|
||||
}
|
||||
</script>
|
||||
```
|
||||
Reference in New Issue
Block a user