restructure commands
This commit is contained in:
@@ -1,163 +1,70 @@
|
||||
import { Extension } from '../Extension'
|
||||
import addMark from '../commands/addMark'
|
||||
import blur from '../commands/blur'
|
||||
import clearContent from '../commands/clearContent'
|
||||
import command from '../commands/command'
|
||||
import clearNodes from '../commands/clearNodes'
|
||||
import deleteSelection from '../commands/deleteSelection'
|
||||
import extendMarkRange from '../commands/extendMarkRange'
|
||||
import focus from '../commands/focus'
|
||||
import insertHTML from '../commands/insertHTML'
|
||||
import insertText from '../commands/insertText'
|
||||
import lift from '../commands/lift'
|
||||
import liftListItem from '../commands/liftListItem'
|
||||
import removeMark from '../commands/removeMark'
|
||||
import removeMarks from '../commands/removeMarks'
|
||||
import resetNodeAttributes from '../commands/resetNodeAttributes'
|
||||
import scrollIntoView from '../commands/scrollIntoView'
|
||||
import selectAll from '../commands/selectAll'
|
||||
import selectParentNode from '../commands/selectParentNode'
|
||||
import setBlockType from '../commands/setBlockType'
|
||||
import setContent from '../commands/setContent'
|
||||
import sinkListItem from '../commands/sinkListItem'
|
||||
import splitBlock from '../commands/splitBlock'
|
||||
import splitListItem from '../commands/splitListItem'
|
||||
import toggleBlockType from '../commands/toggleBlockType'
|
||||
import toggleList from '../commands/toggleList'
|
||||
import toggleMark from '../commands/toggleMark'
|
||||
import toggleWrap from '../commands/toggleWrap'
|
||||
import tryCommand from '../commands/try'
|
||||
import updateNodeAttributes from '../commands/updateNodeAttributes'
|
||||
import wrapIn from '../commands/wrapIn'
|
||||
import wrapInList from '../commands/wrapInList'
|
||||
import * as addMark from '../commands/addMark'
|
||||
import * as blur from '../commands/blur'
|
||||
import * as clearContent from '../commands/clearContent'
|
||||
import * as command from '../commands/command'
|
||||
import * as clearNodes from '../commands/clearNodes'
|
||||
import * as deleteSelection from '../commands/deleteSelection'
|
||||
import * as extendMarkRange from '../commands/extendMarkRange'
|
||||
import * as focus from '../commands/focus'
|
||||
import * as insertHTML from '../commands/insertHTML'
|
||||
import * as insertText from '../commands/insertText'
|
||||
import * as lift from '../commands/lift'
|
||||
import * as liftListItem from '../commands/liftListItem'
|
||||
import * as removeMark from '../commands/removeMark'
|
||||
import * as removeMarks from '../commands/removeMarks'
|
||||
import * as resetNodeAttributes from '../commands/resetNodeAttributes'
|
||||
import * as scrollIntoView from '../commands/scrollIntoView'
|
||||
import * as selectAll from '../commands/selectAll'
|
||||
import * as selectParentNode from '../commands/selectParentNode'
|
||||
import * as setBlockType from '../commands/setBlockType'
|
||||
import * as setContent from '../commands/setContent'
|
||||
import * as sinkListItem from '../commands/sinkListItem'
|
||||
import * as splitBlock from '../commands/splitBlock'
|
||||
import * as splitListItem from '../commands/splitListItem'
|
||||
import * as toggleBlockType from '../commands/toggleBlockType'
|
||||
import * as toggleList from '../commands/toggleList'
|
||||
import * as toggleMark from '../commands/toggleMark'
|
||||
import * as toggleWrap from '../commands/toggleWrap'
|
||||
import * as first from '../commands/first'
|
||||
import * as updateNodeAttributes from '../commands/updateNodeAttributes'
|
||||
import * as wrapIn from '../commands/wrapIn'
|
||||
import * as wrapInList from '../commands/wrapInList'
|
||||
|
||||
export const Commands = Extension.create({
|
||||
addCommands() {
|
||||
return {
|
||||
/**
|
||||
* Add a mark with new attributes.
|
||||
*/
|
||||
addMark,
|
||||
/**
|
||||
* Removes focus from the editor.
|
||||
*/
|
||||
blur,
|
||||
/**
|
||||
* Clear the whole document.
|
||||
*/
|
||||
clearContent,
|
||||
/**
|
||||
* Normalize nodes to a simple paragraph.
|
||||
*/
|
||||
clearNodes,
|
||||
/**
|
||||
* Define a command inline.
|
||||
*/
|
||||
command,
|
||||
/**
|
||||
* Delete the selection, if there is one.
|
||||
*/
|
||||
deleteSelection,
|
||||
/**
|
||||
* Extends the text selection to the current mark.
|
||||
*/
|
||||
extendMarkRange,
|
||||
/**
|
||||
* Focus the editor at the given position.
|
||||
*/
|
||||
focus,
|
||||
/**
|
||||
* Insert a string of HTML at the current position.
|
||||
*/
|
||||
insertHTML,
|
||||
/**
|
||||
* Insert a string of text at the current position.
|
||||
*/
|
||||
insertText,
|
||||
/**
|
||||
* Removes an existing wrap.
|
||||
*/
|
||||
lift,
|
||||
/**
|
||||
* Lift the list item into a wrapping list.
|
||||
*/
|
||||
liftListItem,
|
||||
/**
|
||||
* Remove all marks in the current selection.
|
||||
*/
|
||||
removeMark,
|
||||
/**
|
||||
* Remove all marks in the current selection.
|
||||
*/
|
||||
removeMarks,
|
||||
/**
|
||||
* Resets node attributes to the default value.
|
||||
*/
|
||||
resetNodeAttributes,
|
||||
/**
|
||||
* Scroll the selection into view.
|
||||
*/
|
||||
scrollIntoView,
|
||||
/**
|
||||
* Select the whole document.
|
||||
*/
|
||||
selectAll,
|
||||
/**
|
||||
* Select the parent node.
|
||||
*/
|
||||
selectParentNode,
|
||||
/**
|
||||
* Replace a given range with a node.
|
||||
*/
|
||||
setBlockType,
|
||||
/**
|
||||
* Replace the whole document with new content.
|
||||
*/
|
||||
setContent,
|
||||
/**
|
||||
* Sink the list item down into an inner list.
|
||||
*/
|
||||
sinkListItem,
|
||||
/**
|
||||
* Forks a new node from an existing node.
|
||||
*/
|
||||
splitBlock,
|
||||
/**
|
||||
* Splits one list item into two list items.
|
||||
*/
|
||||
splitListItem,
|
||||
/**
|
||||
* Toggle a node with another node.
|
||||
*/
|
||||
toggleBlockType,
|
||||
/**
|
||||
* Toggle between different list types.
|
||||
*/
|
||||
toggleList,
|
||||
/**
|
||||
* Toggle a mark on and off.
|
||||
*/
|
||||
toggleMark,
|
||||
/**
|
||||
* Wraps nodes in another node, or removes an existing wrap.
|
||||
*/
|
||||
toggleWrap,
|
||||
/**
|
||||
* Runs one command after the other and stops at the first which returns true.
|
||||
*/
|
||||
try: tryCommand,
|
||||
/**
|
||||
* Update attributes of a node.
|
||||
*/
|
||||
updateNodeAttributes,
|
||||
/**
|
||||
* Wraps nodes in another node.
|
||||
*/
|
||||
wrapIn,
|
||||
/**
|
||||
* Wrap a node in a list.
|
||||
*/
|
||||
wrapInList,
|
||||
...addMark,
|
||||
...blur,
|
||||
...clearContent,
|
||||
...clearNodes,
|
||||
...command,
|
||||
...deleteSelection,
|
||||
...extendMarkRange,
|
||||
...first,
|
||||
...focus,
|
||||
...insertHTML,
|
||||
...insertText,
|
||||
...lift,
|
||||
...liftListItem,
|
||||
...removeMark,
|
||||
...removeMarks,
|
||||
...resetNodeAttributes,
|
||||
...scrollIntoView,
|
||||
...selectAll,
|
||||
...selectParentNode,
|
||||
...setBlockType,
|
||||
...setContent,
|
||||
...sinkListItem,
|
||||
...splitBlock,
|
||||
...splitListItem,
|
||||
...toggleBlockType,
|
||||
...toggleList,
|
||||
...toggleMark,
|
||||
...toggleWrap,
|
||||
...updateNodeAttributes,
|
||||
...wrapIn,
|
||||
...wrapInList,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -14,21 +14,21 @@ import { Extension } from '../Extension'
|
||||
|
||||
export const Keymap = Extension.create({
|
||||
addKeyboardShortcuts() {
|
||||
const handleBackspace = () => this.editor.commands.try(({ state, dispatch }) => [
|
||||
const handleBackspace = () => this.editor.commands.first(({ state, dispatch }) => [
|
||||
() => undoInputRule(state, dispatch),
|
||||
() => deleteSelection(state, dispatch),
|
||||
() => joinBackward(state, dispatch),
|
||||
() => selectNodeBackward(state, dispatch),
|
||||
])
|
||||
|
||||
const handleDelete = () => this.editor.commands.try(({ state, dispatch }) => [
|
||||
const handleDelete = () => this.editor.commands.first(({ state, dispatch }) => [
|
||||
() => deleteSelection(state, dispatch),
|
||||
() => joinForward(state, dispatch),
|
||||
() => selectNodeForward(state, dispatch),
|
||||
])
|
||||
|
||||
return {
|
||||
Enter: () => this.editor.commands.try(({ commands, state, dispatch }) => [
|
||||
Enter: () => this.editor.commands.first(({ commands, state, dispatch }) => [
|
||||
() => newlineInCode(state, dispatch),
|
||||
() => createParagraphNear(state, dispatch),
|
||||
() => liftEmptyBlock(state, dispatch),
|
||||
|
||||
Reference in New Issue
Block a user