tiptap/docs/src/docPages/overview/upgrade-guide.md

93 lines
3.1 KiB
Markdown
Raw Normal View History

# Upgrade Guide
## toc
2020-09-27 16:29:01 +08:00
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
2020-09-16 03:07:16 +08:00
The new API will look pretty familiar too you, but there are a ton of changes though. To make the upgrade a little bit easier, here is everything you need to know:
### Upgrade to Vue.js 3
2020-09-30 22:16:15 +08:00
### Explicitly register the Document, Text and Paragraph extensions
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: [
Document(),
Paragraph(),
Text(),
2020-09-22 21:45:57 +08:00
// all your other extensions
2020-09-15 23:26:27 +08:00
]
})
```
2020-09-30 22:16:15 +08:00
### New document type
2020-10-28 23:32:06 +08:00
~~**We renamed the default `Document` type from `doc` to `document`.** To keep it like that, use your own implementation of the `Document` node or migrate the stored JSON to use the new name.~~
2020-09-09 21:57:30 +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
2020-10-28 23:32:06 +08:00
import { createNode } from '@tiptap/core'
const CustomExtension = createNode({
name: 'custom_extension'
defaultOptions: {
},
addAttributes() {
},
parseHTML() {
},
renderHTML({ node, attributes }) {
},
addCommands() {
},
addKeyboardShortcuts() {
},
addInputRules() {
},
// and more …
})
```
2020-10-29 20:13:27 +08:00
Dont forget to call `create()` in the end! Read more about [all the nifty details building custom extensions](/guide/build-custom-extensions) in our guide.
2020-09-22 21:45:57 +08:00
2020-09-30 22:16:15 +08:00
### Renamed API methods
2020-09-16 23:01:47 +08:00
[We renamed a lot of commands](/api/commands), hopefully you can migrate to the new API with search & replace. Here is a list of what changed:
| Old method name | New method name |
| --------------- | --------------- |
2020-10-28 23:32:06 +08:00
| ~~`…`~~ | `…` |
2020-09-16 23:01:47 +08:00
2020-09-30 22:16:15 +08:00
### Commands can be chained now
2020-09-24 21:44:03 +08:00
2020-09-30 22:16:15 +08:00
### .focus() isnt called on every command anymore
2020-09-16 23:01:47 +08:00
We tried to hide the `.focus()` command from you with tiptap 1 and executed that on every other 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:
```js
2020-09-22 15:08:08 +08:00
editor.chain().focus().bold().run()
2020-09-16 23:01:47 +08:00
```