tiptap/docs/overview/upgrade-guide.md

200 lines
8.6 KiB
Markdown
Raw Normal View History

---
tableOfContents: true
---
# Upgrade Guide
## Introduction
2021-10-20 04:30:45 +08:00
First of all, Tiptap v1 isnt supported anymore and wont receive any further updates.
2021-09-29 05:35:40 +08:00
Yes, its tedious work to upgrade your favorite text editor to a new API, but we made sure youve got enough reasons to upgrade to the newest version.
2020-09-09 21:57:30 +08:00
2020-11-03 23:13:13 +08:00
* Autocompletion in your IDE (thanks to TypeScript)
2021-09-29 05:35:40 +08:00
* Amazing documentation with 100+ pages and 100+ interactive examples
* Active development, new features in the making, new releases every week
* Tons of new extensions
2020-09-22 21:45:57 +08:00
* Well-tested code base
2020-09-09 21:57:30 +08:00
2021-01-26 07:51:14 +08:00
The new API will look pretty familiar to you, but there are a ton of changes though. To make the upgrade a little bit easier, here is everything you need to know:
2020-09-16 03:07:16 +08:00
2021-10-20 04:30:45 +08:00
## Uninstall Tiptap v1
The whole package structure has changed, we even moved to another npm namespace, so youll need to remove the old version entirely before upgrading to Tiptap 2.
2020-12-15 22:13:07 +08:00
Otherwise youll run into an exception, for example “looks like multiple versions of prosemirror-model were loaded”.
```bash
# with npm
2021-10-20 04:30:45 +08:00
npm uninstall Tiptap Tiptap-commands Tiptap-extensions Tiptap-utils
2020-12-15 22:13:07 +08:00
# with Yarn
2021-10-20 04:30:45 +08:00
yarn remove Tiptap Tiptap-commands Tiptap-extensions Tiptap-utils
2020-12-15 22:13:07 +08:00
```
2021-10-20 04:30:45 +08:00
## Install Tiptap v2
2021-10-20 04:30:45 +08:00
Once you have uninstalled the old version of Tiptap, install the new Vue 2 package and the starter kit:
2021-09-29 05:35:40 +08:00
```bash
# install with npm
2021-04-22 23:47:53 +08:00
npm install @tiptap/vue-2 @tiptap/starter-kit
# install with Yarn
2021-04-22 23:47:53 +08:00
yarn add @tiptap/vue-2 @tiptap/starter-kit
```
2021-10-20 04:30:45 +08:00
## Keep Tiptap v2 up to date
We are constantly releasing updates to Tiptap. Did you know theres an easy-to-use command to update your dependencies with Yarn?
2021-09-29 05:35:40 +08:00
```bash
yarn upgrade-interactive
```
You can add the `--latest` flag, to show all possible upgrades even if they dont follow the versioning youve set in your package.json.
```bash
yarn upgrade-interactive --latest
```
## Explicitly register the Document, Text and Paragraph extensions
2021-01-26 07:51:14 +08:00
tiptap 1 tried to hide a few required extensions from you with the default setting `useBuiltInExtensions: true`. That setting has been removed and youre required to import all extensions. Be sure to explicitly import at least the [`Document`](/api/nodes/document), [`Paragraph`](/api/nodes/paragraph) and [`Text`](/api/nodes/text) extensions.
2020-09-15 23:26:27 +08:00
```js
import Document from '@tiptap/extension-document'
import Paragraph from '@tiptap/extension-paragraph'
import Text from '@tiptap/extension-text'
new Editor({
extensions: [
2020-11-16 17:03:12 +08:00
Document,
Paragraph,
Text,
2020-11-05 22:11:24 +08:00
// all your other extensions
2021-04-20 16:13:43 +08:00
],
2020-09-15 23:26:27 +08:00
})
```
And we removed some settings: `dropCursor`, `enableDropCursor`, and `enableGapCursor`. Those are separate extensions now: [`Dropcursor`](/api/extensions/dropcursor) and [`Gapcursor`](/api/extensions/gapcursor). You probably want to load them, but if you dont, just ignore this.
2021-01-13 22:49:08 +08:00
## New names for most extensions
We switched to lowerCamelCase, so theres a lot type names that changed. If you stored your content as JSON you need to loop through it and rename them. Sorry for that one.
2021-01-13 23:06:02 +08:00
| Old type | New type |
| --------------------- | ---------------------- |
| ~~`bullet_list`~~ | `bulletList` |
| ~~`code_block`~~ | `codeBlock` |
| ~~`hard_break`~~ | `hardBreak` |
| ~~`horizontal_rule`~~ | `horizontalRule` |
| ~~`list_item`~~ | `listItem` |
2021-01-13 23:06:02 +08:00
| ~~`ordered_list`~~ | `orderedList` |
| ~~`table_cell`~~ | `tableCell` |
| ~~`table_header`~~ | `tableHeader` |
| ~~`table_row`~~ | `tableRow` |
2021-01-13 23:06:02 +08:00
| ~~`todo_list`~~ | `taskList` (new name!) |
| ~~`todo_item`~~ | `taskItem` (new name!) |
2020-09-09 21:57:30 +08:00
## Removed methods
2021-01-13 22:49:08 +08:00
We removed the `.state()` method. No worries though, its still available through `editor.state`.
2020-11-18 00:10:48 +08:00
## New extension API
2020-09-22 21:45:57 +08:00
In case youve built some custom extensions for your project, youre required to rewrite them to fit the new API. No worries, you can keep a lot of your work though. The `schema`, `commands`, `keys`, `inputRules` and `pasteRules` all work like they did before. Its just different how you register them.
2020-09-09 21:57:30 +08:00
```js
import { Node } from '@tiptap/core'
2020-10-28 23:32:06 +08:00
const CustomExtension = Node.create({
2021-09-06 20:52:03 +08:00
name: 'custom_extension',
2020-10-28 23:32:06 +08:00
defaultOptions: {
},
addAttributes() {
},
parseHTML() {
},
2020-11-16 17:03:12 +08:00
renderHTML({ node, HTMLAttributes }) {
2020-10-28 23:32:06 +08:00
},
addCommands() {
},
addKeyboardShortcuts() {
},
addInputRules() {
},
// and more …
})
```
2021-04-07 05:36:07 +08:00
Read more about [all the nifty details building custom extensions](/guide/custom-extensions) in our guide.
2020-09-22 21:45:57 +08:00
## Renamed settings and methods
2020-11-17 22:47:39 +08:00
[We renamed a lot of settings and methods](/api/editor). Hopefully you can migrate to the new API with search & replace. Here is a list of what changed:
2020-09-16 23:01:47 +08:00
2020-11-17 22:47:39 +08:00
| Old name | New name |
| --------------- | ----------- |
| ~~`autoFocus`~~ | `autofocus` |
2020-09-16 23:01:47 +08:00
## Renamed commands
2021-01-13 22:49:08 +08:00
All new extensions come with specific commands to set, unset and toggle styles. So instead of `.bold()`, its now `.toggleBold()`. Also, we switched to lowerCamelCase, below are a few examples. Oh, and we renamed `todo_list`, to `taskList`, sorry for that one.
2021-01-13 23:06:02 +08:00
| Old command | New command |
| ------------------------ | ------------------------------- |
| `.redo()` | `.redo()` (nothing changed) |
| `.undo()` | `.undo()` (nothing changed) |
| ~~`.todo_list()`~~ | `.toggleTaskList()` (new name!) |
| ~~`.blockquote()`~~ | `.toggleBlockquote()` |
| ~~`.bold()`~~ | `.toggleBold()` |
| ~~`.bullet_list()`~~ | `.toggleBulletList()` |
| ~~`.code()`~~ | `.toggleCode()` |
| ~~`.code_block()`~~ | `.toggleCodeBlock()` |
| ~~`.hard_break()`~~ | `.setHardBreak()` |
2021-01-13 23:06:02 +08:00
| ~~`.heading()`~~ | `.toggleHeading()` |
| ~~`.horizontal_rule()`~~ | `.setHorizontalRule()` |
2021-01-13 23:06:02 +08:00
| ~~`.italic()`~~ | `.toggleItalic()` |
| ~~`.link()`~~ | `.toggleLink()` |
| ~~`.ordered_list()`~~ | `.toggleOrderedList()` |
| ~~`.paragraph()`~~ | `.setParagraph()` |
2021-01-13 23:06:02 +08:00
| ~~`.strike()`~~ | `.toggleStrike()` |
| ~~`.underline()`~~ | `.toggleUnderline()` |
| … | … |
2021-01-13 22:49:08 +08:00
## MenuBar, BubbleMenu and FloatingMenu
2021-04-03 21:21:30 +08:00
Read the dedicated [guide on creating menus](/guide/menus) to migrate your menus.
## Commands can be chained now
2020-11-12 22:31:44 +08:00
Most commands can be combined to one call now. Thats shorter than separate function calls in most cases. Here is an example to make the selected text bold:
2020-09-24 21:44:03 +08:00
2020-11-12 22:31:44 +08:00
```js
2020-11-18 04:47:39 +08:00
editor.chain().toggleBold().focus().run()
2020-11-12 22:31:44 +08:00
```
2021-10-20 04:30:45 +08:00
The `.chain()` is required to start a new chain and the `.run()` is needed to actually execute all the commands in between. Read more about [the new Tiptap commands](/api/commands) in our API documentation.
2020-09-24 21:44:03 +08:00
## .focus() isnt called on every command anymore
2021-10-20 04:30:45 +08:00
We tried to hide the `.focus()` command from you with Tiptap 1 and executed that on every command. That led to issues in specific use cases, where you want to run a command, but dont want to focus the editor.
2020-11-12 22:31:44 +08:00
2021-10-20 04:30:45 +08:00
With Tiptap v2 you have to explicitly call the `focus()` and you probably want to do that in a lot of places. Here is an example:
2020-09-16 23:01:47 +08:00
```js
2020-11-18 04:47:39 +08:00
editor.chain().focus().toggleBold().run()
2020-09-16 23:01:47 +08:00
```
2020-11-12 22:31:44 +08:00
## Event callbacks have fewer parameters
2021-01-13 23:06:02 +08:00
The new event callbacks have fewer parameters. The same things should be available through `this.` now. [Read more about events here.](/api/events)
## Collaborative editing
2021-10-20 04:30:45 +08:00
The reference implementation for collaborative editing uses Y.js now. Thats a whole different thing. You still can use the Tiptap 1 extension, but its up to you to adapt it to the new extension API. If youve done this, dont forget to share it with us so we can link to it from here!
2020-11-12 22:31:44 +08:00
Read more about [the new collaborative editing experience](/guide/collaborative-editing) in our guide.
## Marks dont support node view anymore
2021-10-20 04:30:45 +08:00
For marks, node views are [not well supported in ProseMirror](https://discuss.prosemirror.net/t/there-is-a-bug-in-marks-nodeview/2722/2). There is also [a related issue](https://github.com/ueberdosis/tiptap/issues/613) for Tiptap 1. Thats why we removed it in Tiptap 2.
2021-04-16 03:48:19 +08:00
## Become a sponsor
2021-10-20 04:30:45 +08:00
tiptap wouldnt exist without the funding of its community. If you fell in love with Tiptap, dont forget to [become a sponsor](/sponsor) and make the maintenance, development and support sustainable.
2020-11-12 22:31:44 +08:00
2021-02-06 03:37:09 +08:00
In exchange, well take you into our hearts, invite you to private repositories, add a `sponsor ♥` label to your issues and pull requests and more.