return editor for all core command types
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { Editor } from '../Editor'
|
||||
|
||||
type ClearContent = (emitUpdate?: Boolean) => any
|
||||
type ClearContentCommand = (emitUpdate?: Boolean) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
clearContent: ClearContent,
|
||||
clearContent: ClearContentCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): ClearContent => (emitUpdate = false) => {
|
||||
export default (next: Function, editor: Editor) => (emitUpdate = false) => {
|
||||
editor.setContent('', emitUpdate)
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { deleteSelection } from 'prosemirror-commands'
|
||||
|
||||
type DeleteSelection = () => any
|
||||
type DeleteSelectionCommand = () => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
deleteSelection: DeleteSelection,
|
||||
deleteSelection: DeleteSelectionCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, { state, view }: Editor): DeleteSelection => () => {
|
||||
export default (next: Function, { state, view }: Editor) => () => {
|
||||
deleteSelection(state, view.dispatch)
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -3,9 +3,11 @@ import { TextSelection } from 'prosemirror-state'
|
||||
import sleep from '../utils/sleep'
|
||||
import minMax from '../utils/minMax'
|
||||
|
||||
type FocusCommand = (position?: Position) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
focus(position?: Position): Editor,
|
||||
focus: FocusCommand
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ import { DOMParser } from 'prosemirror-model'
|
||||
import { Editor } from '../Editor'
|
||||
import elementFromString from '../utils/elementFromString'
|
||||
|
||||
type InsertHTML = (value: string) => any
|
||||
type InsertHTMLCommand = (value: string) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
insertHTML: InsertHTML,
|
||||
insertHTML: InsertHTMLCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): InsertHTML => value => {
|
||||
export default (next: Function, editor: Editor) => (value: string) => {
|
||||
const { view, state } = editor
|
||||
const { selection } = state
|
||||
const element = elementFromString(value)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Editor } from '../Editor'
|
||||
|
||||
type InsertText = (value: string) => any
|
||||
type InsertTextCommand = (value: string) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
insertText: InsertText,
|
||||
insertText: InsertTextCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): InsertText => value => {
|
||||
export default (next: Function, editor: Editor) => (value: string) => {
|
||||
const { view, state } = editor
|
||||
const transaction = state.tr.insertText(value)
|
||||
|
||||
|
||||
@@ -3,15 +3,15 @@ import { MarkType } from 'prosemirror-model'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
|
||||
type RemoveMark = (type: string | MarkType) => any
|
||||
type RemoveMarkCommand = (typeOrName: string | MarkType) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
toggleMark: RemoveMark,
|
||||
toggleMark: RemoveMarkCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): RemoveMark => typeOrName => {
|
||||
export default (next: Function, editor: Editor) => (typeOrName: string | MarkType) => {
|
||||
const { view, state, schema } = editor
|
||||
const { tr, selection } = state
|
||||
const type = getMarkType(typeOrName, schema)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { Editor } from '../Editor'
|
||||
|
||||
type RemoveMarks = () => any
|
||||
type RemoveMarksCommand = () => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
removeMarks: RemoveMarks,
|
||||
removeMarks: RemoveMarksCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): RemoveMarks => () => {
|
||||
export default (next: Function, editor: Editor) => () => {
|
||||
const { state, view, schema } = editor
|
||||
const { selection, tr } = state
|
||||
const { from, to, empty } = selection
|
||||
|
||||
@@ -7,19 +7,19 @@ interface Range {
|
||||
to: number,
|
||||
}
|
||||
|
||||
type ReplaceWithNode = (
|
||||
type: NodeType,
|
||||
type ReplaceWithNodeCommand = (
|
||||
typeOrName: NodeType,
|
||||
attrs: {},
|
||||
range?: Range,
|
||||
) => any
|
||||
) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
replaceText: ReplaceWithNode,
|
||||
replaceText: ReplaceWithNodeCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): ReplaceWithNode => (typeOrName, attrs, range) => {
|
||||
export default (next: Function, editor: Editor) => (typeOrName: NodeType, attrs: {}, range?: Range) => {
|
||||
const { view, state, schema } = editor
|
||||
const { $from, $to } = state.selection
|
||||
const type = getNodeType(typeOrName, schema)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { selectAll } from 'prosemirror-commands'
|
||||
|
||||
type SelectAll = () => any
|
||||
type SelectAllCommand = () => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
selectAll: SelectAll,
|
||||
selectAll: SelectAllCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, { state, view }: Editor): SelectAll => () => {
|
||||
export default (next: Function, { state, view }: Editor) => () => {
|
||||
selectAll(state, view.dispatch)
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { selectParentNode } from 'prosemirror-commands'
|
||||
|
||||
type SelectParentNode = () => any
|
||||
type SelectParentNodeCommand = () => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
selectParentNode: SelectParentNode,
|
||||
selectParentNode: SelectParentNodeCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, { state, view }: Editor): SelectParentNode => () => {
|
||||
export default (next: Function, { state, view }: Editor) => () => {
|
||||
selectParentNode(state, view.dispatch)
|
||||
next()
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { Editor } from '../Editor'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
|
||||
type SetContent = (
|
||||
type SetContentCommand = (
|
||||
content: string,
|
||||
emitUpdate?: Boolean,
|
||||
parseOptions?: any,
|
||||
) => any
|
||||
) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
setContent: SetContent,
|
||||
setContent: SetContentCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): SetContent => (content, emitUpdate = false, parseOptions = {}) => {
|
||||
export default (next: Function, editor: Editor) => (content: string, emitUpdate: Boolean = false, parseOptions = {}) => {
|
||||
if (content === null) {
|
||||
next()
|
||||
return
|
||||
|
||||
@@ -3,15 +3,15 @@ import { toggleMark } from 'prosemirror-commands'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
|
||||
type ToggleMark = (type: string | MarkType) => any
|
||||
type ToggleMarkCommand = (typeOrName: string | MarkType) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
toggleMark: ToggleMark,
|
||||
toggleMark: ToggleMarkCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): ToggleMark => (typeOrName) => {
|
||||
export default (next: Function, editor: Editor) => (typeOrName: string | MarkType) => {
|
||||
const { view, state, schema } = editor
|
||||
const type = getMarkType(typeOrName, schema)
|
||||
|
||||
|
||||
@@ -4,19 +4,19 @@ import { Editor } from '../Editor'
|
||||
import nodeIsActive from '../utils/nodeIsActive'
|
||||
import getNodeType from '../utils/getNodeType'
|
||||
|
||||
type ToggleNode = (
|
||||
type: string | NodeType,
|
||||
type ToggleNodeCommand = (
|
||||
typeOrName: string | NodeType,
|
||||
toggleType: string | NodeType,
|
||||
attrs?: {}
|
||||
) => any
|
||||
) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
toggleNode: ToggleNode,
|
||||
toggleNode: ToggleNodeCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): ToggleNode => (typeOrName, toggleTypeOrName, attrs) => {
|
||||
export default (next: Function, editor: Editor) => (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}) => {
|
||||
const { view, state, schema } = editor
|
||||
const type = getNodeType(typeOrName, schema)
|
||||
const toggleType = getNodeType(toggleTypeOrName, schema)
|
||||
|
||||
@@ -3,18 +3,18 @@ import { MarkType } from 'prosemirror-model'
|
||||
import getMarkType from '../utils/getMarkType'
|
||||
import getMarkRange from '../utils/getMarkRange'
|
||||
|
||||
type UpdateMark = (
|
||||
type: string | MarkType,
|
||||
type UpdateMarkCommand = (
|
||||
typeOrName: string | MarkType,
|
||||
attrs: {},
|
||||
) => any
|
||||
) => Editor
|
||||
|
||||
declare module '../Editor' {
|
||||
interface Editor {
|
||||
updateMark: UpdateMark,
|
||||
updateMark: UpdateMarkCommand,
|
||||
}
|
||||
}
|
||||
|
||||
export default (next: Function, editor: Editor): UpdateMark => (typeOrName, attrs) => {
|
||||
export default (next: Function, editor: Editor) => (typeOrName: string | MarkType, attrs = {}) => {
|
||||
const { view, state, schema } = editor
|
||||
const { tr, selection, doc } = state
|
||||
let { from, to, $from, empty } = selection
|
||||
|
||||
Reference in New Issue
Block a user