diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index 8c9f68f3..2dcefe0d 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -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) diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index 95fdf253..f703c57b 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -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 { /** @@ -23,12 +23,12 @@ export interface ExtensionConfig { }) => GlobalAttributes | {}, /** - * Commands + * Raw */ addCommands?: (this: { options: Options, editor: Editor, - }) => Partial, + }) => Partial, /** * Keyboard shortcuts diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 05375681..c9e85b57 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -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[] { diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 57303485..df8a1a00 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -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 extends Overwrite, { @@ -70,7 +70,7 @@ export interface MarkConfig extends Overwrite Partial, + }) => Partial, /** * Keyboard shortcuts diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 26f71248..1798cc04 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -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 extends Overwrite Partial, + }) => Partial, /** * Keyboard shortcuts diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts index 17ed7ebe..2c07abc3 100644 --- a/packages/core/src/commands/blur.ts +++ b/packages/core/src/commands/blur.ts @@ -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() diff --git a/packages/core/src/commands/clearContent.ts b/packages/core/src/commands/clearContent.ts index bd9b5482..7f9b701b 100644 --- a/packages/core/src/commands/clearContent.ts +++ b/packages/core/src/commands/clearContent.ts @@ -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) } diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index b9d5f576..d2a686a9 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -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 diff --git a/packages/core/src/commands/command.ts b/packages/core/src/commands/command.ts index 180f66c5..f4ef57fc 100644 --- a/packages/core/src/commands/command.ts +++ b/packages/core/src/commands/command.ts @@ -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) } diff --git a/packages/core/src/commands/createParagraphNear.ts b/packages/core/src/commands/createParagraphNear.ts index 04e51fd1..63a83cdf 100644 --- a/packages/core/src/commands/createParagraphNear.ts +++ b/packages/core/src/commands/createParagraphNear.ts @@ -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) } diff --git a/packages/core/src/commands/deleteRange.ts b/packages/core/src/commands/deleteRange.ts index 41a32903..870938c2 100644 --- a/packages/core/src/commands/deleteRange.ts +++ b/packages/core/src/commands/deleteRange.ts @@ -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) { diff --git a/packages/core/src/commands/deleteSelection.ts b/packages/core/src/commands/deleteSelection.ts index 87958bb4..2b00e7e0 100644 --- a/packages/core/src/commands/deleteSelection.ts +++ b/packages/core/src/commands/deleteSelection.ts @@ -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) } diff --git a/packages/core/src/commands/enter.ts b/packages/core/src/commands/enter.ts index 43cf42ab..116836df 100644 --- a/packages/core/src/commands/enter.ts +++ b/packages/core/src/commands/enter.ts @@ -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') } diff --git a/packages/core/src/commands/exitCode.ts b/packages/core/src/commands/exitCode.ts index 341c5378..eaa9ce53 100644 --- a/packages/core/src/commands/exitCode.ts +++ b/packages/core/src/commands/exitCode.ts @@ -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) } diff --git a/packages/core/src/commands/extendMarkRange.ts b/packages/core/src/commands/extendMarkRange.ts index 15c1e62a..ec45e184 100644 --- a/packages/core/src/commands/extendMarkRange.ts +++ b/packages/core/src/commands/extendMarkRange.ts @@ -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 diff --git a/packages/core/src/commands/first.ts b/packages/core/src/commands/first.ts index 356ec55c..7b7b9cb0 100644 --- a/packages/core/src/commands/first.ts +++ b/packages/core/src/commands/first.ts @@ -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 diff --git a/packages/core/src/commands/focus.ts b/packages/core/src/commands/focus.ts index 723dfe2c..d5bfd989 100644 --- a/packages/core/src/commands/focus.ts +++ b/packages/core/src/commands/focus.ts @@ -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, diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts index bb7bba87..a6357869 100644 --- a/packages/core/src/commands/insertHTML.ts +++ b/packages/core/src/commands/insertHTML.ts @@ -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) diff --git a/packages/core/src/commands/insertText.ts b/packages/core/src/commands/insertText.ts index 14facef8..744a4a11 100644 --- a/packages/core/src/commands/insertText.ts +++ b/packages/core/src/commands/insertText.ts @@ -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) } diff --git a/packages/core/src/commands/joinBackward.ts b/packages/core/src/commands/joinBackward.ts index b78aa55d..94f38b8c 100644 --- a/packages/core/src/commands/joinBackward.ts +++ b/packages/core/src/commands/joinBackward.ts @@ -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) } diff --git a/packages/core/src/commands/joinForward.ts b/packages/core/src/commands/joinForward.ts index 851144d0..38ed0ace 100644 --- a/packages/core/src/commands/joinForward.ts +++ b/packages/core/src/commands/joinForward.ts @@ -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) } diff --git a/packages/core/src/commands/keyboardShortcut.ts b/packages/core/src/commands/keyboardShortcut.ts index eb731f55..cf47f6f9 100644 --- a/packages/core/src/commands/keyboardShortcut.ts +++ b/packages/core/src/commands/keyboardShortcut.ts @@ -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, diff --git a/packages/core/src/commands/lift.ts b/packages/core/src/commands/lift.ts index a8dca7d6..86929794 100644 --- a/packages/core/src/commands/lift.ts +++ b/packages/core/src/commands/lift.ts @@ -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) diff --git a/packages/core/src/commands/liftEmptyBlock.ts b/packages/core/src/commands/liftEmptyBlock.ts index 2a40a909..ef7870d6 100644 --- a/packages/core/src/commands/liftEmptyBlock.ts +++ b/packages/core/src/commands/liftEmptyBlock.ts @@ -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) } diff --git a/packages/core/src/commands/liftListItem.ts b/packages/core/src/commands/liftListItem.ts index 2065c51f..afbbf188 100644 --- a/packages/core/src/commands/liftListItem.ts +++ b/packages/core/src/commands/liftListItem.ts @@ -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) diff --git a/packages/core/src/commands/newlineInCode.ts b/packages/core/src/commands/newlineInCode.ts index 312b6c9f..73b3fc88 100644 --- a/packages/core/src/commands/newlineInCode.ts +++ b/packages/core/src/commands/newlineInCode.ts @@ -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) } diff --git a/packages/core/src/commands/replace.ts b/packages/core/src/commands/replace.ts index 0c432054..46b9bbb4 100644 --- a/packages/core/src/commands/replace.ts +++ b/packages/core/src/commands/replace.ts @@ -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 } diff --git a/packages/core/src/commands/replaceRange.ts b/packages/core/src/commands/replaceRange.ts index 4dbd2184..cd0eaff7 100644 --- a/packages/core/src/commands/replaceRange.ts +++ b/packages/core/src/commands/replaceRange.ts @@ -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) diff --git a/packages/core/src/commands/resetNodeAttributes.ts b/packages/core/src/commands/resetNodeAttributes.ts index dfaa502e..908be4bc 100644 --- a/packages/core/src/commands/resetNodeAttributes.ts +++ b/packages/core/src/commands/resetNodeAttributes.ts @@ -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 diff --git a/packages/core/src/commands/scrollIntoView.ts b/packages/core/src/commands/scrollIntoView.ts index 70f6768d..3b3ee43c 100644 --- a/packages/core/src/commands/scrollIntoView.ts +++ b/packages/core/src/commands/scrollIntoView.ts @@ -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() } diff --git a/packages/core/src/commands/selectAll.ts b/packages/core/src/commands/selectAll.ts index 930ed8db..333a055c 100644 --- a/packages/core/src/commands/selectAll.ts +++ b/packages/core/src/commands/selectAll.ts @@ -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) } diff --git a/packages/core/src/commands/selectNodeBackward.ts b/packages/core/src/commands/selectNodeBackward.ts index 26388e33..b961bdef 100644 --- a/packages/core/src/commands/selectNodeBackward.ts +++ b/packages/core/src/commands/selectNodeBackward.ts @@ -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) } diff --git a/packages/core/src/commands/selectNodeForward.ts b/packages/core/src/commands/selectNodeForward.ts index cc6899bd..d5272836 100644 --- a/packages/core/src/commands/selectNodeForward.ts +++ b/packages/core/src/commands/selectNodeForward.ts @@ -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) } diff --git a/packages/core/src/commands/selectParentNode.ts b/packages/core/src/commands/selectParentNode.ts index 37929e42..da5dedd2 100644 --- a/packages/core/src/commands/selectParentNode.ts +++ b/packages/core/src/commands/selectParentNode.ts @@ -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) } diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index b118d8d9..136f9263 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -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) diff --git a/packages/core/src/commands/setMark.ts b/packages/core/src/commands/setMark.ts index 45dcc689..9a673a49 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -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) diff --git a/packages/core/src/commands/setNode.ts b/packages/core/src/commands/setNode.ts index 981437ff..a7e92fa8 100644 --- a/packages/core/src/commands/setNode.ts +++ b/packages/core/src/commands/setNode.ts @@ -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) diff --git a/packages/core/src/commands/sinkListItem.ts b/packages/core/src/commands/sinkListItem.ts index d985474e..8c0e62c3 100644 --- a/packages/core/src/commands/sinkListItem.ts +++ b/packages/core/src/commands/sinkListItem.ts @@ -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) diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index 4ac53b32..2bf91217 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -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, diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index d5215622..55fe93f4 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -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) diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index f107978a..c34997d6 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -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 diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index 026a96aa..1208d190 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -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) diff --git a/packages/core/src/commands/toggleNode.ts b/packages/core/src/commands/toggleNode.ts index 6ff84275..81d78d8a 100644 --- a/packages/core/src/commands/toggleNode.ts +++ b/packages/core/src/commands/toggleNode.ts @@ -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) diff --git a/packages/core/src/commands/toggleWrap.ts b/packages/core/src/commands/toggleWrap.ts index 6c426cc0..c17d7e85 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -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) diff --git a/packages/core/src/commands/undoInputRule.ts b/packages/core/src/commands/undoInputRule.ts index d27b2c9e..9237d334 100644 --- a/packages/core/src/commands/undoInputRule.ts +++ b/packages/core/src/commands/undoInputRule.ts @@ -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) } diff --git a/packages/core/src/commands/unsetAllMarks.ts b/packages/core/src/commands/unsetAllMarks.ts index 5a0abfff..636ddd8a 100644 --- a/packages/core/src/commands/unsetAllMarks.ts +++ b/packages/core/src/commands/unsetAllMarks.ts @@ -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 diff --git a/packages/core/src/commands/unsetMark.ts b/packages/core/src/commands/unsetMark.ts index 7671a29c..1df17bf7 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -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 diff --git a/packages/core/src/commands/updateNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts index ee7cbe18..69ef092e 100644 --- a/packages/core/src/commands/updateNodeAttributes.ts +++ b/packages/core/src/commands/updateNodeAttributes.ts @@ -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 diff --git a/packages/core/src/commands/wrapIn.ts b/packages/core/src/commands/wrapIn.ts index 1d6bebe0..0cae335b 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -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) diff --git a/packages/core/src/commands/wrapInList.ts b/packages/core/src/commands/wrapInList.ts index 33c321ad..f950e11e 100644 --- a/packages/core/src/commands/wrapInList.ts +++ b/packages/core/src/commands/wrapInList.ts @@ -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) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 284c125c..ce276396 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -114,21 +114,21 @@ export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {}) export type UnionCommands = UnionToIntersection>>> -export type Commands = { +export type RawCommands = { [Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any ? (...args: Parameters) => Command : never } export type SingleCommands = { - [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => boolean + [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => boolean : never } export type ChainedCommands = { - [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => ChainedCommands + [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => ChainedCommands : never } & { run: () => boolean