docs: update content

This commit is contained in:
Hans Pagel
2021-04-03 15:21:30 +02:00
parent 0e6c79a761
commit 4792fc3200
20 changed files with 256 additions and 135 deletions

View File

@@ -31,6 +31,26 @@ 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.
#### Chaining inside custom commands
When chaining a command, the transaction is held back. If you want to chain commands inside your custom commands, youll need to use said transaction and add to it. Here is how you would do that:
```js
addCommands() {
return {
insertTimecode: attributes => ({ chain }) => {
// Doesnt work:
// return editor.chain() …
// Does work:
return chain()
.insertNode('timecode', attributes)
.insertText(' ')
.run()
},
}
}
```
### Inline commands
In some cases, its helpful to put some more logic in a command. Thats why you can execute commands in commands. I know, that sounds crazy, but lets look at an example:
@@ -208,9 +228,26 @@ this.editor
.createParagraphNear()
.insertHTML('<p></p>')
.run()
``` -->
```
## Add your own commands
Add a custom command to insert a node.
```js
addCommands() {
return {
insertTimecode: attributes => ({ chain }) => {
return chain()
.focus()
.insertNode('timecode', attributes)
.insertText(' ')
.run();
},
}
},
```
-->
## Add custom commands
All extensions can add additional commands (and most do), check out the specific [documentation for the provided nodes](/api/nodes), [marks](/api/marks), and [extensions](/api/extensions) to learn more about those.
Of course, you can [add your custom extensions](/guide/build-extensions) with custom commands aswell.