add list of current commands

This commit is contained in:
Philipp Kühn
2020-04-22 09:23:53 +02:00
parent adb44f317c
commit 0e18e67c93
4 changed files with 38 additions and 6 deletions

View File

@@ -1 +1,33 @@
# Commands # Commands
## .clearContent()
Clear the whole document.
## .focus()
Focus the editor at the given position.
## .insertHTML()
Insert a string of HTML at the currently selected position.
## .insertText()
Insert a string of text at the currently selected position.
## .removeMarks()
Remove all marks in the current selection.
## .selectAll()
Select the whole document.
## .setContent()
Replace the whole document with new content.
## .toggleNode()
Toggle a node with another node.

View File

@@ -71,7 +71,7 @@ export class Editor extends EventEmitter {
this.registerCommand('setContent', require('./commands/setContent').default) this.registerCommand('setContent', require('./commands/setContent').default)
this.registerCommand('clearContent', require('./commands/clearContent').default) this.registerCommand('clearContent', require('./commands/clearContent').default)
this.registerCommand('removeMarks', require('./commands/removeMarks').default) this.registerCommand('removeMarks', require('./commands/removeMarks').default)
this.registerCommand('toggleBlockType', require('./commands/toggleBlockType').default) this.registerCommand('toggleNode', require('./commands/toggleNode').default)
this.registerCommand('selectAll', require('./commands/selectAll').default) this.registerCommand('selectAll', require('./commands/selectAll').default)
if (this.options.injectCSS) { if (this.options.injectCSS) {

View File

@@ -4,7 +4,7 @@ import { Editor } from '../Editor'
import nodeIsActive from '../utils/nodeIsActive' import nodeIsActive from '../utils/nodeIsActive'
import getNodeType from '../utils/getNodeType' import getNodeType from '../utils/getNodeType'
type ToggleBlockType = ( type ToggleNode = (
type: string | NodeType, type: string | NodeType,
toggleType: string | NodeType, toggleType: string | NodeType,
attrs?: {} attrs?: {}
@@ -12,11 +12,11 @@ type ToggleBlockType = (
declare module '../Editor' { declare module '../Editor' {
interface Editor { interface Editor {
toggleBlockType: ToggleBlockType, toggleNode: ToggleNode,
} }
} }
export default (next: Function, editor: Editor): ToggleBlockType => (typeOrName, toggleTypeOrName, attrs) => { export default (next: Function, editor: Editor): ToggleNode => (typeOrName, toggleTypeOrName, attrs) => {
const { view, state, schema } = editor const { view, state, schema } = editor
const type = getNodeType(typeOrName, schema) const type = getNodeType(typeOrName, schema)
const toggleType = getNodeType(toggleTypeOrName, schema) const toggleType = getNodeType(toggleTypeOrName, schema)

View File

@@ -48,7 +48,7 @@ export default class Heading extends Node {
commands(): CommandSpec { commands(): CommandSpec {
return { return {
heading: next => attrs => { heading: next => attrs => {
this.editor.toggleBlockType(this.name, 'paragraph', attrs) this.editor.toggleNode(this.name, 'paragraph', attrs)
next() next()
}, },
} }