add generic to commands type

This commit is contained in:
Philipp Kühn
2021-06-04 21:56:29 +02:00
parent af91b811bf
commit 78e2a6e775
75 changed files with 258 additions and 272 deletions

View File

@@ -4,7 +4,7 @@ import {
SingleCommands,
ChainedCommands,
CanCommands,
RawCommands,
AnyCommands,
CommandProps,
} from './types'
@@ -12,9 +12,9 @@ export default class CommandManager {
editor: Editor
commands: RawCommands
commands: AnyCommands
constructor(editor: Editor, commands: RawCommands) {
constructor(editor: Editor, commands: AnyCommands) {
this.editor = editor
this.commands = commands
}
@@ -28,7 +28,7 @@ export default class CommandManager {
return Object.fromEntries(Object
.entries(commands)
.map(([name, command]) => {
const method = (...args: never[]) => {
const method = (...args: any[]) => {
const callback = command(...args)(props)
if (!tr.getMeta('preventDispatch')) {
@@ -39,7 +39,7 @@ export default class CommandManager {
}
return [name, method]
})) as SingleCommands
})) as unknown as SingleCommands
}
public createChain(startTr?: Transaction, shouldDispatch = true): ChainedCommands {
@@ -86,7 +86,7 @@ export default class CommandManager {
.entries(commands)
.map(([name, command]) => {
return [name, (...args: never[]) => command(...args)({ ...props, dispatch })]
})) as SingleCommands
})) as unknown as SingleCommands
return {
...formattedCommands,
@@ -117,7 +117,7 @@ export default class CommandManager {
.entries(commands)
.map(([name, command]) => {
return [name, (...args: never[]) => command(...args)(props)]
})) as SingleCommands
})) as unknown as SingleCommands
},
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
blur: {
/**
* Removes focus from the editor.
*/
blur: () => Command,
blur: () => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
clearContent: {
/**
* Clear the whole document.
*/
clearContent: (emitUpdate?: boolean) => Command,
clearContent: (emitUpdate?: boolean) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { liftTarget } from 'prosemirror-transform'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
clearNodes: {
/**
* Normalize nodes to a simple paragraph.
*/
clearNodes: () => Command,
clearNodes: () => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
command: {
/**
* Define a command inline.
*/
command: (fn: (props: Parameters<Command>[0]) => boolean) => Command,
command: (fn: (props: Parameters<Command>[0]) => boolean) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
createParagraphNear: {
/**
* Create a paragraph nearby.
*/
createParagraphNear: () => Command,
createParagraphNear: () => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands, Range } from '../types'
import { RawCommands, Range } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
deleteRange: {
/**
* Delete a given range.
*/
deleteRange: (range: Range) => Command,
deleteRange: (range: Range) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
deleteSelection: {
/**
* Delete the selection, if there is one.
*/
deleteSelection: () => Command,
deleteSelection: () => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
enter: {
/**
* Trigger enter.
*/
enter: () => Command,
enter: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { exitCode as originalExitCode } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
exitCode: {
/**
* Exit from a code block.
*/
exitCode: () => Command,
exitCode: () => ReturnType,
}
}
}

View File

@@ -1,16 +1,16 @@
import { TextSelection } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType'
import getMarkRange from '../helpers/getMarkRange'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
extendMarkRange: {
/**
* Extends the text selection to the current mark.
*/
extendMarkRange: (typeOrName: string | MarkType, attributes?: Record<string, any>) => Command,
extendMarkRange: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
first: {
/**
* Runs one command after the other and stops at the first which returns true.
*/
first: (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])) => Command,
first: (commands: Command[] | ((props: Parameters<Command>[0]) => Command[])) => ReturnType,
}
}
}

View File

@@ -1,5 +1,5 @@
import { EditorState, TextSelection } from 'prosemirror-state'
import { Command, RawCommands, FocusPosition } from '../types'
import { RawCommands, FocusPosition } from '../types'
import minMax from '../utilities/minMax'
import isTextSelection from '../helpers/isTextSelection'
@@ -31,12 +31,12 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) {
}
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
focus: {
/**
* Focus the editor at the given position.
*/
focus: (position?: FocusPosition) => Command,
focus: (position?: FocusPosition) => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands, Content } from '../types'
import { RawCommands, Content } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
insertContent: {
/**
* Insert a node or string of HTML at the current position.
*/
insertContent: (value: Content) => Command,
insertContent: (value: Content) => ReturnType,
}
}
}

View File

@@ -1,19 +1,18 @@
import createNodeFromContent from '../helpers/createNodeFromContent'
import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd'
import {
Command,
RawCommands,
Content,
Range,
} from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
insertContentAt: {
/**
* Insert a node or string of HTML at a specific position.
*/
insertContentAt: (position: number | Range, value: Content) => Command,
insertContentAt: (position: number | Range, value: Content) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
joinBackward: {
/**
* Join two nodes backward.
*/
joinBackward: () => Command,
joinBackward: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { joinForward as originalJoinForward } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
joinForward: {
/**
* Join two nodes forward.
*/
joinForward: () => Command,
joinForward: () => ReturnType,
}
}
}

View File

@@ -1,4 +1,4 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false
@@ -57,12 +57,12 @@ function normalizeKeyName(name: string) {
}
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
keyboardShortcut: {
/**
* Trigger a keyboard shortcut.
*/
keyboardShortcut: (name: string) => Command,
keyboardShortcut: (name: string) => ReturnType,
}
}
}

View File

@@ -1,16 +1,16 @@
import { lift as originalLift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
lift: {
/**
* Removes an existing wrap.
*/
lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
lift: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
liftEmptyBlock: {
/**
* Lift block if empty.
*/
liftEmptyBlock: () => Command,
liftEmptyBlock: () => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
liftListItem: {
/**
* Lift the list item into a wrapping list.
*/
liftListItem: (typeOrName: string | NodeType) => Command,
liftListItem: (typeOrName: string | NodeType) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
newlineInCode: {
/**
* Add a newline character in code.
*/
newlineInCode: () => Command,
newlineInCode: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
replace: {
/**
* Replaces text with a node.
*/
replace: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
replace: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,14 +1,14 @@
import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType'
import { Command, RawCommands, Range } from '../types'
import { RawCommands, Range } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
replaceRange: {
/**
* Replaces text with a node within a range.
*/
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -3,15 +3,15 @@ import getNodeType from '../helpers/getNodeType'
import getMarkType from '../helpers/getMarkType'
import getSchemaTypeNameByName from '../helpers/getSchemaTypeNameByName'
import deleteProps from '../utilities/deleteProps'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
resetAttributes: {
/**
* Resets some node attributes to the default value.
*/
resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => Command,
resetAttributes: (typeOrName: string | NodeType | MarkType, attributes: string | string[]) => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
scrollIntoView: {
/**
* Scroll the selection into view.
*/
scrollIntoView: () => Command,
scrollIntoView: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { selectAll as originalSelectAll } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
selectAll: {
/**
* Select the whole document.
*/
selectAll: () => Command,
selectAll: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
selectNodeBackward: {
/**
* Select a node backward.
*/
selectNodeBackward: () => Command,
selectNodeBackward: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
selectNodeForward: {
/**
* Select a node forward.
*/
selectNodeForward: () => Command,
selectNodeForward: () => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
selectParentNode: {
/**
* Select the parent node.
*/
selectParentNode: () => Command,
selectParentNode: () => ReturnType,
}
}
}

View File

@@ -1,10 +1,10 @@
import { TextSelection } from 'prosemirror-state'
import { ParseOptions } from 'prosemirror-model'
import createDocument from '../helpers/createDocument'
import { Command, RawCommands, Content } from '../types'
import { RawCommands, Content } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setContent: {
/**
* Replace the whole document with new content.
@@ -13,7 +13,7 @@ declare module '@tiptap/core' {
content: Content,
emitUpdate?: boolean,
parseOptions?: ParseOptions,
) => Command,
) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { MarkType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType'
import getMarkAttributes from '../helpers/getMarkAttributes'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setMark: {
/**
* Add a mark with new attributes.
*/
setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => Command,
setMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setMeta: {
/**
* Store a metadata property in the current transaction.
*/
setMeta: (key: string, value: any) => Command,
setMeta: (key: string, value: any) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { NodeType } from 'prosemirror-model'
import { setBlockType } from 'prosemirror-commands'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setNode: {
/**
* Replace a given range with a node.
*/
setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
setNode: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,14 +1,14 @@
import { NodeSelection } from 'prosemirror-state'
import minMax from '../utilities/minMax'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setNodeSelection: {
/**
* Creates a NodeSelection.
*/
setNodeSelection: (position: number) => Command,
setNodeSelection: (position: number) => ReturnType,
}
}
}

View File

@@ -1,14 +1,14 @@
import { TextSelection } from 'prosemirror-state'
import minMax from '../utilities/minMax'
import { Command, RawCommands, Range } from '../types'
import { RawCommands, Range } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
setTextSelection: {
/**
* Creates a TextSelection.
*/
setTextSelection: (position: number | Range) => Command,
setTextSelection: (position: number | Range) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
sinkListItem: {
/**
* Sink the list item down into an inner list.
*/
sinkListItem: (typeOrName: string | NodeType) => Command,
sinkListItem: (typeOrName: string | NodeType) => ReturnType,
}
}
}

View File

@@ -1,7 +1,7 @@
import { canSplit } from 'prosemirror-transform'
import { ContentMatch } from 'prosemirror-model'
import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getSplittedAttributes from '../helpers/getSplittedAttributes'
function defaultBlockAt(match: ContentMatch) {
@@ -27,12 +27,12 @@ function ensureMarks(state: EditorState, splittableMarks?: string[]) {
}
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
splitBlock: {
/**
* Forks a new node from an existing node.
*/
splitBlock: (options?: { keepMarks?: boolean }) => Command,
splitBlock: (options?: { keepMarks?: boolean }) => ReturnType,
}
}
}

View File

@@ -6,17 +6,17 @@ import {
} from 'prosemirror-model'
import { canSplit } from 'prosemirror-transform'
import { TextSelection } from 'prosemirror-state'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
import getSplittedAttributes from '../helpers/getSplittedAttributes'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
splitListItem: {
/**
* Splits one list item into two list items.
*/
splitListItem: (typeOrName: string | NodeType) => Command,
splitListItem: (typeOrName: string | NodeType) => ReturnType,
}
}
}

View File

@@ -1,16 +1,16 @@
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
import findParentNode from '../helpers/findParentNode'
import isList from '../helpers/isList'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
toggleList: {
/**
* Toggle between different list types.
*/
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command,
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { MarkType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType'
import isMarkActive from '../helpers/isMarkActive'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
toggleMark: {
/**
* Toggle a mark on and off.
*/
toggleMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => Command,
toggleMark: (typeOrName: string | MarkType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
toggleNode: {
/**
* Toggle a node with another node.
*/
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,16 +1,16 @@
import { wrapIn, lift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
toggleWrap: {
/**
* Wraps nodes in another node, or removes an existing wrap.
*/
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
toggleWrap: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,13 +1,13 @@
import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
undoInputRule: {
/**
* Undo an input rule.
*/
undoInputRule: () => Command,
undoInputRule: () => ReturnType,
}
}
}

View File

@@ -1,12 +1,12 @@
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
unsetAllMarks: {
/**
* Remove all marks in the current selection.
*/
unsetAllMarks: () => Command,
unsetAllMarks: () => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { MarkType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getMarkType from '../helpers/getMarkType'
import getMarkRange from '../helpers/getMarkRange'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
unsetMark: {
/**
* Remove all marks in the current selection.
*/
unsetMark: (typeOrName: string | MarkType) => Command,
unsetMark: (typeOrName: string | MarkType) => ReturnType,
}
}
}

View File

@@ -2,15 +2,15 @@ import { NodeType, MarkType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType'
import getMarkType from '../helpers/getMarkType'
import getSchemaTypeNameByName from '../helpers/getSchemaTypeNameByName'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
updateAttributes: {
/**
* Update attributes of a node or mark.
*/
updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record<string, any>) => Command,
updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,16 +1,16 @@
import { wrapIn as originalWrapIn } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import isNodeActive from '../helpers/isNodeActive'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
wrapIn: {
/**
* Wraps nodes in another node.
*/
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
wrapIn: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -1,15 +1,15 @@
import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command, RawCommands } from '../types'
import { RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
declare module '@tiptap/core' {
interface Commands {
interface Commands<ReturnType> {
wrapInList: {
/**
* Wrap a node in a list.
*/
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => Command,
wrapInList: (typeOrName: string | NodeType, attributes?: Record<string, any>) => ReturnType,
}
}
}

View File

@@ -38,7 +38,8 @@ export { default as isNodeSelection } from './helpers/isNodeSelection'
export { default as isTextSelection } from './helpers/isTextSelection'
export { default as posToDOMRect } from './helpers/posToDOMRect'
export interface Commands {}
// eslint-disable-next-line
export interface Commands<ReturnType = any> {}
// eslint-disable-next-line
export interface ExtensionConfig<Options = any> {}

View File

@@ -156,24 +156,20 @@ export type NodeViewRendererProps = {
export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {})
export type UnionCommands = UnionToIntersection<ValuesOf<Pick<Commands, KeysWithTypeOf<Commands, {}>>>>
export type AnyCommands = Record<string, (...args: any[]) => Command>
export type UnionCommands<T = Command> = UnionToIntersection<ValuesOf<Pick<Commands<T>, KeysWithTypeOf<Commands<T>, {}>>>>
export type RawCommands = {
[Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<UnionCommands[Item]>) => Command
: never
[Item in keyof UnionCommands]: UnionCommands<Command>[Item]
}
export type SingleCommands = {
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<RawCommands[Item]>) => boolean
: never
[Item in keyof UnionCommands]: UnionCommands<boolean>[Item]
}
export type ChainedCommands = {
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<RawCommands[Item]>) => ChainedCommands
: never
[Item in keyof UnionCommands]: UnionCommands<ChainedCommands>[Item]
} & {
run: () => boolean
}