tiptap/docs/overview/upgrade-guide.md

186 lines
8.2 KiB
Markdown
Raw Normal View History

---
tableOfContents: true
---
# Upgrade Guide
2020-09-15 23:26:27 +08:00
## Reasons to upgrade to tiptap 2.x
2020-09-22 21:45:57 +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)
2020-09-22 21:45:57 +08:00
* Amazing documentation with 100+ pages
* Active development, new features in the making
* Tons of new extensions planned
* Well-tested code base
2020-09-09 21:57:30 +08:00
2020-09-22 21:45:57 +08:00
## Upgrading from 1.x to 2.x
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
2020-12-15 22:13:07 +08:00
### Uninstall tiptap 1.x
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.
Otherwise youll run into an exception, for example “looks like multiple versions of prosemirror-model were loaded”.
```bash
# with npm
npm uninstall tiptap tiptap-commands tiptap-extensions tiptap-utils
# with Yarn
yarn remove tiptap tiptap-commands tiptap-extensions tiptap-utils
```
### Install tiptap 2.x
2021-04-24 03:43:21 +08:00
Once you have uninstalled the old version of tiptap, install the new Vue 2 package and the starter kit:
```
# 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
```
2020-09-30 22:16:15 +08:00
### 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
2021-01-13 23:06:02 +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
2020-11-18 00:10:48 +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
2020-09-30 22:16:15 +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
2020-11-17 22:47:39 +08:00
### Renamed settings and methods
[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
2021-01-13 22:49:08 +08:00
### Renamed commands
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
2021-04-03 21:21:30 +08:00
### MenuBar, BubbleMenu and FloatingMenu
Read the dedicated [guide on creating menus](/guide/menus) to migrate your menus.
2020-09-30 22:16:15 +08:00
### 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
```
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
2020-09-30 22:16:15 +08:00
### .focus() isnt called on every command anymore
2020-11-12 22:31:44 +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.
With tiptap 2.x 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
2021-01-13 23:06:02 +08:00
### Event callbacks have fewer parameters
The new event callbacks have fewer parameters. The same things should be available through `this.` now. [Read more about events here.](/api/events)
2020-11-12 22:31:44 +08:00
### Collaborative editing
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!
Read more about [the new collaborative editing experience](/guide/collaborative-editing) in our guide.
2021-04-16 03:48:19 +08:00
### Marks dont support node view anymore
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.
2020-11-12 22:31:44 +08:00
### Become a sponsor
2020-11-16 18:34:24 +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.