From 78e2a6e7758d82e173e1bef1b6f735b092c4ccad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 4 Jun 2021 21:56:29 +0200 Subject: [PATCH] add generic to commands type --- packages/core/src/CommandManager.ts | 14 +++---- packages/core/src/commands/blur.ts | 6 +-- packages/core/src/commands/clearContent.ts | 6 +-- packages/core/src/commands/clearNodes.ts | 6 +-- packages/core/src/commands/command.ts | 4 +- .../core/src/commands/createParagraphNear.ts | 6 +-- packages/core/src/commands/deleteRange.ts | 6 +-- packages/core/src/commands/deleteSelection.ts | 6 +-- packages/core/src/commands/enter.ts | 6 +-- packages/core/src/commands/exitCode.ts | 6 +-- packages/core/src/commands/extendMarkRange.ts | 6 +-- packages/core/src/commands/first.ts | 4 +- packages/core/src/commands/focus.ts | 6 +-- packages/core/src/commands/insertContent.ts | 6 +-- packages/core/src/commands/insertContentAt.ts | 5 +-- packages/core/src/commands/joinBackward.ts | 6 +-- packages/core/src/commands/joinForward.ts | 6 +-- .../core/src/commands/keyboardShortcut.ts | 6 +-- packages/core/src/commands/lift.ts | 6 +-- packages/core/src/commands/liftEmptyBlock.ts | 6 +-- packages/core/src/commands/liftListItem.ts | 6 +-- packages/core/src/commands/newlineInCode.ts | 6 +-- packages/core/src/commands/replace.ts | 6 +-- packages/core/src/commands/replaceRange.ts | 6 +-- packages/core/src/commands/resetAttributes.ts | 6 +-- packages/core/src/commands/scrollIntoView.ts | 6 +-- packages/core/src/commands/selectAll.ts | 6 +-- .../core/src/commands/selectNodeBackward.ts | 6 +-- .../core/src/commands/selectNodeForward.ts | 6 +-- .../core/src/commands/selectParentNode.ts | 6 +-- packages/core/src/commands/setContent.ts | 6 +-- packages/core/src/commands/setMark.ts | 6 +-- packages/core/src/commands/setMeta.ts | 6 +-- packages/core/src/commands/setNode.ts | 6 +-- .../core/src/commands/setNodeSelection.ts | 6 +-- .../core/src/commands/setTextSelection.ts | 6 +-- packages/core/src/commands/sinkListItem.ts | 6 +-- packages/core/src/commands/splitBlock.ts | 6 +-- packages/core/src/commands/splitListItem.ts | 6 +-- packages/core/src/commands/toggleList.ts | 6 +-- packages/core/src/commands/toggleMark.ts | 6 +-- packages/core/src/commands/toggleNode.ts | 6 +-- packages/core/src/commands/toggleWrap.ts | 6 +-- packages/core/src/commands/undoInputRule.ts | 6 +-- packages/core/src/commands/unsetAllMarks.ts | 6 +-- packages/core/src/commands/unsetMark.ts | 6 +-- .../core/src/commands/updateAttributes.ts | 6 +-- packages/core/src/commands/wrapIn.ts | 6 +-- packages/core/src/commands/wrapInList.ts | 6 +-- packages/core/src/index.ts | 3 +- packages/core/src/types.ts | 16 +++----- .../extension-blockquote/src/blockquote.ts | 10 ++--- packages/extension-bold/src/bold.ts | 9 ++-- .../extension-bullet-list/src/bullet-list.ts | 6 +-- .../extension-code-block/src/code-block.ts | 8 ++-- packages/extension-code/src/code.ts | 9 ++-- .../src/collaboration-cursor.ts | 6 +-- .../src/collaboration.ts | 8 ++-- .../extension-font-family/src/font-family.ts | 8 ++-- .../extension-hard-break/src/hard-break.ts | 6 +-- packages/extension-heading/src/heading.ts | 8 ++-- packages/extension-highlight/src/highlight.ts | 9 ++-- packages/extension-history/src/history.ts | 8 ++-- .../src/horizontal-rule.ts | 5 +-- packages/extension-image/src/image.ts | 5 +-- packages/extension-italic/src/italic.ts | 9 ++-- packages/extension-link/src/link.ts | 9 ++-- .../src/ordered-list.ts | 6 +-- packages/extension-paragraph/src/paragraph.ts | 6 +-- packages/extension-strike/src/strike.ts | 9 ++-- packages/extension-table/src/table.ts | 41 +++++++++---------- packages/extension-task-list/src/task-list.ts | 6 +-- .../extension-text-align/src/text-align.ts | 8 ++-- .../extension-text-style/src/text-style.ts | 5 +-- packages/extension-underline/src/underline.ts | 10 ++--- 75 files changed, 258 insertions(+), 272 deletions(-) diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index 6fdf6582..6a19e7a8 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -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 }, } diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts index 2090e5b4..2137091b 100644 --- a/packages/core/src/commands/blur.ts +++ b/packages/core/src/commands/blur.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { blur: { /** * Removes focus from the editor. */ - blur: () => Command, + blur: () => ReturnType, } } } diff --git a/packages/core/src/commands/clearContent.ts b/packages/core/src/commands/clearContent.ts index c28cf448..ccefd7b5 100644 --- a/packages/core/src/commands/clearContent.ts +++ b/packages/core/src/commands/clearContent.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { clearContent: { /** * Clear the whole document. */ - clearContent: (emitUpdate?: boolean) => Command, + clearContent: (emitUpdate?: boolean) => ReturnType, } } } diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index 7e4cfd59..5f90083f 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -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 { clearNodes: { /** * Normalize nodes to a simple paragraph. */ - clearNodes: () => Command, + clearNodes: () => ReturnType, } } } diff --git a/packages/core/src/commands/command.ts b/packages/core/src/commands/command.ts index 18de28e4..0cfba783 100644 --- a/packages/core/src/commands/command.ts +++ b/packages/core/src/commands/command.ts @@ -1,12 +1,12 @@ import { Command, RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { command: { /** * Define a command inline. */ - command: (fn: (props: Parameters[0]) => boolean) => Command, + command: (fn: (props: Parameters[0]) => boolean) => ReturnType, } } } diff --git a/packages/core/src/commands/createParagraphNear.ts b/packages/core/src/commands/createParagraphNear.ts index 1ad0deba..48631b0e 100644 --- a/packages/core/src/commands/createParagraphNear.ts +++ b/packages/core/src/commands/createParagraphNear.ts @@ -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 { createParagraphNear: { /** * Create a paragraph nearby. */ - createParagraphNear: () => Command, + createParagraphNear: () => ReturnType, } } } diff --git a/packages/core/src/commands/deleteRange.ts b/packages/core/src/commands/deleteRange.ts index 07bc98e4..f9a041ff 100644 --- a/packages/core/src/commands/deleteRange.ts +++ b/packages/core/src/commands/deleteRange.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands, Range } from '../types' +import { RawCommands, Range } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { deleteRange: { /** * Delete a given range. */ - deleteRange: (range: Range) => Command, + deleteRange: (range: Range) => ReturnType, } } } diff --git a/packages/core/src/commands/deleteSelection.ts b/packages/core/src/commands/deleteSelection.ts index 296f5239..65ead68e 100644 --- a/packages/core/src/commands/deleteSelection.ts +++ b/packages/core/src/commands/deleteSelection.ts @@ -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 { deleteSelection: { /** * Delete the selection, if there is one. */ - deleteSelection: () => Command, + deleteSelection: () => ReturnType, } } } diff --git a/packages/core/src/commands/enter.ts b/packages/core/src/commands/enter.ts index 7a3987fc..bdab0fbc 100644 --- a/packages/core/src/commands/enter.ts +++ b/packages/core/src/commands/enter.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { enter: { /** * Trigger enter. */ - enter: () => Command, + enter: () => ReturnType, } } } diff --git a/packages/core/src/commands/exitCode.ts b/packages/core/src/commands/exitCode.ts index 2f6a4873..e07420a2 100644 --- a/packages/core/src/commands/exitCode.ts +++ b/packages/core/src/commands/exitCode.ts @@ -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 { exitCode: { /** * Exit from a code block. */ - exitCode: () => Command, + exitCode: () => ReturnType, } } } diff --git a/packages/core/src/commands/extendMarkRange.ts b/packages/core/src/commands/extendMarkRange.ts index 793334f7..b44317ce 100644 --- a/packages/core/src/commands/extendMarkRange.ts +++ b/packages/core/src/commands/extendMarkRange.ts @@ -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 { extendMarkRange: { /** * Extends the text selection to the current mark. */ - extendMarkRange: (typeOrName: string | MarkType, attributes?: Record) => Command, + extendMarkRange: (typeOrName: string | MarkType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/first.ts b/packages/core/src/commands/first.ts index 22c7b2cd..fe4f27b6 100644 --- a/packages/core/src/commands/first.ts +++ b/packages/core/src/commands/first.ts @@ -1,12 +1,12 @@ import { Command, RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { first: { /** * Runs one command after the other and stops at the first which returns true. */ - first: (commands: Command[] | ((props: Parameters[0]) => Command[])) => Command, + first: (commands: Command[] | ((props: Parameters[0]) => Command[])) => ReturnType, } } } diff --git a/packages/core/src/commands/focus.ts b/packages/core/src/commands/focus.ts index c1ad5f5f..dd3aee21 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, 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 { focus: { /** * Focus the editor at the given position. */ - focus: (position?: FocusPosition) => Command, + focus: (position?: FocusPosition) => ReturnType, } } } diff --git a/packages/core/src/commands/insertContent.ts b/packages/core/src/commands/insertContent.ts index ac28af3c..9b8db913 100644 --- a/packages/core/src/commands/insertContent.ts +++ b/packages/core/src/commands/insertContent.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands, Content } from '../types' +import { RawCommands, Content } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { insertContent: { /** * Insert a node or string of HTML at the current position. */ - insertContent: (value: Content) => Command, + insertContent: (value: Content) => ReturnType, } } } diff --git a/packages/core/src/commands/insertContentAt.ts b/packages/core/src/commands/insertContentAt.ts index 829ec1bc..22e6fc7d 100644 --- a/packages/core/src/commands/insertContentAt.ts +++ b/packages/core/src/commands/insertContentAt.ts @@ -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 { 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, } } } diff --git a/packages/core/src/commands/joinBackward.ts b/packages/core/src/commands/joinBackward.ts index d08d4d64..23dfb741 100644 --- a/packages/core/src/commands/joinBackward.ts +++ b/packages/core/src/commands/joinBackward.ts @@ -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 { joinBackward: { /** * Join two nodes backward. */ - joinBackward: () => Command, + joinBackward: () => ReturnType, } } } diff --git a/packages/core/src/commands/joinForward.ts b/packages/core/src/commands/joinForward.ts index 4432e20c..3296cb92 100644 --- a/packages/core/src/commands/joinForward.ts +++ b/packages/core/src/commands/joinForward.ts @@ -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 { joinForward: { /** * Join two nodes forward. */ - joinForward: () => Command, + joinForward: () => ReturnType, } } } diff --git a/packages/core/src/commands/keyboardShortcut.ts b/packages/core/src/commands/keyboardShortcut.ts index a3d04362..b5c7d71a 100644 --- a/packages/core/src/commands/keyboardShortcut.ts +++ b/packages/core/src/commands/keyboardShortcut.ts @@ -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 { keyboardShortcut: { /** * Trigger a keyboard shortcut. */ - keyboardShortcut: (name: string) => Command, + keyboardShortcut: (name: string) => ReturnType, } } } diff --git a/packages/core/src/commands/lift.ts b/packages/core/src/commands/lift.ts index 9c671090..b245e9d7 100644 --- a/packages/core/src/commands/lift.ts +++ b/packages/core/src/commands/lift.ts @@ -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 { lift: { /** * Removes an existing wrap. */ - lift: (typeOrName: string | NodeType, attributes?: Record) => Command, + lift: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/liftEmptyBlock.ts b/packages/core/src/commands/liftEmptyBlock.ts index 868fb4fd..af054d36 100644 --- a/packages/core/src/commands/liftEmptyBlock.ts +++ b/packages/core/src/commands/liftEmptyBlock.ts @@ -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 { liftEmptyBlock: { /** * Lift block if empty. */ - liftEmptyBlock: () => Command, + liftEmptyBlock: () => ReturnType, } } } diff --git a/packages/core/src/commands/liftListItem.ts b/packages/core/src/commands/liftListItem.ts index 57a8e730..97266886 100644 --- a/packages/core/src/commands/liftListItem.ts +++ b/packages/core/src/commands/liftListItem.ts @@ -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 { liftListItem: { /** * Lift the list item into a wrapping list. */ - liftListItem: (typeOrName: string | NodeType) => Command, + liftListItem: (typeOrName: string | NodeType) => ReturnType, } } } diff --git a/packages/core/src/commands/newlineInCode.ts b/packages/core/src/commands/newlineInCode.ts index 2b02d056..63baef67 100644 --- a/packages/core/src/commands/newlineInCode.ts +++ b/packages/core/src/commands/newlineInCode.ts @@ -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 { newlineInCode: { /** * Add a newline character in code. */ - newlineInCode: () => Command, + newlineInCode: () => ReturnType, } } } diff --git a/packages/core/src/commands/replace.ts b/packages/core/src/commands/replace.ts index f3a12d54..a74e86c8 100644 --- a/packages/core/src/commands/replace.ts +++ b/packages/core/src/commands/replace.ts @@ -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 { replace: { /** * Replaces text with a node. */ - replace: (typeOrName: string | NodeType, attributes?: Record) => Command, + replace: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/replaceRange.ts b/packages/core/src/commands/replaceRange.ts index 66867d26..2b0848fb 100644 --- a/packages/core/src/commands/replaceRange.ts +++ b/packages/core/src/commands/replaceRange.ts @@ -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 { replaceRange: { /** * Replaces text with a node within a range. */ - replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: Record) => Command, + replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/resetAttributes.ts b/packages/core/src/commands/resetAttributes.ts index e9c6bf6c..020bac6b 100644 --- a/packages/core/src/commands/resetAttributes.ts +++ b/packages/core/src/commands/resetAttributes.ts @@ -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 { 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, } } } diff --git a/packages/core/src/commands/scrollIntoView.ts b/packages/core/src/commands/scrollIntoView.ts index 11abd33c..39e97a36 100644 --- a/packages/core/src/commands/scrollIntoView.ts +++ b/packages/core/src/commands/scrollIntoView.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { scrollIntoView: { /** * Scroll the selection into view. */ - scrollIntoView: () => Command, + scrollIntoView: () => ReturnType, } } } diff --git a/packages/core/src/commands/selectAll.ts b/packages/core/src/commands/selectAll.ts index 6745ce31..a63b5a76 100644 --- a/packages/core/src/commands/selectAll.ts +++ b/packages/core/src/commands/selectAll.ts @@ -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 { selectAll: { /** * Select the whole document. */ - selectAll: () => Command, + selectAll: () => ReturnType, } } } diff --git a/packages/core/src/commands/selectNodeBackward.ts b/packages/core/src/commands/selectNodeBackward.ts index de373ddb..24e30398 100644 --- a/packages/core/src/commands/selectNodeBackward.ts +++ b/packages/core/src/commands/selectNodeBackward.ts @@ -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 { selectNodeBackward: { /** * Select a node backward. */ - selectNodeBackward: () => Command, + selectNodeBackward: () => ReturnType, } } } diff --git a/packages/core/src/commands/selectNodeForward.ts b/packages/core/src/commands/selectNodeForward.ts index 8181be94..193b4692 100644 --- a/packages/core/src/commands/selectNodeForward.ts +++ b/packages/core/src/commands/selectNodeForward.ts @@ -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 { selectNodeForward: { /** * Select a node forward. */ - selectNodeForward: () => Command, + selectNodeForward: () => ReturnType, } } } diff --git a/packages/core/src/commands/selectParentNode.ts b/packages/core/src/commands/selectParentNode.ts index 211afd09..b6fcaa0d 100644 --- a/packages/core/src/commands/selectParentNode.ts +++ b/packages/core/src/commands/selectParentNode.ts @@ -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 { selectParentNode: { /** * Select the parent node. */ - selectParentNode: () => Command, + selectParentNode: () => ReturnType, } } } diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index 85fcb914..1e7452fc 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -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 { setContent: { /** * Replace the whole document with new content. @@ -13,7 +13,7 @@ declare module '@tiptap/core' { content: Content, emitUpdate?: boolean, parseOptions?: ParseOptions, - ) => Command, + ) => ReturnType, } } } diff --git a/packages/core/src/commands/setMark.ts b/packages/core/src/commands/setMark.ts index e97bcf38..511ab822 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -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 { setMark: { /** * Add a mark with new attributes. */ - setMark: (typeOrName: string | MarkType, attributes?: Record) => Command, + setMark: (typeOrName: string | MarkType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/setMeta.ts b/packages/core/src/commands/setMeta.ts index 50afbbe0..cae39082 100644 --- a/packages/core/src/commands/setMeta.ts +++ b/packages/core/src/commands/setMeta.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { setMeta: { /** * Store a metadata property in the current transaction. */ - setMeta: (key: string, value: any) => Command, + setMeta: (key: string, value: any) => ReturnType, } } } diff --git a/packages/core/src/commands/setNode.ts b/packages/core/src/commands/setNode.ts index 98479e77..51210f07 100644 --- a/packages/core/src/commands/setNode.ts +++ b/packages/core/src/commands/setNode.ts @@ -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 { setNode: { /** * Replace a given range with a node. */ - setNode: (typeOrName: string | NodeType, attributes?: Record) => Command, + setNode: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/setNodeSelection.ts b/packages/core/src/commands/setNodeSelection.ts index 2ec8722f..3fd07590 100644 --- a/packages/core/src/commands/setNodeSelection.ts +++ b/packages/core/src/commands/setNodeSelection.ts @@ -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 { setNodeSelection: { /** * Creates a NodeSelection. */ - setNodeSelection: (position: number) => Command, + setNodeSelection: (position: number) => ReturnType, } } } diff --git a/packages/core/src/commands/setTextSelection.ts b/packages/core/src/commands/setTextSelection.ts index bf4a56d9..123249f4 100644 --- a/packages/core/src/commands/setTextSelection.ts +++ b/packages/core/src/commands/setTextSelection.ts @@ -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 { setTextSelection: { /** * Creates a TextSelection. */ - setTextSelection: (position: number | Range) => Command, + setTextSelection: (position: number | Range) => ReturnType, } } } diff --git a/packages/core/src/commands/sinkListItem.ts b/packages/core/src/commands/sinkListItem.ts index a52959d5..6b914da0 100644 --- a/packages/core/src/commands/sinkListItem.ts +++ b/packages/core/src/commands/sinkListItem.ts @@ -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 { sinkListItem: { /** * Sink the list item down into an inner list. */ - sinkListItem: (typeOrName: string | NodeType) => Command, + sinkListItem: (typeOrName: string | NodeType) => ReturnType, } } } diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index 4c3bf5f8..4096a2dd 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 } 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 { splitBlock: { /** * Forks a new node from an existing node. */ - splitBlock: (options?: { keepMarks?: boolean }) => Command, + splitBlock: (options?: { keepMarks?: boolean }) => ReturnType, } } } diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index 0aa6e830..0292d27e 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -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 { splitListItem: { /** * Splits one list item into two list items. */ - splitListItem: (typeOrName: string | NodeType) => Command, + splitListItem: (typeOrName: string | NodeType) => ReturnType, } } } diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index bda4861c..b548b7b2 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -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 { toggleList: { /** * Toggle between different list types. */ - toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command, + toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => ReturnType, } } } diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index 7db81ab9..fa0b9ed1 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -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 { toggleMark: { /** * Toggle a mark on and off. */ - toggleMark: (typeOrName: string | MarkType, attributes?: Record) => Command, + toggleMark: (typeOrName: string | MarkType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/toggleNode.ts b/packages/core/src/commands/toggleNode.ts index a8568b01..d8c0e0a1 100644 --- a/packages/core/src/commands/toggleNode.ts +++ b/packages/core/src/commands/toggleNode.ts @@ -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 { toggleNode: { /** * Toggle a node with another node. */ - toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: Record) => Command, + toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/toggleWrap.ts b/packages/core/src/commands/toggleWrap.ts index 24933507..d59e2dc5 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -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 { toggleWrap: { /** * Wraps nodes in another node, or removes an existing wrap. */ - toggleWrap: (typeOrName: string | NodeType, attributes?: Record) => Command, + toggleWrap: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/undoInputRule.ts b/packages/core/src/commands/undoInputRule.ts index f232cc09..f7a7f602 100644 --- a/packages/core/src/commands/undoInputRule.ts +++ b/packages/core/src/commands/undoInputRule.ts @@ -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 { undoInputRule: { /** * Undo an input rule. */ - undoInputRule: () => Command, + undoInputRule: () => ReturnType, } } } diff --git a/packages/core/src/commands/unsetAllMarks.ts b/packages/core/src/commands/unsetAllMarks.ts index b84307d0..7742af63 100644 --- a/packages/core/src/commands/unsetAllMarks.ts +++ b/packages/core/src/commands/unsetAllMarks.ts @@ -1,12 +1,12 @@ -import { Command, RawCommands } from '../types' +import { RawCommands } from '../types' declare module '@tiptap/core' { - interface Commands { + interface Commands { unsetAllMarks: { /** * Remove all marks in the current selection. */ - unsetAllMarks: () => Command, + unsetAllMarks: () => ReturnType, } } } diff --git a/packages/core/src/commands/unsetMark.ts b/packages/core/src/commands/unsetMark.ts index bee3e197..a4db42fc 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -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 { unsetMark: { /** * Remove all marks in the current selection. */ - unsetMark: (typeOrName: string | MarkType) => Command, + unsetMark: (typeOrName: string | MarkType) => ReturnType, } } } diff --git a/packages/core/src/commands/updateAttributes.ts b/packages/core/src/commands/updateAttributes.ts index 262a682d..ceed6577 100644 --- a/packages/core/src/commands/updateAttributes.ts +++ b/packages/core/src/commands/updateAttributes.ts @@ -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 { updateAttributes: { /** * Update attributes of a node or mark. */ - updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record) => Command, + updateAttributes: (typeOrName: string | NodeType | MarkType, attributes: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/wrapIn.ts b/packages/core/src/commands/wrapIn.ts index e31d7083..0d7db9d0 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -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 { wrapIn: { /** * Wraps nodes in another node. */ - wrapIn: (typeOrName: string | NodeType, attributes?: Record) => Command, + wrapIn: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/commands/wrapInList.ts b/packages/core/src/commands/wrapInList.ts index e1ad677d..20cc4efc 100644 --- a/packages/core/src/commands/wrapInList.ts +++ b/packages/core/src/commands/wrapInList.ts @@ -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 { wrapInList: { /** * Wrap a node in a list. */ - wrapInList: (typeOrName: string | NodeType, attributes?: Record) => Command, + wrapInList: (typeOrName: string | NodeType, attributes?: Record) => ReturnType, } } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 9b51a996..e07c6bf4 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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 {} // eslint-disable-next-line export interface ExtensionConfig {} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 0551b7ad..ecf29c0d 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -156,24 +156,20 @@ export type NodeViewRendererProps = { export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {}) -export type UnionCommands = UnionToIntersection>>> +export type AnyCommands = Record Command> + +export type UnionCommands = UnionToIntersection, KeysWithTypeOf, {}>>>> export type RawCommands = { - [Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => Command - : never + [Item in keyof UnionCommands]: UnionCommands[Item] } export type SingleCommands = { - [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => boolean - : never + [Item in keyof UnionCommands]: UnionCommands[Item] } export type ChainedCommands = { - [Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => ChainedCommands - : never + [Item in keyof UnionCommands]: UnionCommands[Item] } & { run: () => boolean } diff --git a/packages/extension-blockquote/src/blockquote.ts b/packages/extension-blockquote/src/blockquote.ts index 521bbc9e..16b89889 100644 --- a/packages/extension-blockquote/src/blockquote.ts +++ b/packages/extension-blockquote/src/blockquote.ts @@ -1,4 +1,4 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' export interface BlockquoteOptions { @@ -6,20 +6,20 @@ export interface BlockquoteOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { blockQuote: { /** * Set a blockquote node */ - setBlockquote: () => Command, + setBlockquote: () => ReturnType, /** * Toggle a blockquote node */ - toggleBlockquote: () => Command, + toggleBlockquote: () => ReturnType, /** * Unset a blockquote node */ - unsetBlockquote: () => Command, + unsetBlockquote: () => ReturnType, } } } diff --git a/packages/extension-bold/src/bold.ts b/packages/extension-bold/src/bold.ts index 05599964..a39e2443 100644 --- a/packages/extension-bold/src/bold.ts +++ b/packages/extension-bold/src/bold.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markInputRule, markPasteRule, @@ -11,20 +10,20 @@ export interface BoldOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { bold: { /** * Set a bold mark */ - setBold: () => Command, + setBold: () => ReturnType, /** * Toggle a bold mark */ - toggleBold: () => Command, + toggleBold: () => ReturnType, /** * Unset a bold mark */ - unsetBold: () => Command, + unsetBold: () => ReturnType, } } } diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 30e4cb9b..8c3c432f 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -1,4 +1,4 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' export interface BulletListOptions { @@ -6,12 +6,12 @@ export interface BulletListOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { bulletList: { /** * Toggle a bullet list */ - toggleBulletList: () => Command, + toggleBulletList: () => ReturnType, } } } diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index 1119b7de..9368f28c 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -1,4 +1,4 @@ -import { Command, Node } from '@tiptap/core' +import { Node } from '@tiptap/core' import { textblockTypeInputRule } from 'prosemirror-inputrules' export interface CodeBlockOptions { @@ -7,16 +7,16 @@ export interface CodeBlockOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { codeBlock: { /** * Set a code block */ - setCodeBlock: (attributes?: { language: string }) => Command, + setCodeBlock: (attributes?: { language: string }) => ReturnType, /** * Toggle a code block */ - toggleCodeBlock: (attributes?: { language: string }) => Command, + toggleCodeBlock: (attributes?: { language: string }) => ReturnType, } } } diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index 8e4e48f1..ddc9cfa0 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markInputRule, markPasteRule, @@ -11,20 +10,20 @@ export interface CodeOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { code: { /** * Set a code mark */ - setCode: () => Command, + setCode: () => ReturnType, /** * Toggle inline code */ - toggleCode: () => Command, + toggleCode: () => ReturnType, /** * Unset a code mark */ - unsetCode: () => Command, + unsetCode: () => ReturnType, } } } diff --git a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts index 9a60eddc..66f22da3 100644 --- a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts +++ b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts @@ -1,4 +1,4 @@ -import { Extension, Command } from '@tiptap/core' +import { Extension } from '@tiptap/core' import { yCursorPlugin } from 'y-prosemirror' export interface CollaborationCursorOptions { @@ -9,12 +9,12 @@ export interface CollaborationCursorOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { collaborationCursor: { /** * Update details of the current user */ - user: (attributes: Record) => Command, + user: (attributes: Record) => ReturnType, } } } diff --git a/packages/extension-collaboration/src/collaboration.ts b/packages/extension-collaboration/src/collaboration.ts index 725ac6bb..e0ce339d 100644 --- a/packages/extension-collaboration/src/collaboration.ts +++ b/packages/extension-collaboration/src/collaboration.ts @@ -1,4 +1,4 @@ -import { Extension, Command } from '@tiptap/core' +import { Extension } from '@tiptap/core' import { UndoManager } from 'yjs' import { redo, @@ -9,16 +9,16 @@ import { } from 'y-prosemirror' declare module '@tiptap/core' { - interface Commands { + interface Commands { collaboration: { /** * Undo recent changes */ - undo: () => Command, + undo: () => ReturnType, /** * Reapply reverted changes */ - redo: () => Command, + redo: () => ReturnType, } } } diff --git a/packages/extension-font-family/src/font-family.ts b/packages/extension-font-family/src/font-family.ts index 5c407561..1dff324a 100644 --- a/packages/extension-font-family/src/font-family.ts +++ b/packages/extension-font-family/src/font-family.ts @@ -1,4 +1,4 @@ -import { Command, Extension } from '@tiptap/core' +import { Extension } from '@tiptap/core' import '@tiptap/extension-text-style' type FontFamilyOptions = { @@ -6,16 +6,16 @@ type FontFamilyOptions = { } declare module '@tiptap/core' { - interface Commands { + interface Commands { fontFamily: { /** * Set the font family */ - setFontFamily: (fontFamily: string) => Command, + setFontFamily: (fontFamily: string) => ReturnType, /** * Unset the font family */ - unsetFontFamily: () => Command, + unsetFontFamily: () => ReturnType, } } } diff --git a/packages/extension-hard-break/src/hard-break.ts b/packages/extension-hard-break/src/hard-break.ts index c0f515c4..7d9fb206 100644 --- a/packages/extension-hard-break/src/hard-break.ts +++ b/packages/extension-hard-break/src/hard-break.ts @@ -1,16 +1,16 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' export interface HardBreakOptions { HTMLAttributes: Record, } declare module '@tiptap/core' { - interface Commands { + interface Commands { hardBreak: { /** * Add a hard break */ - setHardBreak: () => Command, + setHardBreak: () => ReturnType, } } } diff --git a/packages/extension-heading/src/heading.ts b/packages/extension-heading/src/heading.ts index 97c9e9c4..a0f493ec 100644 --- a/packages/extension-heading/src/heading.ts +++ b/packages/extension-heading/src/heading.ts @@ -1,4 +1,4 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' import { textblockTypeInputRule } from 'prosemirror-inputrules' type Level = 1 | 2 | 3 | 4 | 5 | 6 @@ -9,16 +9,16 @@ export interface HeadingOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { heading: { /** * Set a heading node */ - setHeading: (attributes: { level: Level }) => Command, + setHeading: (attributes: { level: Level }) => ReturnType, /** * Toggle a heading node */ - toggleHeading: (attributes: { level: Level }) => Command, + toggleHeading: (attributes: { level: Level }) => ReturnType, } } } diff --git a/packages/extension-highlight/src/highlight.ts b/packages/extension-highlight/src/highlight.ts index 9a032129..2f41c2d0 100644 --- a/packages/extension-highlight/src/highlight.ts +++ b/packages/extension-highlight/src/highlight.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markInputRule, markPasteRule, @@ -12,20 +11,20 @@ export interface HighlightOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { highlight: { /** * Set a highlight mark */ - setHighlight: (attributes?: { color: string }) => Command, + setHighlight: (attributes?: { color: string }) => ReturnType, /** * Toggle a highlight mark */ - toggleHighlight: (attributes?: { color: string }) => Command, + toggleHighlight: (attributes?: { color: string }) => ReturnType, /** * Unset a highlight mark */ - unsetHighlight: () => Command, + unsetHighlight: () => ReturnType, } } } diff --git a/packages/extension-history/src/history.ts b/packages/extension-history/src/history.ts index 308ebfc2..dfaa9622 100644 --- a/packages/extension-history/src/history.ts +++ b/packages/extension-history/src/history.ts @@ -1,4 +1,4 @@ -import { Command, Extension } from '@tiptap/core' +import { Extension } from '@tiptap/core' import { history, undo, redo } from 'prosemirror-history' export interface HistoryOptions { @@ -7,16 +7,16 @@ export interface HistoryOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { history: { /** * Undo recent changes */ - undo: () => Command, + undo: () => ReturnType, /** * Reapply reverted changes */ - redo: () => Command, + redo: () => ReturnType, } } } diff --git a/packages/extension-horizontal-rule/src/horizontal-rule.ts b/packages/extension-horizontal-rule/src/horizontal-rule.ts index af302107..409b96d2 100644 --- a/packages/extension-horizontal-rule/src/horizontal-rule.ts +++ b/packages/extension-horizontal-rule/src/horizontal-rule.ts @@ -1,5 +1,4 @@ import { - Command, Node, nodeInputRule, mergeAttributes, @@ -11,12 +10,12 @@ export interface HorizontalRuleOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { horizontalRule: { /** * Add a horizontal rule */ - setHorizontalRule: () => Command, + setHorizontalRule: () => ReturnType, } } } diff --git a/packages/extension-image/src/image.ts b/packages/extension-image/src/image.ts index 987d893c..7bfe871b 100644 --- a/packages/extension-image/src/image.ts +++ b/packages/extension-image/src/image.ts @@ -1,5 +1,4 @@ import { - Command, Node, nodeInputRule, mergeAttributes, @@ -11,12 +10,12 @@ export interface ImageOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { image: { /** * Add an image */ - setImage: (options: { src: string, alt?: string, title?: string }) => Command, + setImage: (options: { src: string, alt?: string, title?: string }) => ReturnType, } } } diff --git a/packages/extension-italic/src/italic.ts b/packages/extension-italic/src/italic.ts index 00316292..9cc818cf 100644 --- a/packages/extension-italic/src/italic.ts +++ b/packages/extension-italic/src/italic.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markInputRule, markPasteRule, @@ -11,20 +10,20 @@ export interface ItalicOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { italic: { /** * Set an italic mark */ - setItalic: () => Command, + setItalic: () => ReturnType, /** * Toggle an italic mark */ - toggleItalic: () => Command, + toggleItalic: () => ReturnType, /** * Unset an italic mark */ - unsetItalic: () => Command, + unsetItalic: () => ReturnType, } } } diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 36e5ce2c..c92a8ffc 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markPasteRule, mergeAttributes, @@ -22,20 +21,20 @@ export interface LinkOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { link: { /** * Set a link mark */ - setLink: (attributes: { href: string, target?: string }) => Command, + setLink: (attributes: { href: string, target?: string }) => ReturnType, /** * Toggle a link mark */ - toggleLink: (attributes: { href: string, target?: string }) => Command, + toggleLink: (attributes: { href: string, target?: string }) => ReturnType, /** * Unset a link mark */ - unsetLink: () => Command, + unsetLink: () => ReturnType, } } } diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 51dad268..38d880bc 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -1,4 +1,4 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' import { wrappingInputRule } from 'prosemirror-inputrules' export interface OrderedListOptions { @@ -6,12 +6,12 @@ export interface OrderedListOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { orderedList: { /** * Toggle an ordered list */ - toggleOrderedList: () => Command, + toggleOrderedList: () => ReturnType, } } } diff --git a/packages/extension-paragraph/src/paragraph.ts b/packages/extension-paragraph/src/paragraph.ts index 3adcc244..da881ba5 100644 --- a/packages/extension-paragraph/src/paragraph.ts +++ b/packages/extension-paragraph/src/paragraph.ts @@ -1,16 +1,16 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' export interface ParagraphOptions { HTMLAttributes: Record, } declare module '@tiptap/core' { - interface Commands { + interface Commands { paragraph: { /** * Toggle a paragraph */ - setParagraph: () => Command, + setParagraph: () => ReturnType, } } } diff --git a/packages/extension-strike/src/strike.ts b/packages/extension-strike/src/strike.ts index 1bb25fd3..879ad047 100644 --- a/packages/extension-strike/src/strike.ts +++ b/packages/extension-strike/src/strike.ts @@ -1,5 +1,4 @@ import { - Command, Mark, markInputRule, markPasteRule, @@ -11,20 +10,20 @@ export interface StrikeOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { strike: { /** * Set a strike mark */ - setStrike: () => Command, + setStrike: () => ReturnType, /** * Toggle a strike mark */ - toggleStrike: () => Command, + toggleStrike: () => ReturnType, /** * Unset a strike mark */ - unsetStrike: () => Command, + unsetStrike: () => ReturnType, } } } diff --git a/packages/extension-table/src/table.ts b/packages/extension-table/src/table.ts index 5985d243..abb3eb39 100644 --- a/packages/extension-table/src/table.ts +++ b/packages/extension-table/src/table.ts @@ -1,6 +1,5 @@ import { Node, - Command, ParentConfig, mergeAttributes, getExtensionField, @@ -43,27 +42,27 @@ export interface TableOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { table: { - insertTable: (options?: { rows?: number, cols?: number, withHeaderRow?: boolean }) => Command, - addColumnBefore: () => Command, - addColumnAfter: () => Command, - deleteColumn: () => Command, - addRowBefore: () => Command, - addRowAfter: () => Command, - deleteRow: () => Command, - deleteTable: () => Command, - mergeCells: () => Command, - splitCell: () => Command, - toggleHeaderColumn: () => Command, - toggleHeaderRow: () => Command, - toggleHeaderCell: () => Command, - mergeOrSplit: () => Command, - setCellAttribute: (name: string, value: any) => Command, - goToNextCell: () => Command, - goToPreviousCell: () => Command, - fixTables: () => Command, - setCellSelection: (position: { anchorCell: number, headCell?: number }) => Command, + insertTable: (options?: { rows?: number, cols?: number, withHeaderRow?: boolean }) => ReturnType, + addColumnBefore: () => ReturnType, + addColumnAfter: () => ReturnType, + deleteColumn: () => ReturnType, + addRowBefore: () => ReturnType, + addRowAfter: () => ReturnType, + deleteRow: () => ReturnType, + deleteTable: () => ReturnType, + mergeCells: () => ReturnType, + splitCell: () => ReturnType, + toggleHeaderColumn: () => ReturnType, + toggleHeaderRow: () => ReturnType, + toggleHeaderCell: () => ReturnType, + mergeOrSplit: () => ReturnType, + setCellAttribute: (name: string, value: any) => ReturnType, + goToNextCell: () => ReturnType, + goToPreviousCell: () => ReturnType, + fixTables: () => ReturnType, + setCellSelection: (position: { anchorCell: number, headCell?: number }) => ReturnType, } } diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index 8ac433c6..f52d57dc 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -1,16 +1,16 @@ -import { Command, Node, mergeAttributes } from '@tiptap/core' +import { Node, mergeAttributes } from '@tiptap/core' export interface TaskListOptions { HTMLAttributes: Record, } declare module '@tiptap/core' { - interface Commands { + interface Commands { taskList: { /** * Toggle a task list */ - toggleTaskList: () => Command, + toggleTaskList: () => ReturnType, } } } diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index b65c6d1a..d18202fd 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -1,4 +1,4 @@ -import { Command, Extension } from '@tiptap/core' +import { Extension } from '@tiptap/core' type TextAlignOptions = { types: string[], @@ -7,16 +7,16 @@ type TextAlignOptions = { } declare module '@tiptap/core' { - interface Commands { + interface Commands { textAlign: { /** * Set the text align attribute */ - setTextAlign: (alignment: string) => Command, + setTextAlign: (alignment: string) => ReturnType, /** * Unset the text align attribute */ - unsetTextAlign: () => Command, + unsetTextAlign: () => ReturnType, } } } diff --git a/packages/extension-text-style/src/text-style.ts b/packages/extension-text-style/src/text-style.ts index 41580443..cf4122a7 100644 --- a/packages/extension-text-style/src/text-style.ts +++ b/packages/extension-text-style/src/text-style.ts @@ -1,5 +1,4 @@ import { - Command, Mark, getMarkAttributes, mergeAttributes, @@ -10,12 +9,12 @@ export interface TextStyleOptions { } declare module '@tiptap/core' { - interface Commands { + interface Commands { textStyle: { /** * Remove spans without inline style attributes. */ - removeEmptyTextStyle: () => Command, + removeEmptyTextStyle: () => ReturnType, } } } diff --git a/packages/extension-underline/src/underline.ts b/packages/extension-underline/src/underline.ts index e0fc223f..5e1b790e 100644 --- a/packages/extension-underline/src/underline.ts +++ b/packages/extension-underline/src/underline.ts @@ -1,24 +1,24 @@ -import { Command, Mark, mergeAttributes } from '@tiptap/core' +import { Mark, mergeAttributes } from '@tiptap/core' export interface UnderlineOptions { HTMLAttributes: Record, } declare module '@tiptap/core' { - interface Commands { + interface Commands { underline: { /** * Set an underline mark */ - setUnderline: () => Command, + setUnderline: () => ReturnType, /** * Toggle an underline mark */ - toggleUnderline: () => Command, + toggleUnderline: () => ReturnType, /** * Unset an underline mark */ - unsetUnderline: () => Command, + unsetUnderline: () => ReturnType, } } }