From ca8d1a42450be9d41adf64697b607c3ca8697f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Tue, 16 Feb 2021 11:27:58 +0100 Subject: [PATCH] add command scope --- .../Annotation/extension/annotation.ts | 8 ++-- docs/src/demos/Experiments/Embeds/iframe.ts | 12 +++--- packages/core/src/CommandManager.ts | 9 ++++- packages/core/src/commands/blur.ts | 12 +++--- packages/core/src/commands/clearContent.ts | 12 +++--- packages/core/src/commands/clearNodes.ts | 12 +++--- packages/core/src/commands/command.ts | 12 +++--- .../core/src/commands/createParagraphNear.ts | 12 +++--- packages/core/src/commands/deleteRange.ts | 12 +++--- packages/core/src/commands/deleteSelection.ts | 12 +++--- packages/core/src/commands/enter.ts | 12 +++--- packages/core/src/commands/exitCode.ts | 12 +++--- packages/core/src/commands/extendMarkRange.ts | 12 +++--- packages/core/src/commands/first.ts | 12 +++--- packages/core/src/commands/focus.ts | 12 +++--- packages/core/src/commands/insertHTML.ts | 12 +++--- packages/core/src/commands/insertText.ts | 12 +++--- packages/core/src/commands/joinBackward.ts | 12 +++--- packages/core/src/commands/joinForward.ts | 12 +++--- .../core/src/commands/keyboardShortcut.ts | 12 +++--- packages/core/src/commands/lift.ts | 12 +++--- packages/core/src/commands/liftEmptyBlock.ts | 12 +++--- packages/core/src/commands/liftListItem.ts | 12 +++--- packages/core/src/commands/newlineInCode.ts | 12 +++--- packages/core/src/commands/replace.ts | 12 +++--- packages/core/src/commands/replaceRange.ts | 12 +++--- .../core/src/commands/resetNodeAttributes.ts | 12 +++--- packages/core/src/commands/scrollIntoView.ts | 12 +++--- packages/core/src/commands/selectAll.ts | 12 +++--- .../core/src/commands/selectNodeBackward.ts | 12 +++--- .../core/src/commands/selectNodeForward.ts | 12 +++--- .../core/src/commands/selectParentNode.ts | 12 +++--- packages/core/src/commands/setContent.ts | 12 +++--- packages/core/src/commands/setMark.ts | 12 +++--- packages/core/src/commands/setNode.ts | 12 +++--- packages/core/src/commands/sinkListItem.ts | 12 +++--- packages/core/src/commands/splitBlock.ts | 12 +++--- packages/core/src/commands/splitListItem.ts | 12 +++--- packages/core/src/commands/toggleList.ts | 12 +++--- packages/core/src/commands/toggleMark.ts | 12 +++--- packages/core/src/commands/toggleNode.ts | 12 +++--- packages/core/src/commands/toggleWrap.ts | 12 +++--- packages/core/src/commands/undoInputRule.ts | 12 +++--- packages/core/src/commands/unsetAllMarks.ts | 12 +++--- packages/core/src/commands/unsetMark.ts | 12 +++--- .../core/src/commands/updateNodeAttributes.ts | 12 +++--- packages/core/src/commands/wrapIn.ts | 12 +++--- packages/core/src/commands/wrapInList.ts | 12 +++--- packages/core/src/index.ts | 2 +- packages/core/src/types.ts | 11 ++++- .../extension-blockquote/src/blockquote.ts | 28 +++++++------ packages/extension-bold/src/bold.ts | 28 +++++++------ .../extension-bullet-list/src/bullet-list.ts | 12 +++--- .../extension-code-block/src/code-block.ts | 20 +++++----- packages/extension-code/src/code.ts | 28 +++++++------ .../src/collaboration-cursor.ts | 12 +++--- .../src/collaboration.ts | 20 +++++----- .../extension-font-family/src/font-family.ts | 20 +++++----- .../extension-hard-break/src/hard-break.ts | 12 +++--- packages/extension-heading/src/heading.ts | 20 +++++----- packages/extension-highlight/src/highlight.ts | 28 +++++++------ packages/extension-history/src/history.ts | 20 +++++----- .../src/horizontal-rule.ts | 12 +++--- packages/extension-image/src/image.ts | 12 +++--- packages/extension-italic/src/italic.ts | 28 +++++++------ packages/extension-link/src/link.ts | 28 +++++++------ .../src/ordered-list.ts | 12 +++--- packages/extension-paragraph/src/paragraph.ts | 12 +++--- packages/extension-strike/src/strike.ts | 28 +++++++------ packages/extension-table/src/table.ts | 40 ++++++++++--------- packages/extension-task-list/src/task-list.ts | 12 +++--- .../extension-text-align/src/text-align.ts | 20 +++++----- .../extension-text-style/src/text-style.ts | 12 +++--- packages/extension-underline/src/underline.ts | 28 +++++++------ 74 files changed, 614 insertions(+), 460 deletions(-) diff --git a/docs/src/demos/Experiments/Annotation/extension/annotation.ts b/docs/src/demos/Experiments/Annotation/extension/annotation.ts index f6b7092d..d0deae95 100644 --- a/docs/src/demos/Experiments/Annotation/extension/annotation.ts +++ b/docs/src/demos/Experiments/Annotation/extension/annotation.ts @@ -14,9 +14,11 @@ export interface AnnotationOptions { } declare module '@tiptap/core' { - interface Commands { - addAnnotation: (content: any) => Command, - deleteAnnotation: (id: number) => Command, + interface AllCommands { + annotation: { + addAnnotation: (content: any) => Command, + deleteAnnotation: (id: number) => Command, + } } } diff --git a/docs/src/demos/Experiments/Embeds/iframe.ts b/docs/src/demos/Experiments/Embeds/iframe.ts index 740ff3ac..f6b0d352 100644 --- a/docs/src/demos/Experiments/Embeds/iframe.ts +++ b/docs/src/demos/Experiments/Embeds/iframe.ts @@ -8,11 +8,13 @@ export interface IframeOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Add an iframe - */ - setIframe: (options: { src: string }) => Command, + interface AllCommands { + iframe: { + /** + * Add an iframe + */ + setIframe: (options: { src: string }) => Command, + } } } diff --git a/packages/core/src/CommandManager.ts b/packages/core/src/CommandManager.ts index f0f40bc5..d06f037a 100644 --- a/packages/core/src/CommandManager.ts +++ b/packages/core/src/CommandManager.ts @@ -35,7 +35,8 @@ export default class CommandManager { .entries(commands) .map(([name, command]) => { const method = (...args: any) => { - const callback = command(...args)(props) + // TODO: fix any + const callback = command(...args as any)(props) if (!tr.getMeta('preventDispatch')) { view.dispatch(tr) @@ -85,7 +86,7 @@ export default class CommandManager { public createCan(startTr?: Transaction): CanCommands { const { commands, editor } = this const { state } = editor - const dispatch = false + const dispatch = undefined const tr = startTr || state.tr const props = this.buildProps(tr, dispatch) const formattedCommands = Object.fromEntries(Object @@ -118,10 +119,14 @@ export default class CommandManager { : undefined, chain: () => this.createChain(tr), can: () => this.createCan(tr), + // TODO: fix + // @ts-ignore get commands() { return Object.fromEntries(Object .entries(commands) .map(([name, command]) => { + // TODO: fix + // @ts-ignore return [name, (...args: any[]) => command(...args)(props)] })) as SingleCommands }, diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts index dbb5297d..17ed7ebe 100644 --- a/packages/core/src/commands/blur.ts +++ b/packages/core/src/commands/blur.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Removes focus from the editor. - */ - blur: () => Command, + interface AllCommands { + blur: { + /** + * Removes focus from the editor. + */ + blur: () => Command, + } } } diff --git a/packages/core/src/commands/clearContent.ts b/packages/core/src/commands/clearContent.ts index dd08f21b..bd9b5482 100644 --- a/packages/core/src/commands/clearContent.ts +++ b/packages/core/src/commands/clearContent.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Clear the whole document. - */ - clearContent: (emitUpdate: Boolean) => Command, + interface AllCommands { + clearContent: { + /** + * Clear the whole document. + */ + clearContent: (emitUpdate: Boolean) => Command, + } } } diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index cb58ff98..b9d5f576 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -2,11 +2,13 @@ import { liftTarget } from 'prosemirror-transform' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Normalize nodes to a simple paragraph. - */ - clearNodes: () => Command, + interface AllCommands { + clearNodes: { + /** + * Normalize nodes to a simple paragraph. + */ + clearNodes: () => Command, + } } } diff --git a/packages/core/src/commands/command.ts b/packages/core/src/commands/command.ts index 9943652b..180f66c5 100644 --- a/packages/core/src/commands/command.ts +++ b/packages/core/src/commands/command.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Define a command inline. - */ - command: (fn: (props: Parameters[0]) => boolean) => Command, + interface AllCommands { + command: { + /** + * Define a command inline. + */ + command: (fn: (props: Parameters[0]) => boolean) => Command, + } } } diff --git a/packages/core/src/commands/createParagraphNear.ts b/packages/core/src/commands/createParagraphNear.ts index 3588d228..04e51fd1 100644 --- a/packages/core/src/commands/createParagraphNear.ts +++ b/packages/core/src/commands/createParagraphNear.ts @@ -2,11 +2,13 @@ import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror- import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Create a paragraph nearby. - */ - createParagraphNear: () => Command, + interface AllCommands { + createParagraphNear: { + /** + * Create a paragraph nearby. + */ + createParagraphNear: () => Command, + } } } diff --git a/packages/core/src/commands/deleteRange.ts b/packages/core/src/commands/deleteRange.ts index 437cb985..41a32903 100644 --- a/packages/core/src/commands/deleteRange.ts +++ b/packages/core/src/commands/deleteRange.ts @@ -1,11 +1,13 @@ import { Command, Commands, Range } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Delete a given range. - */ - deleteRange: (range: Range) => Command, + interface AllCommands { + deleteRange: { + /** + * Delete a given range. + */ + deleteRange: (range: Range) => Command, + } } } diff --git a/packages/core/src/commands/deleteSelection.ts b/packages/core/src/commands/deleteSelection.ts index 65f361ca..87958bb4 100644 --- a/packages/core/src/commands/deleteSelection.ts +++ b/packages/core/src/commands/deleteSelection.ts @@ -2,11 +2,13 @@ import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Delete the selection, if there is one. - */ - deleteSelection: () => Command, + interface AllCommands { + deleteSelection: { + /** + * Delete the selection, if there is one. + */ + deleteSelection: () => Command, + } } } diff --git a/packages/core/src/commands/enter.ts b/packages/core/src/commands/enter.ts index d7b93260..43cf42ab 100644 --- a/packages/core/src/commands/enter.ts +++ b/packages/core/src/commands/enter.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Trigger enter. - */ - enter: () => Command, + interface AllCommands { + enter: { + /** + * Trigger enter. + */ + enter: () => Command, + } } } diff --git a/packages/core/src/commands/exitCode.ts b/packages/core/src/commands/exitCode.ts index 48956654..341c5378 100644 --- a/packages/core/src/commands/exitCode.ts +++ b/packages/core/src/commands/exitCode.ts @@ -2,11 +2,13 @@ import { exitCode as originalExitCode } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Exit from a code block. - */ - exitCode: () => Command, + interface AllCommands { + exitCode: { + /** + * Exit from a code block. + */ + exitCode: () => Command, + } } } diff --git a/packages/core/src/commands/extendMarkRange.ts b/packages/core/src/commands/extendMarkRange.ts index a05fe423..15c1e62a 100644 --- a/packages/core/src/commands/extendMarkRange.ts +++ b/packages/core/src/commands/extendMarkRange.ts @@ -5,11 +5,13 @@ import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' declare module '@tiptap/core' { - interface Commands { - /** - * Extends the text selection to the current mark. - */ - extendMarkRange: (typeOrName: string | MarkType) => Command, + interface AllCommands { + extendMarkRange: { + /** + * Extends the text selection to the current mark. + */ + extendMarkRange: (typeOrName: string | MarkType) => Command, + } } } diff --git a/packages/core/src/commands/first.ts b/packages/core/src/commands/first.ts index b034cc1d..356ec55c 100644 --- a/packages/core/src/commands/first.ts +++ b/packages/core/src/commands/first.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Runs one command after the other and stops at the first which returns true. - */ - first: (commands: Command[] | ((props: Parameters[0]) => Command[])) => Command, + interface AllCommands { + first: { + /** + * Runs one command after the other and stops at the first which returns true. + */ + first: (commands: Command[] | ((props: Parameters[0]) => Command[])) => Command, + } } } diff --git a/packages/core/src/commands/focus.ts b/packages/core/src/commands/focus.ts index 84a26ab1..723dfe2c 100644 --- a/packages/core/src/commands/focus.ts +++ b/packages/core/src/commands/focus.ts @@ -31,11 +31,13 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) { } declare module '@tiptap/core' { - interface Commands { - /** - * Focus the editor at the given position. - */ - focus: (position?: FocusPosition) => Command, + interface AllCommands { + focus: { + /** + * Focus the editor at the given position. + */ + focus: (position?: FocusPosition) => Command, + } } } diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts index b78690ca..bb7bba87 100644 --- a/packages/core/src/commands/insertHTML.ts +++ b/packages/core/src/commands/insertHTML.ts @@ -18,11 +18,13 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number } declare module '@tiptap/core' { - interface Commands { - /** - * Insert a string of HTML at the current position. - */ - insertHTML: (value: string) => Command, + interface AllCommands { + insertHTML: { + /** + * Insert a string of HTML at the current position. + */ + insertHTML: (value: string) => Command, + } } } diff --git a/packages/core/src/commands/insertText.ts b/packages/core/src/commands/insertText.ts index decf70ca..14facef8 100644 --- a/packages/core/src/commands/insertText.ts +++ b/packages/core/src/commands/insertText.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Insert a string of text at the current position. - */ - insertText: (value: string) => Command, + interface AllCommands { + insertText: { + /** + * Insert a string of text at the current position. + */ + insertText: (value: string) => Command, + } } } diff --git a/packages/core/src/commands/joinBackward.ts b/packages/core/src/commands/joinBackward.ts index 799b8014..b78aa55d 100644 --- a/packages/core/src/commands/joinBackward.ts +++ b/packages/core/src/commands/joinBackward.ts @@ -2,11 +2,13 @@ import { joinBackward as originalJoinBackward } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Join two nodes backward. - */ - joinBackward: () => Command, + interface AllCommands { + joinBackward: { + /** + * Join two nodes backward. + */ + joinBackward: () => Command, + } } } diff --git a/packages/core/src/commands/joinForward.ts b/packages/core/src/commands/joinForward.ts index f855d0d6..851144d0 100644 --- a/packages/core/src/commands/joinForward.ts +++ b/packages/core/src/commands/joinForward.ts @@ -2,11 +2,13 @@ import { joinForward as originalJoinForward } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Join two nodes forward. - */ - joinForward: () => Command, + interface AllCommands { + joinForward: { + /** + * Join two nodes forward. + */ + joinForward: () => Command, + } } } diff --git a/packages/core/src/commands/keyboardShortcut.ts b/packages/core/src/commands/keyboardShortcut.ts index 0491f806..eb731f55 100644 --- a/packages/core/src/commands/keyboardShortcut.ts +++ b/packages/core/src/commands/keyboardShortcut.ts @@ -57,11 +57,13 @@ function normalizeKeyName(name: string) { } declare module '@tiptap/core' { - interface Commands { - /** - * Trigger a keyboard shortcut. - */ - keyboardShortcut: (name: string) => Command, + interface AllCommands { + keyboardShortcut: { + /** + * Trigger a keyboard shortcut. + */ + keyboardShortcut: (name: string) => Command, + } } } diff --git a/packages/core/src/commands/lift.ts b/packages/core/src/commands/lift.ts index e2a57673..a8dca7d6 100644 --- a/packages/core/src/commands/lift.ts +++ b/packages/core/src/commands/lift.ts @@ -5,11 +5,13 @@ import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Removes an existing wrap. - */ - lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + lift: { + /** + * Removes an existing wrap. + */ + lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/liftEmptyBlock.ts b/packages/core/src/commands/liftEmptyBlock.ts index f65d4304..2a40a909 100644 --- a/packages/core/src/commands/liftEmptyBlock.ts +++ b/packages/core/src/commands/liftEmptyBlock.ts @@ -2,11 +2,13 @@ import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Lift block if empty. - */ - liftEmptyBlock: () => Command, + interface AllCommands { + liftEmptyBlock: { + /** + * Lift block if empty. + */ + liftEmptyBlock: () => Command, + } } } diff --git a/packages/core/src/commands/liftListItem.ts b/packages/core/src/commands/liftListItem.ts index d6fbf63c..2065c51f 100644 --- a/packages/core/src/commands/liftListItem.ts +++ b/packages/core/src/commands/liftListItem.ts @@ -4,11 +4,13 @@ import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Lift the list item into a wrapping list. - */ - liftListItem: (typeOrName: string | NodeType) => Command, + interface AllCommands { + liftListItem: { + /** + * Lift the list item into a wrapping list. + */ + liftListItem: (typeOrName: string | NodeType) => Command, + } } } diff --git a/packages/core/src/commands/newlineInCode.ts b/packages/core/src/commands/newlineInCode.ts index e23fe609..312b6c9f 100644 --- a/packages/core/src/commands/newlineInCode.ts +++ b/packages/core/src/commands/newlineInCode.ts @@ -2,11 +2,13 @@ import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Add a newline character in code. - */ - newlineInCode: () => Command, + interface AllCommands { + newlineInCode: { + /** + * Add a newline character in code. + */ + newlineInCode: () => Command, + } } } diff --git a/packages/core/src/commands/replace.ts b/packages/core/src/commands/replace.ts index ba63b2f1..0c432054 100644 --- a/packages/core/src/commands/replace.ts +++ b/packages/core/src/commands/replace.ts @@ -2,11 +2,13 @@ import { NodeType } from 'prosemirror-model' import { Command, Commands, AnyObject } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Replaces text with a node. - */ - replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + replace: { + /** + * Replaces text with a node. + */ + replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/replaceRange.ts b/packages/core/src/commands/replaceRange.ts index c067c3d8..4dbd2184 100644 --- a/packages/core/src/commands/replaceRange.ts +++ b/packages/core/src/commands/replaceRange.ts @@ -8,11 +8,13 @@ import { } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Replaces text with a node within a range. - */ - replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + replaceRange: { + /** + * Replaces text with a node within a range. + */ + replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/resetNodeAttributes.ts b/packages/core/src/commands/resetNodeAttributes.ts index 5536cb55..dfaa502e 100644 --- a/packages/core/src/commands/resetNodeAttributes.ts +++ b/packages/core/src/commands/resetNodeAttributes.ts @@ -4,11 +4,13 @@ import deleteProps from '../utilities/deleteProps' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Resets node attributes to the default value. - */ - resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command, + interface AllCommands { + resetNodeAttributes: { + /** + * Resets node attributes to the default value. + */ + resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command, + } } } diff --git a/packages/core/src/commands/scrollIntoView.ts b/packages/core/src/commands/scrollIntoView.ts index 90fba1fb..70f6768d 100644 --- a/packages/core/src/commands/scrollIntoView.ts +++ b/packages/core/src/commands/scrollIntoView.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Scroll the selection into view. - */ - scrollIntoView: () => Command, + interface AllCommands { + scrollIntoView: { + /** + * Scroll the selection into view. + */ + scrollIntoView: () => Command, + } } } diff --git a/packages/core/src/commands/selectAll.ts b/packages/core/src/commands/selectAll.ts index 3d5a6a19..930ed8db 100644 --- a/packages/core/src/commands/selectAll.ts +++ b/packages/core/src/commands/selectAll.ts @@ -2,11 +2,13 @@ import { selectAll as originalSelectAll } from 'prosemirror-commands' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Select the whole document. - */ - selectAll: () => Command, + interface AllCommands { + selectAll: { + /** + * Select the whole document. + */ + selectAll: () => Command, + } } } diff --git a/packages/core/src/commands/selectNodeBackward.ts b/packages/core/src/commands/selectNodeBackward.ts index d31c70ac..26388e33 100644 --- a/packages/core/src/commands/selectNodeBackward.ts +++ b/packages/core/src/commands/selectNodeBackward.ts @@ -2,11 +2,13 @@ import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-co import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Select a node backward. - */ - selectNodeBackward: () => Command, + interface AllCommands { + selectNodeBackward: { + /** + * Select a node backward. + */ + selectNodeBackward: () => Command, + } } } diff --git a/packages/core/src/commands/selectNodeForward.ts b/packages/core/src/commands/selectNodeForward.ts index de44cf6a..cc6899bd 100644 --- a/packages/core/src/commands/selectNodeForward.ts +++ b/packages/core/src/commands/selectNodeForward.ts @@ -2,11 +2,13 @@ import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-comm import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Select a node forward. - */ - selectNodeForward: () => Command, + interface AllCommands { + selectNodeForward: { + /** + * Select a node forward. + */ + selectNodeForward: () => Command, + } } } diff --git a/packages/core/src/commands/selectParentNode.ts b/packages/core/src/commands/selectParentNode.ts index 503b3f19..37929e42 100644 --- a/packages/core/src/commands/selectParentNode.ts +++ b/packages/core/src/commands/selectParentNode.ts @@ -2,11 +2,13 @@ import { selectParentNode as originalSelectParentNode } from 'prosemirror-comman import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Select the parent node. - */ - selectParentNode: () => Command, + interface AllCommands { + selectParentNode: { + /** + * Select the parent node. + */ + selectParentNode: () => Command, + } } } diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index ecf7e816..b118d8d9 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -2,11 +2,13 @@ import { TextSelection } from 'prosemirror-state' import { AnyObject, Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Replace the whole document with new content. - */ - setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command, + interface AllCommands { + setContent: { + /** + * Replace the whole document with new content. + */ + setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/setMark.ts b/packages/core/src/commands/setMark.ts index 27090137..45dcc689 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -4,11 +4,13 @@ import getMarkType from '../helpers/getMarkType' import getMarkAttributes from '../helpers/getMarkAttributes' declare module '@tiptap/core' { - interface Commands { - /** - * Add a mark with new attributes. - */ - setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + interface AllCommands { + setMark: { + /** + * Add a mark with new attributes. + */ + setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/setNode.ts b/packages/core/src/commands/setNode.ts index 91fedbc4..981437ff 100644 --- a/packages/core/src/commands/setNode.ts +++ b/packages/core/src/commands/setNode.ts @@ -4,11 +4,13 @@ import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Replace a given range with a node. - */ - setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + setNode: { + /** + * Replace a given range with a node. + */ + setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/sinkListItem.ts b/packages/core/src/commands/sinkListItem.ts index e99c59f6..d985474e 100644 --- a/packages/core/src/commands/sinkListItem.ts +++ b/packages/core/src/commands/sinkListItem.ts @@ -4,11 +4,13 @@ import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Sink the list item down into an inner list. - */ - sinkListItem: (typeOrName: string | NodeType) => Command, + interface AllCommands { + sinkListItem: { + /** + * Sink the list item down into an inner list. + */ + sinkListItem: (typeOrName: string | NodeType) => Command, + } } } diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index 37754324..4ac53b32 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -25,11 +25,13 @@ function ensureMarks(state: EditorState) { } declare module '@tiptap/core' { - interface Commands { - /** - * Forks a new node from an existing node. - */ - splitBlock: (options?: { keepMarks?: boolean }) => Command, + interface AllCommands { + splitBlock: { + /** + * Forks a new node from an existing node. + */ + splitBlock: (options?: { keepMarks?: boolean }) => Command, + } } } diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index 53f0ffac..d5215622 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -11,11 +11,13 @@ import getNodeType from '../helpers/getNodeType' import getSplittedAttributes from '../helpers/getSplittedAttributes' declare module '@tiptap/core' { - interface Commands { - /** - * Splits one list item into two list items. - */ - splitListItem: (typeOrName: string | NodeType) => Command, + interface AllCommands { + splitListItem: { + /** + * Splits one list item into two list items. + */ + splitListItem: (typeOrName: string | NodeType) => Command, + } } } diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index 93ced519..f107978a 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -5,11 +5,13 @@ import findParentNode from '../helpers/findParentNode' import isList from '../helpers/isList' declare module '@tiptap/core' { - interface Commands { - /** - * Toggle between different list types. - */ - toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command, + interface AllCommands { + toggleList: { + /** + * Toggle between different list types. + */ + toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command, + } } } diff --git a/packages/core/src/commands/toggleMark.ts b/packages/core/src/commands/toggleMark.ts index 2216184e..026a96aa 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -4,11 +4,13 @@ import getMarkType from '../helpers/getMarkType' import isMarkActive from '../helpers/isMarkActive' declare module '@tiptap/core' { - interface Commands { - /** - * Toggle a mark on and off. - */ - toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + interface AllCommands { + toggleMark: { + /** + * Toggle a mark on and off. + */ + toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/toggleNode.ts b/packages/core/src/commands/toggleNode.ts index 65eb7f3a..6ff84275 100644 --- a/packages/core/src/commands/toggleNode.ts +++ b/packages/core/src/commands/toggleNode.ts @@ -4,11 +4,13 @@ import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Toggle a node with another node. - */ - toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + toggleNode: { + /** + * Toggle a node with another node. + */ + toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/toggleWrap.ts b/packages/core/src/commands/toggleWrap.ts index 9ffd02a2..6c426cc0 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -5,11 +5,13 @@ import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Wraps nodes in another node, or removes an existing wrap. - */ - toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + toggleWrap: { + /** + * Wraps nodes in another node, or removes an existing wrap. + */ + toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/undoInputRule.ts b/packages/core/src/commands/undoInputRule.ts index 548ca029..d27b2c9e 100644 --- a/packages/core/src/commands/undoInputRule.ts +++ b/packages/core/src/commands/undoInputRule.ts @@ -2,11 +2,13 @@ import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules' import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Undo an input rule. - */ - undoInputRule: () => Command, + interface AllCommands { + undoInputRule: { + /** + * Undo an input rule. + */ + undoInputRule: () => Command, + } } } diff --git a/packages/core/src/commands/unsetAllMarks.ts b/packages/core/src/commands/unsetAllMarks.ts index cdec2648..5a0abfff 100644 --- a/packages/core/src/commands/unsetAllMarks.ts +++ b/packages/core/src/commands/unsetAllMarks.ts @@ -1,11 +1,13 @@ import { Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Remove all marks in the current selection. - */ - unsetAllMarks: () => Command, + interface AllCommands { + unsetAllMarks: { + /** + * Remove all marks in the current selection. + */ + unsetAllMarks: () => Command, + } } } diff --git a/packages/core/src/commands/unsetMark.ts b/packages/core/src/commands/unsetMark.ts index da56827d..7671a29c 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -4,11 +4,13 @@ import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' declare module '@tiptap/core' { - interface Commands { - /** - * Remove all marks in the current selection. - */ - unsetMark: (typeOrName: string | MarkType) => Command, + interface AllCommands { + unsetMark: { + /** + * Remove all marks in the current selection. + */ + unsetMark: (typeOrName: string | MarkType) => Command, + } } } diff --git a/packages/core/src/commands/updateNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts index 000610b4..ee7cbe18 100644 --- a/packages/core/src/commands/updateNodeAttributes.ts +++ b/packages/core/src/commands/updateNodeAttributes.ts @@ -3,11 +3,13 @@ import getNodeType from '../helpers/getNodeType' import { AnyObject, Command, Commands } from '../types' declare module '@tiptap/core' { - interface Commands { - /** - * Update attributes of a node. - */ - updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command, + interface AllCommands { + updateNodeAttributes: { + /** + * Update attributes of a node. + */ + updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/wrapIn.ts b/packages/core/src/commands/wrapIn.ts index b0ea8a82..1d6bebe0 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -5,11 +5,13 @@ import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Wraps nodes in another node. - */ - wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + wrapIn: { + /** + * Wraps nodes in another node. + */ + wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/commands/wrapInList.ts b/packages/core/src/commands/wrapInList.ts index e0d1894b..33c321ad 100644 --- a/packages/core/src/commands/wrapInList.ts +++ b/packages/core/src/commands/wrapInList.ts @@ -4,11 +4,13 @@ import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' declare module '@tiptap/core' { - interface Commands { - /** - * Wrap a node in a list. - */ - wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + interface AllCommands { + wrapInList: { + /** + * Wrap a node in a list. + */ + wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } } diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index cfa75a8f..8b19b1bc 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -22,4 +22,4 @@ export { default as isCellSelection } from './helpers/isCellSelection' export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos' export interface AllExtensions {} -export interface Commands {} +export interface AllCommands {} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index c31f59d5..16426428 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -14,9 +14,9 @@ import { Extension } from './Extension' import { Node } from './Node' import { Mark } from './Mark' import { Editor } from './Editor' -import { Commands } from '.' +import { AllCommands } from '.' -export { Commands } +export { AllCommands } export type Extensions = (Extension | Node | Mark)[] @@ -120,6 +120,13 @@ export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {}) export type ValuesOf = T[keyof T]; export type KeysWithTypeOf = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] +export type UnionCommands = UnionToIntersection>>> + +export type Commands = { + [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 diff --git a/packages/extension-blockquote/src/blockquote.ts b/packages/extension-blockquote/src/blockquote.ts index f3aa8452..049b5059 100644 --- a/packages/extension-blockquote/src/blockquote.ts +++ b/packages/extension-blockquote/src/blockquote.ts @@ -8,19 +8,21 @@ export interface BlockquoteOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a blockquote node - */ - setBlockquote: () => Command, - /** - * Toggle a blockquote node - */ - toggleBlockquote: () => Command, - /** - * Unset a blockquote node - */ - unsetBlockquote: () => Command, + interface AllCommands { + blockQuote: { + /** + * Set a blockquote node + */ + setBlockquote: () => Command, + /** + * Toggle a blockquote node + */ + toggleBlockquote: () => Command, + /** + * Unset a blockquote node + */ + unsetBlockquote: () => Command, + } } } diff --git a/packages/extension-bold/src/bold.ts b/packages/extension-bold/src/bold.ts index 60e9c1db..45df059b 100644 --- a/packages/extension-bold/src/bold.ts +++ b/packages/extension-bold/src/bold.ts @@ -13,19 +13,21 @@ export interface BoldOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a bold mark - */ - setBold: () => Command, - /** - * Toggle a bold mark - */ - toggleBold: () => Command, - /** - * Unset a bold mark - */ - unsetBold: () => Command, + interface AllCommands { + bold: { + /** + * Set a bold mark + */ + setBold: () => Command, + /** + * Toggle a bold mark + */ + toggleBold: () => Command, + /** + * Unset a bold mark + */ + unsetBold: () => Command, + } } } diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 8a4fa658..ec206f86 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -8,11 +8,13 @@ export interface BulletListOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Toggle a bullet list - */ - toggleBulletList: () => Command, + interface AllCommands { + bulletList: { + /** + * Toggle a bullet list + */ + toggleBulletList: () => Command, + } } } diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index c55cfc7e..a67a5471 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -9,15 +9,17 @@ export interface CodeBlockOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a code block - */ - setCodeBlock: (attributes?: { language: string }) => Command, - /** - * Toggle a code block - */ - toggleCodeBlock: (attributes?: { language: string }) => Command, + interface AllCommands { + codeBlock: { + /** + * Set a code block + */ + setCodeBlock: (attributes?: { language: string }) => Command, + /** + * Toggle a code block + */ + toggleCodeBlock: (attributes?: { language: string }) => Command, + } } } diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index 014572a6..d276c85d 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -13,19 +13,21 @@ export interface CodeOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a code mark - */ - setCode: () => Command, - /** - * Toggle inline code - */ - toggleCode: () => Command, - /** - * Unset a code mark - */ - unsetCode: () => Command, + interface AllCommands { + code: { + /** + * Set a code mark + */ + setCode: () => Command, + /** + * Toggle inline code + */ + toggleCode: () => Command, + /** + * Unset a code mark + */ + unsetCode: () => Command, + } } } diff --git a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts index fcaa64a9..c3148dec 100644 --- a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts +++ b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts @@ -9,11 +9,13 @@ export interface CollaborationCursorOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Update details of the current user - */ - user: (attributes: AnyObject) => Command, + interface AllCommands { + collaborationCursor: { + /** + * Update details of the current user + */ + user: (attributes: AnyObject) => Command, + } } } diff --git a/packages/extension-collaboration/src/collaboration.ts b/packages/extension-collaboration/src/collaboration.ts index bf57f436..008a4e57 100644 --- a/packages/extension-collaboration/src/collaboration.ts +++ b/packages/extension-collaboration/src/collaboration.ts @@ -7,15 +7,17 @@ import { } from 'y-prosemirror' declare module '@tiptap/core' { - interface Commands { - /** - * Undo recent changes - */ - undo: () => Command, - /** - * Reapply reverted changes - */ - redo: () => Command, + interface AllCommands { + collaboration: { + /** + * Undo recent changes + */ + undo: () => Command, + /** + * Reapply reverted changes + */ + redo: () => Command, + } } } diff --git a/packages/extension-font-family/src/font-family.ts b/packages/extension-font-family/src/font-family.ts index 33610ecb..446bb346 100644 --- a/packages/extension-font-family/src/font-family.ts +++ b/packages/extension-font-family/src/font-family.ts @@ -6,15 +6,17 @@ type FontFamilyOptions = { } declare module '@tiptap/core' { - interface Commands { - /** - * Set the font family - */ - setFontFamily: (fontFamily: string) => Command, - /** - * Unset the font family - */ - unsetFontFamily: () => Command, + interface AllCommands { + fontFamily: { + /** + * Set the font family + */ + setFontFamily: (fontFamily: string) => Command, + /** + * Unset the font family + */ + unsetFontFamily: () => Command, + } } } diff --git a/packages/extension-hard-break/src/hard-break.ts b/packages/extension-hard-break/src/hard-break.ts index 84e3adee..8f7bb8a9 100644 --- a/packages/extension-hard-break/src/hard-break.ts +++ b/packages/extension-hard-break/src/hard-break.ts @@ -8,11 +8,13 @@ export interface HardBreakOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Add a hard break - */ - setHardBreak: () => Command, + interface AllCommands { + hardBreak: { + /** + * Add a hard break + */ + setHardBreak: () => Command, + } } } diff --git a/packages/extension-heading/src/heading.ts b/packages/extension-heading/src/heading.ts index 1325d44d..65b70446 100644 --- a/packages/extension-heading/src/heading.ts +++ b/packages/extension-heading/src/heading.ts @@ -11,15 +11,17 @@ export interface HeadingOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a heading node - */ - setHeading: (attributes: { level: Level }) => Command, - /** - * Toggle a heading node - */ - toggleHeading: (attributes: { level: Level }) => Command, + interface AllCommands { + heading: { + /** + * Set a heading node + */ + setHeading: (attributes: { level: Level }) => Command, + /** + * Toggle a heading node + */ + toggleHeading: (attributes: { level: Level }) => Command, + } } } diff --git a/packages/extension-highlight/src/highlight.ts b/packages/extension-highlight/src/highlight.ts index 06726c9c..2b19924b 100644 --- a/packages/extension-highlight/src/highlight.ts +++ b/packages/extension-highlight/src/highlight.ts @@ -14,19 +14,21 @@ export interface HighlightOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a highlight mark - */ - setHighlight: (attributes?: { color: string }) => Command, - /** - * Toggle a highlight mark - */ - toggleHighlight: (attributes?: { color: string }) => Command, - /** - * Unset a highlight mark - */ - unsetHighlight: () => Command, + interface AllCommands { + highlight: { + /** + * Set a highlight mark + */ + setHighlight: (attributes?: { color: string }) => Command, + /** + * Toggle a highlight mark + */ + toggleHighlight: (attributes?: { color: string }) => Command, + /** + * Unset a highlight mark + */ + unsetHighlight: () => Command, + } } } diff --git a/packages/extension-history/src/history.ts b/packages/extension-history/src/history.ts index 4ea1efc5..f70558e9 100644 --- a/packages/extension-history/src/history.ts +++ b/packages/extension-history/src/history.ts @@ -7,15 +7,17 @@ export interface HistoryOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Undo recent changes - */ - undo: () => Command, - /** - * Reapply reverted changes - */ - redo: () => Command, + interface AllCommands { + history: { + /** + * Undo recent changes + */ + undo: () => Command, + /** + * Reapply reverted changes + */ + redo: () => Command, + } } } diff --git a/packages/extension-horizontal-rule/src/horizontal-rule.ts b/packages/extension-horizontal-rule/src/horizontal-rule.ts index a19344f2..e1e2d648 100644 --- a/packages/extension-horizontal-rule/src/horizontal-rule.ts +++ b/packages/extension-horizontal-rule/src/horizontal-rule.ts @@ -12,11 +12,13 @@ export interface HorizontalRuleOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Add a horizontal rule - */ - setHorizontalRule: () => Command, + interface AllCommands { + horizontalRule: { + /** + * Add a horizontal rule + */ + setHorizontalRule: () => Command, + } } } diff --git a/packages/extension-image/src/image.ts b/packages/extension-image/src/image.ts index 8e2ba38b..947eed22 100644 --- a/packages/extension-image/src/image.ts +++ b/packages/extension-image/src/image.ts @@ -13,11 +13,13 @@ export interface ImageOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Add an image - */ - setImage: (options: { src: string, alt?: string, title?: string }) => Command, + interface AllCommands { + image: { + /** + * Add an image + */ + setImage: (options: { src: string, alt?: string, title?: string }) => Command, + } } } diff --git a/packages/extension-italic/src/italic.ts b/packages/extension-italic/src/italic.ts index 60b2f6ad..7842a049 100644 --- a/packages/extension-italic/src/italic.ts +++ b/packages/extension-italic/src/italic.ts @@ -13,19 +13,21 @@ export interface ItalicOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set an italic mark - */ - setItalic: () => Command, - /** - * Toggle an italic mark - */ - toggleItalic: () => Command, - /** - * Unset an italic mark - */ - unsetItalic: () => Command, + interface AllCommands { + italic: { + /** + * Set an italic mark + */ + setItalic: () => Command, + /** + * Toggle an italic mark + */ + toggleItalic: () => Command, + /** + * Unset an italic mark + */ + unsetItalic: () => Command, + } } } diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 0e694975..9199ac09 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -14,19 +14,21 @@ export interface LinkOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a link mark - */ - setLink: (attributes: { href: string, target?: string }) => Command, - /** - * Toggle a link mark - */ - toggleLink: (attributes: { href: string, target?: string }) => Command, - /** - * Unset a link mark - */ - unsetLink: () => Command, + interface AllCommands { + link: { + /** + * Set a link mark + */ + setLink: (attributes: { href: string, target?: string }) => Command, + /** + * Toggle a link mark + */ + toggleLink: (attributes: { href: string, target?: string }) => Command, + /** + * Unset a link mark + */ + unsetLink: () => Command, + } } } diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 41c68a3e..b602c0ab 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -8,11 +8,13 @@ export interface OrderedListOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Toggle an ordered list - */ - toggleOrderedList: () => Command, + interface AllCommands { + orderedList: { + /** + * Toggle an ordered list + */ + toggleOrderedList: () => Command, + } } } diff --git a/packages/extension-paragraph/src/paragraph.ts b/packages/extension-paragraph/src/paragraph.ts index d7b7fb5f..6e9ac939 100644 --- a/packages/extension-paragraph/src/paragraph.ts +++ b/packages/extension-paragraph/src/paragraph.ts @@ -7,11 +7,13 @@ export interface ParagraphOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Toggle a paragraph - */ - setParagraph: () => Command, + interface AllCommands { + paragraph: { + /** + * Toggle a paragraph + */ + setParagraph: () => Command, + } } } diff --git a/packages/extension-strike/src/strike.ts b/packages/extension-strike/src/strike.ts index ef5cb8c3..33fdb5f3 100644 --- a/packages/extension-strike/src/strike.ts +++ b/packages/extension-strike/src/strike.ts @@ -13,19 +13,21 @@ export interface StrikeOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set a strike mark - */ - setStrike: () => Command, - /** - * Toggle a strike mark - */ - toggleStrike: () => Command, - /** - * Unset a strike mark - */ - unsetStrike: () => Command, + interface AllCommands { + strike: { + /** + * Set a strike mark + */ + setStrike: () => Command, + /** + * Toggle a strike mark + */ + toggleStrike: () => Command, + /** + * Unset a strike mark + */ + unsetStrike: () => Command, + } } } diff --git a/packages/extension-table/src/table.ts b/packages/extension-table/src/table.ts index a28762f3..66d9cd65 100644 --- a/packages/extension-table/src/table.ts +++ b/packages/extension-table/src/table.ts @@ -42,25 +42,27 @@ export interface TableOptions { } declare module '@tiptap/core' { - interface Commands { - 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, + interface AllCommands { + 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, + } } } diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index 0bc6142d..0c0e47bb 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -7,11 +7,13 @@ export interface TaskListOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Toggle a task list - */ - toggleTaskList: () => Command, + interface AllCommands { + taskList: { + /** + * Toggle a task list + */ + toggleTaskList: () => Command, + } } } diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index a9044cb5..be8c8fd3 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -7,15 +7,17 @@ type TextAlignOptions = { } declare module '@tiptap/core' { - interface Commands { - /** - * Set the text align attribute - */ - setTextAlign: (alignment: string) => Command, - /** - * Unset the text align attribute - */ - unsetTextAlign: () => Command, + interface AllCommands { + textAlign: { + /** + * Set the text align attribute + */ + setTextAlign: (alignment: string) => Command, + /** + * Unset the text align attribute + */ + unsetTextAlign: () => Command, + } } } diff --git a/packages/extension-text-style/src/text-style.ts b/packages/extension-text-style/src/text-style.ts index 0d66e0c6..a3687b72 100644 --- a/packages/extension-text-style/src/text-style.ts +++ b/packages/extension-text-style/src/text-style.ts @@ -12,11 +12,13 @@ export interface TextStyleOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Remove spans without inline style attributes. - */ - removeEmptyTextStyle: () => Command, + interface AllCommands { + textStyle: { + /** + * Remove spans without inline style attributes. + */ + removeEmptyTextStyle: () => Command, + } } } diff --git a/packages/extension-underline/src/underline.ts b/packages/extension-underline/src/underline.ts index 940632fa..75e503b2 100644 --- a/packages/extension-underline/src/underline.ts +++ b/packages/extension-underline/src/underline.ts @@ -7,19 +7,21 @@ export interface UnderlineOptions { } declare module '@tiptap/core' { - interface Commands { - /** - * Set an underline mark - */ - setUnderline: () => Command, - /** - * Toggle an underline mark - */ - toggleUnderline: () => Command, - /** - * Unset an underline mark - */ - unsetUnderline: () => Command, + interface AllCommands { + underline: { + /** + * Set an underline mark + */ + setUnderline: () => Command, + /** + * Toggle an underline mark + */ + toggleUnderline: () => Command, + /** + * Unset an underline mark + */ + unsetUnderline: () => Command, + } } }