docs: update content

This commit is contained in:
Philipp Kühn
2021-04-21 10:22:59 +02:00
parent 8fd618a788
commit 00fc1d1ae7

View File

@@ -37,7 +37,7 @@ When chaining a command, the transaction is held back. If you want to chain comm
```js
addCommands() {
return {
insertTimecode: attributes => ({ chain }) => {
customCommand: attributes => ({ chain }) => {
// Doesnt work:
// return editor.chain() …
@@ -94,7 +94,7 @@ In order to make that work with your custom commands, dont forget to return `
For some of your own commands, you probably want to work with the raw [transaction](/api/concept). To make them work with `.can()` you should check if the transaction should be dispatched. Here is how you can create a simple `.insertText()` command:
```js
export default (value: string): Command => ({ tr, dispatch }) => {
export default (value) => ({ tr, dispatch }) => {
if (dispatch) {
tr.insertText(value)
}
@@ -106,18 +106,22 @@ export default (value: string): Command => ({ tr, dispatch }) => {
If youre just wrapping another tiptap command, you dont need to check that, well do it for you.
```js
bold: (): Command => ({ commands }) => {
return commands.toggleMark('bold')
},
addCommands() {
return {
bold: () => ({ commands }) => {
return commands.toggleMark('bold')
},
}
}
```
If youre just wrapping a ProseMirror command, youll need to pass `dispatch` anyway. Then theres also no need to check it:
If youre just wrapping a plain ProseMirror command, youll need to pass `dispatch` anyway. Then theres also no need to check it:
```js
export default (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
import { exitCode } from 'prosemirror-commands'
return liftListItem(type)(state, dispatch)
export default () => ({ state, dispatch }) => {
return exitCode(state, dispatch)
}
```
@@ -137,11 +141,13 @@ editor.first(({ commands }) => [
Inside of commands you can do the same thing like that:
```js
commands.first([
() => commands.undoInputRule(),
() => commands.deleteSelection(),
// …
])
export default () => ({ commands }) => {
return commands.first([
() => commands.undoInputRule(),
() => commands.deleteSelection(),
// …
])
}
```
## List of commands