mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-25 04:19:02 +08:00
Merge branch 'main' of https://github.com/ueberdosis/tiptap-next into main
This commit is contained in:
commit
7e2f7f7a0f
@ -18,7 +18,11 @@ While that’s perfectly fine and does make the selected bold, you’d likely wa
|
||||
Most commands can be combined to one call. That’s shorter than separate function calls in most cases. Here is an example to make the selected text bold:
|
||||
|
||||
```js
|
||||
editor.chain().bold().focus().run()
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.bold()
|
||||
.run()
|
||||
```
|
||||
|
||||
The `.chain()` is required to start a new chain and the `.run()` is needed to actually execute all the commands in between.
|
||||
@ -27,17 +31,40 @@ In the example above two different commands are executed at once. When a user cl
|
||||
|
||||
All chained commands are kind of queued up. They are combined to one single transaction. That means, the content is only updated once, also the `update` event is only triggered once.
|
||||
|
||||
### Inline commands
|
||||
In some cases, it’s helpful to put some more logic in a command. That’s why you can execute commands in commands. I know, that sounds crazy, but let’s look at an example:
|
||||
|
||||
```js
|
||||
editor
|
||||
.chain()
|
||||
.focus()
|
||||
.command(({ tr }) => {
|
||||
// manipulate the transaction
|
||||
tr.insertText('hey, that’s cool!')
|
||||
|
||||
return true
|
||||
})
|
||||
.run()
|
||||
```
|
||||
|
||||
### Dry run for commands
|
||||
Sometimes, you don’t want to actually run the commands, but only know if it would be possible to run commands, for example to show or hide buttons in a menu. That’s what we added `.can()` for. Everything coming after this method will be executed, without applying the changes to the document:
|
||||
|
||||
```js
|
||||
editor.can().bold()
|
||||
editor
|
||||
.can()
|
||||
.bold()
|
||||
```
|
||||
|
||||
And you can use it together with `.chain()`, too. Here is an example which checks if it’s possible to apply all the commands:
|
||||
|
||||
```js
|
||||
editor.can().chain().bold().italic().run()
|
||||
editor
|
||||
.can()
|
||||
.chain()
|
||||
.bold()
|
||||
.italic()
|
||||
.run()
|
||||
```
|
||||
|
||||
Both calls would return `true` if it’s possible to apply the commands, and `false` in case it’s not.
|
||||
|
@ -1,81 +0,0 @@
|
||||
# Get started
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
tiptap 2 is framework-agnostic and even works with plain JavaScript, if that’s your thing. As the previous major version required Vue.js, we decided to focus on Vue.js in the first version of this guide. That said, it’s probably also helpful for developers who work with different technologies.
|
||||
|
||||
Let’s take a few basic building blocks for a test drive.
|
||||
|
||||
## Requirements
|
||||
The following guide assumes you’re working with Vue.js. Hopefully, that helps to get you going with other frameworks (or without a framework at all), while we’re working on more guides. We also assume you’ve [set up Node.js](https://nodejs.org/en/download/) on your machine already.
|
||||
|
||||
## 1. Create a new project
|
||||
|
||||
### Install Vue CLI (optional)
|
||||
```bash
|
||||
# with npm
|
||||
npm install -g @vue/cli
|
||||
# with Yarn
|
||||
yarn global add @vue/cli
|
||||
```
|
||||
|
||||
Let’s start with a fresh Vue.js project. If you already have an existing Vue.js project, that’s fine too. Just skip this first step and proceed with the next step.
|
||||
|
||||
### Create a project (optional)
|
||||
Pick *Default ([Vue 2] babel, eslint)*
|
||||
|
||||
```bash
|
||||
# create a project
|
||||
vue create tiptap-example
|
||||
|
||||
# change directory
|
||||
cd tiptap-example
|
||||
```
|
||||
|
||||
### Install the dependencies
|
||||
You can install tiptap for Vue.js as a dependency in your project:
|
||||
|
||||
```bash
|
||||
# install the Vue.js adapter with npm
|
||||
npm install @tiptap/core @tiptap/vue-starter-kit
|
||||
|
||||
# or: install the Vue.js adapter with Yarn
|
||||
yarn add @tiptap/core @tiptap/vue-starter-kit
|
||||
```
|
||||
|
||||
The `@tiptap/vue-starter-kit` includes a few basics you would probably need anyway. Cool, you have got everything in place to start fiddling around with tiptap! 🙌
|
||||
|
||||
Start your project with `$ yarn serve` or `$ npm run serve`. Open [http://localhost:8080/](http://localhost:8080/) in your favorite browser.
|
||||
|
||||
## 2. Create a new component
|
||||
Create a new Vue component (you can call it `<tiptap />`) and add the following content. This is the fastest way to get tiptap up and running with Vue.js. It will give you a very basic version of tiptap, without any buttons. No worries, you will be able to add more functionality soon.
|
||||
|
||||
<demo name="Guide/GettingStarted" />
|
||||
|
||||
## 3. Add it to your app
|
||||
|
||||
```js
|
||||
<template>
|
||||
<div id="app">
|
||||
<tiptap />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Tiptap from './components/Tiptap.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
Tiptap
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
|
||||
::: warning Nuxt.js
|
||||
If you use Nuxt.js, 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.
|
||||
:::
|
||||
|
||||
Congrats! You’ve got it! 🎉 Let’s start to configure your editor in the next step.
|
85
docs/src/docPages/guide/getting-started.md
Normal file
85
docs/src/docPages/guide/getting-started.md
Normal file
@ -0,0 +1,85 @@
|
||||
# Getting started
|
||||
|
||||
## toc
|
||||
|
||||
## Introduction
|
||||
tiptap 2 is framework-agnostic and even works with plain JavaScript, if that’s your thing. As the previous major version required Vue, we decided to focus on Vue in the first version of this guide. That said, it’s probably helpful for developers who work with different technologies too.
|
||||
|
||||
## Requirements
|
||||
* [Node](https://nodejs.org/en/download/) installed on your machine
|
||||
* Experience with [Vue](https://vuejs.org/v2/guide/#Getting-Started)
|
||||
|
||||
## 1. Install Vue CLI (optional)
|
||||
Vue CLI aims to be the standard tooling baseline for the Vue ecosystem, and helps to create new projects quickly. If you’re working with Vue a lot, chances are you have this installed already. Just skip this step then.
|
||||
|
||||
Here is how you could install (or update) it:
|
||||
|
||||
```bash
|
||||
# with npm
|
||||
npm install -g @vue/cli
|
||||
|
||||
# with Yarn
|
||||
yarn global add @vue/cli
|
||||
```
|
||||
|
||||
From now on, the `vue` command is available globally. Test it with `vue --version`, this should output the current version.
|
||||
|
||||
## 2. 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
|
||||
```
|
||||
|
||||
## 3. 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` (the actual editor) and the `@tiptap/vue-starter-kit` which has everything to get started quickly, for example a few default extensions and a basic Vue component.
|
||||
|
||||
```bash
|
||||
# install with npm
|
||||
npm install @tiptap/core @tiptap/vue-starter-kit
|
||||
|
||||
# install with Yarn
|
||||
yarn add @tiptap/core @tiptap/vue-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.
|
||||
|
||||
## 4. 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.
|
||||
|
||||
<demo name="Guide/GettingStarted" />
|
||||
|
||||
## 5. 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.
|
||||
|
||||
```js
|
||||
<template>
|
||||
<div id="app">
|
||||
<tiptap />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Tiptap from './components/Tiptap.vue'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
components: {
|
||||
Tiptap
|
||||
}
|
||||
}
|
||||
</script>
|
||||
```
|
||||
::: warning Nuxt.js
|
||||
If you use Nuxt.js, 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.
|
||||
:::
|
||||
|
||||
You should now see tiptap in your browser. You’ve successfully set up tiptap! Time to give yourself a pat on the back. Let’s start to configure your editor in the next step.
|
@ -10,13 +10,13 @@ Nothing here is production-ready, don’t use it anywhere.
|
||||
[![Version](https://img.shields.io/npm/v/@tiptap/core.svg?label=version)](https://www.npmjs.com/package/@tiptap/core)
|
||||
[![Downloads](https://img.shields.io/npm/dm/@tiptap/core.svg)](https://npmcharts.com/compare/@tiptap/core?minimal=true)
|
||||
[![License](https://img.shields.io/npm/l/@tiptap/core.svg)](https://www.npmjs.com/package/@tiptap/core)
|
||||
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
|
||||
<!-- [![Filesize](https://img.badgesize.io/https://unpkg.com/tiptap/dist/tiptap.min.js?compression=gzip&label=size&colorB=000000)](https://www.npmjs.com/package/tiptap) -->
|
||||
<!-- [![Build Status](https://github.com/ueberdosis/tiptap-next/workflows/build/badge.svg)](https://github.com/ueberdosis/tiptap-next/actions) -->
|
||||
[![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
|
||||
|
||||
tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – 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*.
|
||||
|
||||
Create exactly the rich text editor you want out of modular, and customizable building blocks. Tiptap comes with sensible defaults, many default extensions and a friendly API. It’s open source, free, and backed by a welcoming community.
|
||||
Create exactly the rich text editor you want out of modular, and customizable building blocks. tiptap comes with sensible defaults, a lot of extensions and a friendly API to customize every aspect. It’s backed by a welcoming community, open source, and free.
|
||||
|
||||
## Features
|
||||
**Headless.** We don’t tell you what a menu should look like or where it should be rendered in the DOM. That’s why tiptap is headless and comes without any CSS. You are in full control over markup and styling.
|
||||
@ -34,7 +34,7 @@ Create exactly the rich text editor you want out of modular, and customizable bu
|
||||
- [Nextcloud](https://apps.nextcloud.com/apps/text)
|
||||
- [DocIQ](https://www.dociq.io)
|
||||
- [Scrumpy](https://www.scrumpy.io)
|
||||
- [and many more →](https://github.com/ueberdosis/tiptap/network/dependents?package_id=UGFja2FnZS0xMzE5OTg0ODc%3D)
|
||||
- … and [many more](https://github.com/ueberdosis/tiptap/network/dependents?package_id=UGFja2FnZS0xMzE5OTg0ODc%3D)
|
||||
|
||||
## License
|
||||
tiptap is licensed under MIT, so you’re free to whatever you want. Anyway, we kindly ask you to [become a sponsor](https://github.com/sponsors/ueberdosis) on GitHub to fund the development, maintenance and support of tiptap.
|
||||
tiptap is licensed under MIT, so you’re free to whatever you want. Anyway, we kindly ask you to [become a sponsor](/sponsor) to fund the development, maintenance and support of tiptap.
|
||||
|
@ -41,9 +41,9 @@
|
||||
|
||||
- title: Guide
|
||||
items:
|
||||
- title: Get started
|
||||
link: /guide/get-started
|
||||
draft: true
|
||||
- title: Getting started
|
||||
link: /guide/getting-started
|
||||
new: true
|
||||
- title: Configure the editor
|
||||
link: /guide/configuration
|
||||
draft: true
|
||||
|
Loading…
Reference in New Issue
Block a user