add comments to all commands
This commit is contained in:
@@ -95,18 +95,18 @@ Have a look at all of the core commands listed below. They should give you a goo
|
|||||||
| .updateNodeAttributes() | Update attributes of a node. |
|
| .updateNodeAttributes() | Update attributes of a node. |
|
||||||
|
|
||||||
### Lists
|
### Lists
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| ---------------- | ------------------------------------------------------ |
|
| ---------------- | ------------------------------------------- |
|
||||||
| .liftListItem() | Lift the list item into a wrapping list. |
|
| .liftListItem() | Lift the list item into a wrapping list. |
|
||||||
| .sinkListItem() | Sink the list item down into an inner list. |
|
| .sinkListItem() | Sink the list item down into an inner list. |
|
||||||
| .splitListItem() | Splits a textblock of a list item into two list items. |
|
| .splitListItem() | Splits one list item into two list items. |
|
||||||
| .toggleList() | Toggle between different list types. |
|
| .toggleList() | Toggle between different list types. |
|
||||||
| .wrapInList() | Wrap a node in a list. |
|
| .wrapInList() | Wrap a node in a list. |
|
||||||
|
|
||||||
### Selection
|
### Selection
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| ------------------ | --------------------------------------- |
|
| ------------------ | --------------------------------------- |
|
||||||
| .blur() | Blurs the editor. |
|
| .blur() | Removes focus from the editor. |
|
||||||
| .deleteSelection() | Delete the selection, if there is one. |
|
| .deleteSelection() | Delete the selection, if there is one. |
|
||||||
| .focus() | Focus the editor at the given position. |
|
| .focus() | Focus the editor at the given position. |
|
||||||
| .scrollIntoView() | Scroll the selection into view. |
|
| .scrollIntoView() | Scroll the selection into view. |
|
||||||
|
|||||||
@@ -282,6 +282,10 @@ const CustomParagraph = Paragraph.extend({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
:::warning Use the commands parameter inside of addCommands
|
||||||
|
All commands are also available through ~~this.editor.commands~~, but inside of `addCommands` you must use the `commands` parameter that’s passed to it.
|
||||||
|
:::
|
||||||
|
|
||||||
### Keyboard shortcuts
|
### Keyboard shortcuts
|
||||||
Most core extensions come with sensible keyboard shortcut defaults. Depending on what you want to build, you’ll likely want to change them though. With the `addKeyboardShortcuts()` method you can overwrite the predefined shortcut map:
|
Most core extensions come with sensible keyboard shortcut defaults. Depending on what you want to build, you’ll likely want to change them though. With the `addKeyboardShortcuts()` method you can overwrite the predefined shortcut map:
|
||||||
|
|
||||||
|
|||||||
@@ -31,33 +31,117 @@ import wrapInList from '../commands/wrapInList'
|
|||||||
export const Commands = createExtension({
|
export const Commands = createExtension({
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Removes focus from the editor.
|
||||||
|
*/
|
||||||
blur,
|
blur,
|
||||||
|
/**
|
||||||
|
* Clear the whole document.
|
||||||
|
*/
|
||||||
clearContent,
|
clearContent,
|
||||||
|
/**
|
||||||
|
* Normalize nodes to a simple paragraph.
|
||||||
|
*/
|
||||||
clearNodes,
|
clearNodes,
|
||||||
|
/**
|
||||||
|
* Delete the selection, if there is one.
|
||||||
|
*/
|
||||||
deleteSelection,
|
deleteSelection,
|
||||||
|
/**
|
||||||
|
* Extends the text selection to the current mark.
|
||||||
|
*/
|
||||||
extendMarkRange,
|
extendMarkRange,
|
||||||
|
/**
|
||||||
|
* Focus the editor at the given position.
|
||||||
|
*/
|
||||||
focus,
|
focus,
|
||||||
|
/**
|
||||||
|
* Insert a string of HTML at the current position.
|
||||||
|
*/
|
||||||
insertHTML,
|
insertHTML,
|
||||||
|
/**
|
||||||
|
* Insert a string of text at the current position.
|
||||||
|
*/
|
||||||
insertText,
|
insertText,
|
||||||
|
/**
|
||||||
|
* Lift the list item into a wrapping list.
|
||||||
|
*/
|
||||||
liftListItem,
|
liftListItem,
|
||||||
|
/**
|
||||||
|
* Remove all marks in the current selection.
|
||||||
|
*/
|
||||||
removeMark,
|
removeMark,
|
||||||
|
/**
|
||||||
|
* Remove all marks in the current selection.
|
||||||
|
*/
|
||||||
removeMarks,
|
removeMarks,
|
||||||
|
/**
|
||||||
|
* Resets all node attributes to the default value.
|
||||||
|
*/
|
||||||
resetNodeAttributes,
|
resetNodeAttributes,
|
||||||
|
/**
|
||||||
|
* Scroll the selection into view.
|
||||||
|
*/
|
||||||
scrollIntoView,
|
scrollIntoView,
|
||||||
|
/**
|
||||||
|
* Select the whole document.
|
||||||
|
*/
|
||||||
selectAll,
|
selectAll,
|
||||||
|
/**
|
||||||
|
* Select the parent node.
|
||||||
|
*/
|
||||||
selectParentNode,
|
selectParentNode,
|
||||||
|
/**
|
||||||
|
* Replace a given range with a node.
|
||||||
|
*/
|
||||||
setBlockType,
|
setBlockType,
|
||||||
|
/**
|
||||||
|
* Replace the whole document with new content.
|
||||||
|
*/
|
||||||
setContent,
|
setContent,
|
||||||
|
/**
|
||||||
|
* Sink the list item down into an inner list.
|
||||||
|
*/
|
||||||
sinkListItem,
|
sinkListItem,
|
||||||
|
/**
|
||||||
|
* Forks a new node from an existing node.
|
||||||
|
*/
|
||||||
splitBlock,
|
splitBlock,
|
||||||
|
/**
|
||||||
|
* Splits one list item into two list items.
|
||||||
|
*/
|
||||||
splitListItem,
|
splitListItem,
|
||||||
|
/**
|
||||||
|
* Toggle a node with another node.
|
||||||
|
*/
|
||||||
toggleBlockType,
|
toggleBlockType,
|
||||||
|
/**
|
||||||
|
* Toggle between different list types.
|
||||||
|
*/
|
||||||
toggleList,
|
toggleList,
|
||||||
|
/**
|
||||||
|
* Toggle a mark on and off.
|
||||||
|
*/
|
||||||
toggleMark,
|
toggleMark,
|
||||||
|
/**
|
||||||
|
* Wraps nodes in another node, or removes an existing wrap.
|
||||||
|
*/
|
||||||
toggleWrap,
|
toggleWrap,
|
||||||
|
/**
|
||||||
|
* Runs one command after the other and stops at the first which returns true.
|
||||||
|
*/
|
||||||
try: tryCommand,
|
try: tryCommand,
|
||||||
|
/**
|
||||||
|
* Update a mark with new attributes.
|
||||||
|
*/
|
||||||
updateMarkAttributes,
|
updateMarkAttributes,
|
||||||
|
/**
|
||||||
|
* Update attributes of a node.
|
||||||
|
*/
|
||||||
updateNodeAttributes,
|
updateNodeAttributes,
|
||||||
|
/**
|
||||||
|
* Wrap a node in a list.
|
||||||
|
*/
|
||||||
wrapInList,
|
wrapInList,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ const Blockquote = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a blockquote node
|
||||||
|
*/
|
||||||
blockquote: (): Command => ({ commands }) => {
|
blockquote: (): Command => ({ commands }) => {
|
||||||
return commands.toggleWrap('blockquote')
|
return commands.toggleWrap('blockquote')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const Bold = createMark({
|
|||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* bold command
|
* Toggle a bold mark
|
||||||
*/
|
*/
|
||||||
bold: (): Command => ({ commands }) => {
|
bold: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('bold')
|
return commands.toggleMark('bold')
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ const BulletList = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a bullet list
|
||||||
|
*/
|
||||||
bulletList: (): Command => ({ commands }) => {
|
bulletList: (): Command => ({ commands }) => {
|
||||||
return commands.toggleList('bulletList', 'listItem')
|
return commands.toggleList('bulletList', 'listItem')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ const CodeBlock = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a code block
|
||||||
|
*/
|
||||||
codeBlock: (attrs?: CodeBlockOptions): Command => ({ commands }) => {
|
codeBlock: (attrs?: CodeBlockOptions): Command => ({ commands }) => {
|
||||||
return commands.toggleBlockType('codeBlock', 'paragraph', attrs)
|
return commands.toggleBlockType('codeBlock', 'paragraph', attrs)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ const Code = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle inline code
|
||||||
|
*/
|
||||||
code: (): Command => ({ commands }) => {
|
code: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('code')
|
return commands.toggleMark('code')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ const CollaborationCursor = createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Update details of the current user
|
||||||
|
*/
|
||||||
user: (attributes: {
|
user: (attributes: {
|
||||||
name: string,
|
name: string,
|
||||||
color: string,
|
color: string,
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ const FontFamily = createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Update the font family
|
||||||
|
*/
|
||||||
fontFamily: (fontFamily: string | null = null): Command => ({ chain }) => {
|
fontFamily: (fontFamily: string | null = null): Command => ({ chain }) => {
|
||||||
return chain()
|
return chain()
|
||||||
.updateMarkAttributes('textStyle', { fontFamily })
|
.updateMarkAttributes('textStyle', { fontFamily })
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ const HardBreak = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Add a hard break
|
||||||
|
*/
|
||||||
hardBreak: (): Command => ({ commands, state, dispatch }) => {
|
hardBreak: (): Command => ({ commands, state, dispatch }) => {
|
||||||
return commands.try([
|
return commands.try([
|
||||||
() => exitCode(state, dispatch),
|
() => exitCode(state, dispatch),
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const Heading = createNode({
|
|||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
/**
|
/**
|
||||||
* heading command
|
* Toggle a heading node
|
||||||
*/
|
*/
|
||||||
heading: (options: { level: Level }): Command => ({ commands }) => {
|
heading: (options: { level: Level }): Command => ({ commands }) => {
|
||||||
if (!this.options.levels.includes(options.level)) {
|
if (!this.options.levels.includes(options.level)) {
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ const Highlight = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a highlight mark
|
||||||
|
*/
|
||||||
highlight: (attributes?: { color: string }): Command => ({ commands }) => {
|
highlight: (attributes?: { color: string }): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('highlight', attributes)
|
return commands.toggleMark('highlight', attributes)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -14,9 +14,15 @@ const History = createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Undo recent changes
|
||||||
|
*/
|
||||||
undo: (): Command => ({ state, dispatch }) => {
|
undo: (): Command => ({ state, dispatch }) => {
|
||||||
return undo(state, dispatch)
|
return undo(state, dispatch)
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Reapply reverted changes
|
||||||
|
*/
|
||||||
redo: (): Command => ({ state, dispatch }) => {
|
redo: (): Command => ({ state, dispatch }) => {
|
||||||
return redo(state, dispatch)
|
return redo(state, dispatch)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ const HorizontalRule = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Add a horizontal rule
|
||||||
|
*/
|
||||||
horizontalRule: (): Command => ({ tr }) => {
|
horizontalRule: (): Command => ({ tr }) => {
|
||||||
tr.replaceSelectionWith(this.type.create())
|
tr.replaceSelectionWith(this.type.create())
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ const Image = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Add an image
|
||||||
|
*/
|
||||||
image: (options: { src: string, alt?: string, title?: string }): Command => ({ tr }) => {
|
image: (options: { src: string, alt?: string, title?: string }): Command => ({ tr }) => {
|
||||||
const { selection } = tr
|
const { selection } = tr
|
||||||
const node = this.type.create(options)
|
const node = this.type.create(options)
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ const Italic = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle an italic mark
|
||||||
|
*/
|
||||||
italic: (): Command => ({ commands }) => {
|
italic: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('italic')
|
return commands.toggleMark('italic')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ const Link = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle or update a link mark
|
||||||
|
*/
|
||||||
link: (options: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
link: (options: { href?: string, target?: string } = {}): Command => ({ commands }) => {
|
||||||
if (!options.href) {
|
if (!options.href) {
|
||||||
return commands.removeMark('link')
|
return commands.removeMark('link')
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ const OrderedList = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle an ordered list
|
||||||
|
*/
|
||||||
orderedList: (): Command => ({ commands }) => {
|
orderedList: (): Command => ({ commands }) => {
|
||||||
return commands.toggleList('orderedList', 'listItem')
|
return commands.toggleList('orderedList', 'listItem')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ const Paragraph = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a paragraph
|
||||||
|
*/
|
||||||
paragraph: (): Command => ({ commands }) => {
|
paragraph: (): Command => ({ commands }) => {
|
||||||
return commands.toggleBlockType('paragraph', 'paragraph')
|
return commands.toggleBlockType('paragraph', 'paragraph')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ const Strike = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a strike mark
|
||||||
|
*/
|
||||||
strike: (): Command => ({ commands }) => {
|
strike: (): Command => ({ commands }) => {
|
||||||
return commands.toggleMark('strike')
|
return commands.toggleMark('strike')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ const TaskList = createNode({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Toggle a task list
|
||||||
|
*/
|
||||||
taskList: (): Command => ({ commands }) => {
|
taskList: (): Command => ({ commands }) => {
|
||||||
return commands.toggleList('taskList', 'taskItem')
|
return commands.toggleList('taskList', 'taskItem')
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -34,6 +34,9 @@ const TextAlign = createExtension({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Update the text align attribute
|
||||||
|
*/
|
||||||
textAlign: (alignment: string): Command => ({ commands }) => {
|
textAlign: (alignment: string): Command => ({ commands }) => {
|
||||||
if (!this.options.alignments.includes(alignment)) {
|
if (!this.options.alignments.includes(alignment)) {
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ const TextStyle = createMark({
|
|||||||
|
|
||||||
addCommands() {
|
addCommands() {
|
||||||
return {
|
return {
|
||||||
|
/**
|
||||||
|
* Remove spans without inline style attributes.
|
||||||
|
*/
|
||||||
removeEmptyTextStyle: (): Command => ({ state, commands }) => {
|
removeEmptyTextStyle: (): Command => ({ state, commands }) => {
|
||||||
const attributes = getMarkAttrs(state, this.type)
|
const attributes = getMarkAttrs(state, this.type)
|
||||||
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
|
const hasStyles = Object.entries(attributes).every(([, value]) => !!value)
|
||||||
|
|||||||
Reference in New Issue
Block a user