mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 23:15:15 +08:00
rename Commands to RawCommands
This commit is contained in:
parent
381bc0ce49
commit
a705134998
@ -4,9 +4,7 @@ import {
|
||||
SingleCommands,
|
||||
ChainedCommands,
|
||||
CanCommands,
|
||||
Commands,
|
||||
Command,
|
||||
CommandSpec,
|
||||
RawCommands,
|
||||
CommandProps,
|
||||
} from './types'
|
||||
import getAllMethodNames from './utilities/getAllMethodNames'
|
||||
@ -15,11 +13,11 @@ export default class CommandManager {
|
||||
|
||||
editor: Editor
|
||||
|
||||
commands: Commands
|
||||
commands: RawCommands
|
||||
|
||||
methodNames: string[] = []
|
||||
|
||||
constructor(editor: Editor, commands: Commands) {
|
||||
constructor(editor: Editor, commands: RawCommands) {
|
||||
this.editor = editor
|
||||
this.commands = commands
|
||||
this.methodNames = getAllMethodNames(this.editor)
|
||||
|
@ -2,7 +2,7 @@ import { Plugin, Transaction } from 'prosemirror-state'
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
import { Editor } from './Editor'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import { GlobalAttributes, Commands } from './types'
|
||||
import { GlobalAttributes, RawCommands } from './types'
|
||||
|
||||
export interface ExtensionConfig<Options = any> {
|
||||
/**
|
||||
@ -23,12 +23,12 @@ export interface ExtensionConfig<Options = any> {
|
||||
}) => GlobalAttributes | {},
|
||||
|
||||
/**
|
||||
* Commands
|
||||
* Raw
|
||||
*/
|
||||
addCommands?: (this: {
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
}) => Partial<Commands>,
|
||||
}) => Partial<RawCommands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
|
@ -4,7 +4,7 @@ import { inputRules as inputRulesPlugin } from 'prosemirror-inputrules'
|
||||
import { EditorView, Decoration } from 'prosemirror-view'
|
||||
import { Plugin } from 'prosemirror-state'
|
||||
import { Editor } from './Editor'
|
||||
import { Extensions, NodeViewRenderer, Commands } from './types'
|
||||
import { Extensions, NodeViewRenderer, RawCommands } from './types'
|
||||
import getSchema from './helpers/getSchema'
|
||||
import getSchemaTypeByName from './helpers/getSchemaTypeByName'
|
||||
import getNodeType from './helpers/getNodeType'
|
||||
@ -62,7 +62,7 @@ export default class ExtensionManager {
|
||||
})
|
||||
}
|
||||
|
||||
get commands(): Commands {
|
||||
get commands(): RawCommands {
|
||||
return this.extensions.reduce((extensions, extension) => {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
@ -74,7 +74,7 @@ export default class ExtensionManager {
|
||||
...extensions,
|
||||
...extension.config.addCommands.bind(context)(),
|
||||
}
|
||||
}, {} as Commands)
|
||||
}, {} as RawCommands)
|
||||
}
|
||||
|
||||
get plugins(): Plugin[] {
|
||||
|
@ -8,7 +8,7 @@ import { Plugin, Transaction } from 'prosemirror-state'
|
||||
import { InputRule } from 'prosemirror-inputrules'
|
||||
import { ExtensionConfig } from './Extension'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import { Attributes, Overwrite, Commands } from './types'
|
||||
import { Attributes, Overwrite, RawCommands } from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
export interface MarkConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
|
||||
@ -70,7 +70,7 @@ export interface MarkConfig<Options = any> extends Overwrite<ExtensionConfig<Opt
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: MarkType,
|
||||
}) => Partial<Commands>,
|
||||
}) => Partial<RawCommands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
|
@ -10,7 +10,7 @@ import { InputRule } from 'prosemirror-inputrules'
|
||||
import { ExtensionConfig } from './Extension'
|
||||
import mergeDeep from './utilities/mergeDeep'
|
||||
import {
|
||||
Attributes, NodeViewRenderer, Overwrite, Commands,
|
||||
Attributes, NodeViewRenderer, Overwrite, RawCommands,
|
||||
} from './types'
|
||||
import { Editor } from './Editor'
|
||||
|
||||
@ -127,7 +127,7 @@ export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Opt
|
||||
options: Options,
|
||||
editor: Editor,
|
||||
type: NodeType,
|
||||
}) => Partial<Commands>,
|
||||
}) => Partial<RawCommands>,
|
||||
|
||||
/**
|
||||
* Keyboard shortcuts
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const blur: Commands['blur'] = () => ({ view }) => {
|
||||
export const blur: RawCommands['blur'] = () => ({ view }) => {
|
||||
const element = view.dom as HTMLElement
|
||||
|
||||
element.blur()
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,6 +11,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
|
||||
export const clearContent: RawCommands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
|
||||
return commands.setContent('', emitUpdate)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { liftTarget } from 'prosemirror-transform'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,7 +12,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
||||
export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,6 +11,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const command: Commands['command'] = fn => props => {
|
||||
export const command: RawCommands['command'] = fn => props => {
|
||||
return fn(props)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => {
|
||||
export const createParagraphNear: RawCommands['createParagraphNear'] = () => ({ state, dispatch }) => {
|
||||
return originalCreateParagraphNear(state, dispatch)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands, Range } from '../types'
|
||||
import { Command, RawCommands, Range } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => {
|
||||
export const deleteRange: RawCommands['deleteRange'] = range => ({ tr, dispatch }) => {
|
||||
const { from, to } = range
|
||||
|
||||
if (dispatch) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => {
|
||||
export const deleteSelection: RawCommands['deleteSelection'] = () => ({ state, dispatch }) => {
|
||||
return originalDeleteSelection(state, dispatch)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,6 +11,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const enter: Commands['enter'] = () => ({ commands }) => {
|
||||
export const enter: RawCommands['enter'] = () => ({ commands }) => {
|
||||
return commands.keyboardShortcut('Enter')
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { exitCode as originalExitCode } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => {
|
||||
export const exitCode: RawCommands['exitCode'] = () => ({ state, dispatch }) => {
|
||||
return originalExitCode(state, dispatch)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
@ -15,7 +15,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
export const extendMarkRange: RawCommands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const { doc, selection } = tr
|
||||
const { $from, empty } = selection
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const first: Commands['first'] = commands => props => {
|
||||
export const first: RawCommands['first'] = commands => props => {
|
||||
const items = typeof commands === 'function'
|
||||
? commands(props)
|
||||
: commands
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { EditorState, TextSelection } from 'prosemirror-state'
|
||||
import { Command, Commands, FocusPosition } from '../types'
|
||||
import { Command, RawCommands, FocusPosition } from '../types'
|
||||
import minMax from '../utilities/minMax'
|
||||
import isTextSelection from '../helpers/isTextSelection'
|
||||
|
||||
@ -41,7 +41,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const focus: Commands['focus'] = (position = null) => ({
|
||||
export const focus: RawCommands['focus'] = (position = null) => ({
|
||||
editor,
|
||||
view,
|
||||
tr,
|
||||
|
@ -2,7 +2,7 @@ import { DOMParser } from 'prosemirror-model'
|
||||
import { Selection, Transaction } from 'prosemirror-state'
|
||||
import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform'
|
||||
import elementFromString from '../utilities/elementFromString'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
// TODO: move to utils
|
||||
// https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466
|
||||
@ -28,7 +28,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
||||
export const insertHTML: RawCommands['insertHTML'] = value => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const element = elementFromString(value)
|
||||
const slice = DOMParser.fromSchema(state.schema).parseSlice(element)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => {
|
||||
export const insertText: RawCommands['insertText'] = value => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.insertText(value)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => {
|
||||
export const joinBackward: RawCommands['joinBackward'] = () => ({ state, dispatch }) => {
|
||||
return originalJoinBackward(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { joinForward as originalJoinForward } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => {
|
||||
export const joinForward: RawCommands['joinForward'] = () => ({ state, dispatch }) => {
|
||||
return originalJoinForward(state, dispatch)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false
|
||||
|
||||
@ -67,7 +67,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({
|
||||
export const keyboardShortcut: RawCommands['keyboardShortcut'] = name => ({
|
||||
editor,
|
||||
view,
|
||||
tr,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { lift as originalLift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, Commands, AnyObject } from '../types'
|
||||
import { Command, RawCommands, AnyObject } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
@ -15,7 +15,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
|
||||
export const liftEmptyBlock: RawCommands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
|
||||
return originalLiftEmptyBlock(state, dispatch)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const liftListItem: Commands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
export const liftListItem: RawCommands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalLiftListItem(type)(state, dispatch)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => {
|
||||
export const newlineInCode: RawCommands['newlineInCode'] = () => ({ state, dispatch }) => {
|
||||
return originalNewlineInCode(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, Commands, AnyObject } from '../types'
|
||||
import { Command, RawCommands, AnyObject } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,7 +12,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const replace: Commands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
export const replace: RawCommands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const { from, to } = state.selection
|
||||
const range = { from, to }
|
||||
|
||||
|
@ -2,7 +2,7 @@ import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import {
|
||||
Command,
|
||||
Commands,
|
||||
RawCommands,
|
||||
Range,
|
||||
AnyObject,
|
||||
} from '../types'
|
||||
@ -18,7 +18,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
export const replaceRange: RawCommands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { from, to } = range
|
||||
const $from = tr.doc.resolve(from)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import deleteProps from '../utilities/deleteProps'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
||||
export const resetNodeAttributes: RawCommands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => {
|
||||
export const scrollIntoView: RawCommands['scrollIntoView'] = () => ({ tr, dispatch }) => {
|
||||
if (dispatch) {
|
||||
tr.scrollIntoView()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { selectAll as originalSelectAll } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => {
|
||||
export const selectAll: RawCommands['selectAll'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectAll(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => {
|
||||
export const selectNodeBackward: RawCommands['selectNodeBackward'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectNodeBackward(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => {
|
||||
export const selectNodeForward: RawCommands['selectNodeForward'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectNodeForward(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => {
|
||||
export const selectParentNode: RawCommands['selectParentNode'] = () => ({ state, dispatch }) => {
|
||||
return originalSelectParentNode(state, dispatch)
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,7 +12,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
||||
export const setContent: RawCommands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
|
||||
const { createDocument } = editor
|
||||
const { doc } = tr
|
||||
const document = createDocument(content, parseOptions)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkAttributes from '../helpers/getMarkAttributes'
|
||||
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { setBlockType } from 'prosemirror-commands'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const setNode: RawCommands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return setBlockType(type, attributes)(state, dispatch)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const sinkListItem: Commands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
export const sinkListItem: RawCommands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalSinkListItem(type)(state, dispatch)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { canSplit } from 'prosemirror-transform'
|
||||
import { ContentMatch, Fragment } from 'prosemirror-model'
|
||||
import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
||||
|
||||
function defaultBlockAt(match: ContentMatch) {
|
||||
@ -35,7 +35,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const splitBlock: Commands['splitBlock'] = ({ keepMarks = true } = {}) => ({
|
||||
export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {}) => ({
|
||||
tr,
|
||||
state,
|
||||
dispatch,
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
} from 'prosemirror-model'
|
||||
import { canSplit } from 'prosemirror-transform'
|
||||
import { TextSelection } from 'prosemirror-state'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import getSplittedAttributes from '../helpers/getSplittedAttributes'
|
||||
|
||||
@ -21,7 +21,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const splitListItem: Commands['splitListItem'] = typeOrName => ({
|
||||
export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
|
||||
tr, state, dispatch, editor,
|
||||
}) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import findParentNode from '../helpers/findParentNode'
|
||||
import isList from '../helpers/isList'
|
||||
@ -15,7 +15,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
|
||||
export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
|
||||
editor, tr, state, dispatch, chain, commands, can,
|
||||
}) => {
|
||||
const { extensions } = editor.options
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import isMarkActive from '../helpers/isMarkActive'
|
||||
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
export const toggleMark: RawCommands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
const isActive = isMarkActive(state, type, attributes)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
export const toggleNode: RawCommands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const toggleType = getNodeType(toggleTypeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { wrapIn, lift } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
@ -15,7 +15,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -12,6 +12,6 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => {
|
||||
export const undoInputRule: RawCommands['undoInputRule'] = () => ({ state, dispatch }) => {
|
||||
return originalUndoInputRule(state, dispatch)
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -11,7 +11,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
||||
export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const { from, to, empty } = selection
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { MarkType } from 'prosemirror-model'
|
||||
import { Command, Commands } from '../types'
|
||||
import { Command, RawCommands } from '../types'
|
||||
import getMarkType from '../helpers/getMarkType'
|
||||
import getMarkRange from '../helpers/getMarkRange'
|
||||
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
|
||||
const { selection } = tr
|
||||
const type = getMarkType(typeOrName, state.schema)
|
||||
let { from, to } = selection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
interface AllCommands {
|
||||
@ -13,7 +13,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
export const updateNodeAttributes: RawCommands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const { selection } = tr
|
||||
const { from, to } = selection
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import isNodeActive from '../helpers/isNodeActive'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
@ -15,7 +15,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
const isActive = isNodeActive(state, type, attributes)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
|
||||
import { NodeType } from 'prosemirror-model'
|
||||
import { AnyObject, Command, Commands } from '../types'
|
||||
import { AnyObject, Command, RawCommands } from '../types'
|
||||
import getNodeType from '../helpers/getNodeType'
|
||||
|
||||
declare module '@tiptap/core' {
|
||||
@ -14,7 +14,7 @@ declare module '@tiptap/core' {
|
||||
}
|
||||
}
|
||||
|
||||
export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
export const wrapInList: RawCommands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
|
||||
const type = getNodeType(typeOrName, state.schema)
|
||||
|
||||
return originalWrapInList(type, attributes)(state, dispatch)
|
||||
|
@ -114,21 +114,21 @@ export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {})
|
||||
|
||||
export type UnionCommands = UnionToIntersection<ValuesOf<Pick<AllCommands, KeysWithTypeOf<AllCommands, {}>>>>
|
||||
|
||||
export type Commands = {
|
||||
export type RawCommands = {
|
||||
[Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<UnionCommands[Item]>) => Command
|
||||
: never
|
||||
}
|
||||
|
||||
export type SingleCommands = {
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => boolean
|
||||
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<RawCommands[Item]>) => boolean
|
||||
: never
|
||||
}
|
||||
|
||||
export type ChainedCommands = {
|
||||
[Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<Commands[Item]>) => ChainedCommands
|
||||
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
|
||||
? (...args: Parameters<RawCommands[Item]>) => ChainedCommands
|
||||
: never
|
||||
} & {
|
||||
run: () => boolean
|
||||
|
Loading…
Reference in New Issue
Block a user