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 ```js
addCommands() { addCommands() {
return { return {
insertTimecode: attributes => ({ chain }) => { customCommand: attributes => ({ chain }) => {
// Doesnt work: // Doesnt work:
// return editor.chain() … // 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: 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 ```js
export default (value: string): Command => ({ tr, dispatch }) => { export default (value) => ({ tr, dispatch }) => {
if (dispatch) { if (dispatch) {
tr.insertText(value) 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. If youre just wrapping another tiptap command, you dont need to check that, well do it for you.
```js ```js
bold: (): Command => ({ commands }) => { addCommands() {
return {
bold: () => ({ commands }) => {
return commands.toggleMark('bold') 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 ```js
export default (typeOrName: string | NodeType): Command => ({ state, dispatch }) => { import { exitCode } from 'prosemirror-commands'
const type = getNodeType(typeOrName, state.schema)
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: Inside of commands you can do the same thing like that:
```js ```js
commands.first([ export default () => ({ commands }) => {
return commands.first([
() => commands.undoInputRule(), () => commands.undoInputRule(),
() => commands.deleteSelection(), () => commands.deleteSelection(),
// … // …
]) ])
}
``` ```
## List of commands ## List of commands