Merge branch 'main' of github.com:ueberdosis/tiptap-next into main
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# Events
|
||||
Events are a great way to run code when the editor has been initialized, the content has changed, the editor is in focus or the editor isn’t in focus anymore. There are two ways to add code that is executed at those events:
|
||||
|
||||
## Option 1: Use hooks
|
||||
## Option 1: Hook into events
|
||||
Hooks can be assigned to the editor on initialization. Pass a function that gets called in case of those events.
|
||||
|
||||
```js
|
||||
@@ -9,9 +9,8 @@ const editor = new Editor({
|
||||
onInit: () => {
|
||||
// the editor is ready
|
||||
},
|
||||
onUpdate: ({ html }) => {
|
||||
onUpdate: () => {
|
||||
// the content has been changed
|
||||
const newContent = html()
|
||||
},
|
||||
})
|
||||
```
|
||||
@@ -28,20 +27,31 @@ editor.on('init', () => {
|
||||
// the editor is ready
|
||||
})
|
||||
|
||||
editor.on('update', ({ html }) => {
|
||||
editor.on('update', () => {
|
||||
// the content has been changed
|
||||
const newContent = html()
|
||||
})
|
||||
```
|
||||
|
||||
### Unbind event listeners
|
||||
|
||||
```js
|
||||
const callback = () => {
|
||||
// the content has been changed
|
||||
}
|
||||
|
||||
editor.on('update', callback)
|
||||
editor.off('update', callback)
|
||||
```
|
||||
|
||||
## List of events
|
||||
| Event | Description | Parameters |
|
||||
| -------- | ----------------------------- | ------------------------------------ |
|
||||
| `blur` | Editor isn’t focused anymore. | `{ event, state, view }` |
|
||||
| `focus` | Editor is in focus. | `{ event, state, view }` |
|
||||
| `init` | Editor has been initialized. | `{ state, view }` |
|
||||
| `update` | Content has been changed. | `{ state, json, html, transaction }` |
|
||||
| `blur` | Editor isn’t focused anymore. | `{ event }` |
|
||||
| `focus` | Editor is in focus. | `{ event }` |
|
||||
| `init` | Editor has been initialized. | *None* |
|
||||
| `update` | Content has changed. | *None* |
|
||||
| `transaction` | State has changed. | `{ transaction }` |
|
||||
|
||||
:::info List of hooks
|
||||
The according hooks are called `onBlur`, `onFocus`, `onInit` and `onUpdate`.
|
||||
:::
|
||||
The according hooks are called `onBlur`, `onFocus`, `onInit`, `onUpdate` and `onTransaction`.
|
||||
:::
|
||||
|
||||
@@ -14,7 +14,7 @@ You can use `Mod` as a shorthand for `Cmd` on Mac and `Control` on other platfor
|
||||
import BulletList from '@tiptap/extension-bullet-list'
|
||||
|
||||
// 2. Overwrite the keyboard shortcuts
|
||||
const CustomBulletList = new Node()
|
||||
const CustomBulletList = BulletList()
|
||||
.keys(({ editor }) => ({
|
||||
// ↓ your new keyboard shortcut
|
||||
'Mod-l': () => editor.bulletList(),
|
||||
|
||||
Reference in New Issue
Block a user