docs: update content
This commit is contained in:
@@ -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 }) => {
|
||||||
// Doesn’t work:
|
// Doesn’t work:
|
||||||
// return editor.chain() …
|
// return editor.chain() …
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ In order to make that work with your custom commands, don’t 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 you’re just wrapping another tiptap command, you don’t need to check that, we’ll do it for you.
|
If you’re just wrapping another tiptap command, you don’t need to check that, we’ll do it for you.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
bold: (): Command => ({ commands }) => {
|
addCommands() {
|
||||||
|
return {
|
||||||
|
bold: () => ({ commands }) => {
|
||||||
return commands.toggleMark('bold')
|
return commands.toggleMark('bold')
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If you’re just wrapping a ProseMirror command, you’ll need to pass `dispatch` anyway. Then there’s also no need to check it:
|
If you’re just wrapping a plain ProseMirror command, you’ll need to pass `dispatch` anyway. Then there’s 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
|
||||||
|
|||||||
Reference in New Issue
Block a user