diff --git a/docs/src/demos/Experiments/Embeds/iframe.ts b/docs/src/demos/Experiments/Embeds/iframe.ts index 2ca2e9a4f..740ff3ac6 100644 --- a/docs/src/demos/Experiments/Embeds/iframe.ts +++ b/docs/src/demos/Experiments/Embeds/iframe.ts @@ -9,6 +9,9 @@ export interface IframeOptions { declare module '@tiptap/core' { interface Commands { + /** + * Add an iframe + */ setIframe: (options: { src: string }) => Command, } } @@ -58,9 +61,6 @@ export default Node.create({ addCommands() { return { - /** - * Add an iframe - */ setIframe: (options: { src: string }) => ({ tr, dispatch }) => { const { selection } = tr const node = this.type.create(options) diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts index 41a67af84..dbb5297d2 100644 --- a/packages/core/src/commands/blur.ts +++ b/packages/core/src/commands/blur.ts @@ -1,8 +1,14 @@ import { Command, Commands } from '../types' -/** - * Removes focus from the editor. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Removes focus from the editor. + */ + blur: () => Command, + } +} + export const blur: Commands['blur'] = () => ({ view }) => { const element = view.dom as HTMLElement @@ -10,9 +16,3 @@ export const blur: Commands['blur'] = () => ({ view }) => { return true } - -declare module '@tiptap/core' { - interface Commands { - blur: () => Command, - } -} diff --git a/packages/core/src/commands/clearContent.ts b/packages/core/src/commands/clearContent.ts index 2624ef128..dd08f21b3 100644 --- a/packages/core/src/commands/clearContent.ts +++ b/packages/core/src/commands/clearContent.ts @@ -1,14 +1,14 @@ import { Command, Commands } from '../types' -/** - * Clear the whole document. - */ -export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => { - return commands.setContent('', emitUpdate) -} - declare module '@tiptap/core' { interface Commands { + /** + * Clear the whole document. + */ clearContent: (emitUpdate: Boolean) => Command, } } + +export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => { + return commands.setContent('', emitUpdate) +} diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index fa92ff08d..cb58ff982 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -1,9 +1,15 @@ import { liftTarget } from 'prosemirror-transform' import { Command, Commands } from '../types' -/** - * Normalize nodes to a simple paragraph. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Normalize nodes to a simple paragraph. + */ + clearNodes: () => Command, + } +} + export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => { const { selection } = tr const { from, to } = selection @@ -30,9 +36,3 @@ export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch } return true } - -declare module '@tiptap/core' { - interface Commands { - clearNodes: () => Command, - } -} diff --git a/packages/core/src/commands/command.ts b/packages/core/src/commands/command.ts index 8ba9632e0..9943652b7 100644 --- a/packages/core/src/commands/command.ts +++ b/packages/core/src/commands/command.ts @@ -1,14 +1,14 @@ import { Command, Commands } from '../types' -/** - * Define a command inline. - */ -export const command: Commands['command'] = fn => props => { - return fn(props) -} - declare module '@tiptap/core' { interface Commands { + /** + * Define a command inline. + */ command: (fn: (props: Parameters[0]) => boolean) => Command, } } + +export const command: Commands['command'] = fn => props => { + return fn(props) +} diff --git a/packages/core/src/commands/createParagraphNear.ts b/packages/core/src/commands/createParagraphNear.ts index 96947f16e..3588d2281 100644 --- a/packages/core/src/commands/createParagraphNear.ts +++ b/packages/core/src/commands/createParagraphNear.ts @@ -1,15 +1,15 @@ import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Create a paragraph nearby. - */ -export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => { - return originalCreateParagraphNear(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Create a paragraph nearby. + */ createParagraphNear: () => Command, } } + +export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => { + return originalCreateParagraphNear(state, dispatch) +} diff --git a/packages/core/src/commands/deleteRange.ts b/packages/core/src/commands/deleteRange.ts index ac6389875..437cb985c 100644 --- a/packages/core/src/commands/deleteRange.ts +++ b/packages/core/src/commands/deleteRange.ts @@ -1,8 +1,14 @@ import { Command, Commands, Range } from '../types' -/** - * Delete a given range. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Delete a given range. + */ + deleteRange: (range: Range) => Command, + } +} + export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => { const { from, to } = range @@ -12,9 +18,3 @@ export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) return true } - -declare module '@tiptap/core' { - interface Commands { - deleteRange: (range: Range) => Command, - } -} diff --git a/packages/core/src/commands/deleteSelection.ts b/packages/core/src/commands/deleteSelection.ts index 6459256a0..65f361caf 100644 --- a/packages/core/src/commands/deleteSelection.ts +++ b/packages/core/src/commands/deleteSelection.ts @@ -1,15 +1,15 @@ import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Delete the selection, if there is one. - */ -export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => { - return originalDeleteSelection(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Delete the selection, if there is one. + */ deleteSelection: () => Command, } } + +export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => { + return originalDeleteSelection(state, dispatch) +} diff --git a/packages/core/src/commands/enter.ts b/packages/core/src/commands/enter.ts index 660c13124..d7b932602 100644 --- a/packages/core/src/commands/enter.ts +++ b/packages/core/src/commands/enter.ts @@ -1,14 +1,14 @@ import { Command, Commands } from '../types' -/** - * Trigger enter. - */ -export const enter: Commands['enter'] = () => ({ commands }) => { - return commands.keyboardShortcut('Enter') -} - declare module '@tiptap/core' { interface Commands { + /** + * Trigger enter. + */ enter: () => Command, } } + +export const enter: Commands['enter'] = () => ({ commands }) => { + return commands.keyboardShortcut('Enter') +} diff --git a/packages/core/src/commands/exitCode.ts b/packages/core/src/commands/exitCode.ts index 3e554a90d..48956654b 100644 --- a/packages/core/src/commands/exitCode.ts +++ b/packages/core/src/commands/exitCode.ts @@ -1,15 +1,15 @@ import { exitCode as originalExitCode } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Exit from a code block. - */ -export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => { - return originalExitCode(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Exit from a code block. + */ exitCode: () => Command, } } + +export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => { + return originalExitCode(state, dispatch) +} diff --git a/packages/core/src/commands/extendMarkRange.ts b/packages/core/src/commands/extendMarkRange.ts index a005be8e3..a05fe423c 100644 --- a/packages/core/src/commands/extendMarkRange.ts +++ b/packages/core/src/commands/extendMarkRange.ts @@ -4,9 +4,15 @@ import { Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' -/** - * Extends the text selection to the current mark. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Extends the text selection to the current mark. + */ + extendMarkRange: (typeOrName: string | MarkType) => Command, + } +} + export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => { const type = getMarkType(typeOrName, state.schema) const { doc, selection } = tr @@ -24,9 +30,3 @@ export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, return true } - -declare module '@tiptap/core' { - interface Commands { - extendMarkRange: (typeOrName: string | MarkType) => Command, - } -} diff --git a/packages/core/src/commands/first.ts b/packages/core/src/commands/first.ts index b0b23537c..b034cc1d9 100644 --- a/packages/core/src/commands/first.ts +++ b/packages/core/src/commands/first.ts @@ -1,8 +1,14 @@ import { Command, Commands } from '../types' -/** - * Runs one command after the other and stops at the first which returns true. - */ +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, + } +} + export const first: Commands['first'] = commands => props => { const items = typeof commands === 'function' ? commands(props) @@ -16,9 +22,3 @@ export const first: Commands['first'] = commands => props => { return false } - -declare module '@tiptap/core' { - interface Commands { - 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 9f987c2f7..84a26ab1d 100644 --- a/packages/core/src/commands/focus.ts +++ b/packages/core/src/commands/focus.ts @@ -30,9 +30,15 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) { } } -/** - * Focus the editor at the given position. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Focus the editor at the given position. + */ + focus: (position?: FocusPosition) => Command, + } +} + export const focus: Commands['focus'] = (position = null) => ({ editor, view, @@ -62,9 +68,3 @@ export const focus: Commands['focus'] = (position = null) => ({ return true } - -declare module '@tiptap/core' { - interface Commands { - focus: (position?: FocusPosition) => Command, - } -} diff --git a/packages/core/src/commands/insertHTML.ts b/packages/core/src/commands/insertHTML.ts index 7d63ae7e8..b78690ca4 100644 --- a/packages/core/src/commands/insertHTML.ts +++ b/packages/core/src/commands/insertHTML.ts @@ -17,9 +17,15 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number tr.setSelection(Selection.near(tr.doc.resolve(end as unknown as number), bias)) } -/** - * Insert a string of HTML at the current position. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Insert a string of HTML at the current position. + */ + insertHTML: (value: string) => Command, + } +} + export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => { const { selection } = tr const element = elementFromString(value) @@ -32,9 +38,3 @@ export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatc return true } - -declare module '@tiptap/core' { - interface Commands { - insertHTML: (value: string) => Command, - } -} diff --git a/packages/core/src/commands/insertText.ts b/packages/core/src/commands/insertText.ts index 61fa1f926..decf70ca6 100644 --- a/packages/core/src/commands/insertText.ts +++ b/packages/core/src/commands/insertText.ts @@ -1,8 +1,14 @@ import { Command, Commands } from '../types' -/** - * Insert a string of text at the current position. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Insert a string of text at the current position. + */ + insertText: (value: string) => Command, + } +} + export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => { if (dispatch) { tr.insertText(value) @@ -10,9 +16,3 @@ export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => return true } - -declare module '@tiptap/core' { - interface Commands { - insertText: (value: string) => Command, - } -} diff --git a/packages/core/src/commands/joinBackward.ts b/packages/core/src/commands/joinBackward.ts index ef8016800..799b8014b 100644 --- a/packages/core/src/commands/joinBackward.ts +++ b/packages/core/src/commands/joinBackward.ts @@ -1,15 +1,15 @@ import { joinBackward as originalJoinBackward } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Join two nodes backward. - */ -export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => { - return originalJoinBackward(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Join two nodes backward. + */ joinBackward: () => Command, } } + +export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => { + return originalJoinBackward(state, dispatch) +} diff --git a/packages/core/src/commands/joinForward.ts b/packages/core/src/commands/joinForward.ts index 979954953..f855d0d65 100644 --- a/packages/core/src/commands/joinForward.ts +++ b/packages/core/src/commands/joinForward.ts @@ -1,15 +1,15 @@ import { joinForward as originalJoinForward } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Join two nodes forward. - */ -export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => { - return originalJoinForward(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Join two nodes forward. + */ joinForward: () => Command, } } + +export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => { + return originalJoinForward(state, dispatch) +} diff --git a/packages/core/src/commands/keyboardShortcut.ts b/packages/core/src/commands/keyboardShortcut.ts index 7921df134..0491f8065 100644 --- a/packages/core/src/commands/keyboardShortcut.ts +++ b/packages/core/src/commands/keyboardShortcut.ts @@ -56,9 +56,15 @@ function normalizeKeyName(name: string) { return result } -/** - * Trigger a keyboard shortcut. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Trigger a keyboard shortcut. + */ + keyboardShortcut: (name: string) => Command, + } +} + export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({ editor, view, @@ -93,9 +99,3 @@ export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({ return true } - -declare module '@tiptap/core' { - interface Commands { - keyboardShortcut: (name: string) => Command, - } -} diff --git a/packages/core/src/commands/lift.ts b/packages/core/src/commands/lift.ts index 16498ce40..e2a576731 100644 --- a/packages/core/src/commands/lift.ts +++ b/packages/core/src/commands/lift.ts @@ -4,9 +4,15 @@ import { Command, Commands, AnyObject } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' -/** - * Removes an existing wrap. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Removes an existing wrap. + */ + lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,9 +23,3 @@ export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, return originalLift(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/liftEmptyBlock.ts b/packages/core/src/commands/liftEmptyBlock.ts index 2986eebd0..f65d43044 100644 --- a/packages/core/src/commands/liftEmptyBlock.ts +++ b/packages/core/src/commands/liftEmptyBlock.ts @@ -1,15 +1,15 @@ import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Lift block if empty. - */ -export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => { - return originalLiftEmptyBlock(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Lift block if empty. + */ liftEmptyBlock: () => Command, } } + +export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => { + return originalLiftEmptyBlock(state, dispatch) +} diff --git a/packages/core/src/commands/liftListItem.ts b/packages/core/src/commands/liftListItem.ts index 09d68da78..d6fbf63c3 100644 --- a/packages/core/src/commands/liftListItem.ts +++ b/packages/core/src/commands/liftListItem.ts @@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model' import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' -/** - * Lift the list item into a wrapping list. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Lift the list item into a wrapping list. + */ + liftListItem: (typeOrName: string | NodeType) => Command, + } +} + export const liftListItem: Commands['liftListItem'] = typeOrName => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) return originalLiftListItem(type)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - liftListItem: (typeOrName: string | NodeType) => Command, - } -} diff --git a/packages/core/src/commands/newlineInCode.ts b/packages/core/src/commands/newlineInCode.ts index 1cf5c40a3..e23fe609a 100644 --- a/packages/core/src/commands/newlineInCode.ts +++ b/packages/core/src/commands/newlineInCode.ts @@ -1,15 +1,15 @@ import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Add a newline character in code. - */ -export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => { - return originalNewlineInCode(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Add a newline character in code. + */ newlineInCode: () => Command, } } + +export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => { + return originalNewlineInCode(state, dispatch) +} diff --git a/packages/core/src/commands/replace.ts b/packages/core/src/commands/replace.ts index 24ae5910f..ba63b2f1c 100644 --- a/packages/core/src/commands/replace.ts +++ b/packages/core/src/commands/replace.ts @@ -1,18 +1,18 @@ import { NodeType } from 'prosemirror-model' import { Command, Commands, AnyObject } from '../types' -/** - * Replaces text with a node. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Replaces text with a node. + */ + replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const replace: Commands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => { const { from, to } = state.selection const range = { from, to } return commands.replaceRange(range, typeOrName, attributes) } - -declare module '@tiptap/core' { - interface Commands { - replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/replaceRange.ts b/packages/core/src/commands/replaceRange.ts index 111b78135..c067c3d8e 100644 --- a/packages/core/src/commands/replaceRange.ts +++ b/packages/core/src/commands/replaceRange.ts @@ -7,9 +7,15 @@ import { AnyObject, } from '../types' -/** - * Replaces text with a node within a range. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Replaces text with a node within a range. + */ + replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { from, to } = range @@ -26,9 +32,3 @@ export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attrib return true } - -declare module '@tiptap/core' { - interface Commands { - 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 e179da0e0..5536cb551 100644 --- a/packages/core/src/commands/resetNodeAttributes.ts +++ b/packages/core/src/commands/resetNodeAttributes.ts @@ -3,9 +3,15 @@ import getNodeType from '../helpers/getNodeType' import deleteProps from '../utilities/deleteProps' import { Command, Commands } from '../types' -/** - * Resets node attributes to the default value. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Resets node attributes to the default value. + */ + resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command, + } +} + export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { selection } = tr @@ -19,9 +25,3 @@ export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, return true } - -declare module '@tiptap/core' { - interface Commands { - 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 b0cf8dac9..90fba1fb3 100644 --- a/packages/core/src/commands/scrollIntoView.ts +++ b/packages/core/src/commands/scrollIntoView.ts @@ -1,8 +1,14 @@ import { Command, Commands } from '../types' -/** - * Scroll the selection into view. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Scroll the selection into view. + */ + scrollIntoView: () => Command, + } +} + export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => { if (dispatch) { tr.scrollIntoView() @@ -10,9 +16,3 @@ export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch return true } - -declare module '@tiptap/core' { - interface Commands { - scrollIntoView: () => Command, - } -} diff --git a/packages/core/src/commands/selectAll.ts b/packages/core/src/commands/selectAll.ts index 4c1296144..3d5a6a19c 100644 --- a/packages/core/src/commands/selectAll.ts +++ b/packages/core/src/commands/selectAll.ts @@ -1,15 +1,15 @@ import { selectAll as originalSelectAll } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Select the whole document. - */ -export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => { - return originalSelectAll(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Select the whole document. + */ selectAll: () => Command, } } + +export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => { + return originalSelectAll(state, dispatch) +} diff --git a/packages/core/src/commands/selectNodeBackward.ts b/packages/core/src/commands/selectNodeBackward.ts index 174b50fe2..d31c70ac9 100644 --- a/packages/core/src/commands/selectNodeBackward.ts +++ b/packages/core/src/commands/selectNodeBackward.ts @@ -1,15 +1,15 @@ import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Select a node backward. - */ -export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => { - return originalSelectNodeBackward(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Select a node backward. + */ selectNodeBackward: () => Command, } } + +export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => { + return originalSelectNodeBackward(state, dispatch) +} diff --git a/packages/core/src/commands/selectNodeForward.ts b/packages/core/src/commands/selectNodeForward.ts index 4a2feecec..de44cf6a8 100644 --- a/packages/core/src/commands/selectNodeForward.ts +++ b/packages/core/src/commands/selectNodeForward.ts @@ -1,15 +1,15 @@ import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Select a node forward. - */ -export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => { - return originalSelectNodeForward(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Select a node forward. + */ selectNodeForward: () => Command, } } + +export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => { + return originalSelectNodeForward(state, dispatch) +} diff --git a/packages/core/src/commands/selectParentNode.ts b/packages/core/src/commands/selectParentNode.ts index 464ec68ac..503b3f19f 100644 --- a/packages/core/src/commands/selectParentNode.ts +++ b/packages/core/src/commands/selectParentNode.ts @@ -1,15 +1,15 @@ import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands' import { Command, Commands } from '../types' -/** - * Select the parent node. - */ -export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => { - return originalSelectParentNode(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Select the parent node. + */ selectParentNode: () => Command, } } + +export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => { + return originalSelectParentNode(state, dispatch) +} diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index 0f57904c1..ecf7e8166 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -1,9 +1,15 @@ import { TextSelection } from 'prosemirror-state' import { AnyObject, Command, Commands } from '../types' -/** - * Replace the whole document with new content. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Replace the whole document with new content. + */ + setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command, + } +} + export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => { const { createDocument } = editor const { doc } = tr @@ -18,9 +24,3 @@ export const setContent: Commands['setContent'] = (content, emitUpdate = false, return true } - -declare module '@tiptap/core' { - interface Commands { - 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 e1a74c5d0..27090137c 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkAttributes from '../helpers/getMarkAttributes' -/** - * Add a mark with new attributes. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Add a mark with new attributes. + */ + setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + } +} + export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const { selection } = tr const { from, to, empty } = selection @@ -26,9 +32,3 @@ export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ return true } - -declare module '@tiptap/core' { - interface Commands { - setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/setNode.ts b/packages/core/src/commands/setNode.ts index 8531fa5c4..91fedbc49 100644 --- a/packages/core/src/commands/setNode.ts +++ b/packages/core/src/commands/setNode.ts @@ -3,17 +3,17 @@ import { setBlockType } from 'prosemirror-commands' import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' -/** - * Replace a given range with a node. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Replace a given range with a node. + */ + setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) return setBlockType(type, attributes)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/sinkListItem.ts b/packages/core/src/commands/sinkListItem.ts index 01ed0c2f9..e99c59f69 100644 --- a/packages/core/src/commands/sinkListItem.ts +++ b/packages/core/src/commands/sinkListItem.ts @@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model' import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' -/** - * Sink the list item down into an inner list. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Sink the list item down into an inner list. + */ + sinkListItem: (typeOrName: string | NodeType) => Command, + } +} + export const sinkListItem: Commands['sinkListItem'] = typeOrName => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) return originalSinkListItem(type)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - sinkListItem: (typeOrName: string | NodeType) => Command, - } -} diff --git a/packages/core/src/commands/splitBlock.ts b/packages/core/src/commands/splitBlock.ts index d79084354..377543241 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -15,11 +15,7 @@ function defaultBlockAt(match: ContentMatch) { return null } -export interface SplitBlockOptions { - keepMarks: boolean, -} - -function keepMarks(state: EditorState) { +function ensureMarks(state: EditorState) { const marks = state.storedMarks || (state.selection.$to.parentOffset && state.selection.$from.marks()) @@ -28,19 +24,21 @@ function keepMarks(state: EditorState) { } } -/** - * Forks a new node from an existing node. - */ -export const splitBlock: Commands['splitBlock'] = (options = {}) => ({ +declare module '@tiptap/core' { + interface Commands { + /** + * Forks a new node from an existing node. + */ + splitBlock: (options?: { keepMarks?: boolean }) => Command, + } +} + +export const splitBlock: Commands['splitBlock'] = ({ keepMarks = true } = {}) => ({ tr, state, dispatch, editor, }) => { - const defaultOptions: SplitBlockOptions = { - keepMarks: true, - } - const config = { ...defaultOptions, ...options } const { selection, doc } = tr const { $from, $to } = selection const extensionAttributes = editor.extensionManager.attributes @@ -56,8 +54,8 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({ } if (dispatch) { - if (config.keepMarks) { - keepMarks(state) + if (keepMarks) { + ensureMarks(state) } tr.split($from.pos).scrollIntoView() @@ -117,8 +115,8 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({ } } - if (config.keepMarks) { - keepMarks(state) + if (keepMarks) { + ensureMarks(state) } tr.scrollIntoView() @@ -126,9 +124,3 @@ export const splitBlock: Commands['splitBlock'] = (options = {}) => ({ return true } - -declare module '@tiptap/core' { - interface Commands { - splitBlock: (options?: Partial) => Command, - } -} diff --git a/packages/core/src/commands/splitListItem.ts b/packages/core/src/commands/splitListItem.ts index 28c85b986..53f0ffac8 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -10,9 +10,15 @@ import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' import getSplittedAttributes from '../helpers/getSplittedAttributes' -/** - * Splits one list item into two list items. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Splits one list item into two list items. + */ + splitListItem: (typeOrName: string | NodeType) => Command, + } +} + export const splitListItem: Commands['splitListItem'] = typeOrName => ({ tr, state, dispatch, editor, }) => { @@ -110,9 +116,3 @@ export const splitListItem: Commands['splitListItem'] = typeOrName => ({ return true } - -declare module '@tiptap/core' { - interface Commands { - splitListItem: (typeOrName: string | NodeType) => Command, - } -} diff --git a/packages/core/src/commands/toggleList.ts b/packages/core/src/commands/toggleList.ts index 29bc47311..93ced5192 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -4,9 +4,15 @@ import getNodeType from '../helpers/getNodeType' import findParentNode from '../helpers/findParentNode' import isList from '../helpers/isList' -/** - * Toggle between different list types. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Toggle between different list types. + */ + toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command, + } +} + export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({ editor, tr, state, dispatch, chain, commands, can, }) => { @@ -53,9 +59,3 @@ export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrNam return commands.wrapInList(listType) } - -declare module '@tiptap/core' { - interface Commands { - 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 d342ae331..2216184ee 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import isMarkActive from '../helpers/isMarkActive' -/** - * Toggle a mark on and off. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Toggle a mark on and off. + */ + toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, + } +} + export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => { const type = getMarkType(typeOrName, state.schema) const isActive = isMarkActive(state, type, attributes) @@ -16,9 +22,3 @@ export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) return commands.setMark(type, attributes) } - -declare module '@tiptap/core' { - interface Commands { - toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/toggleNode.ts b/packages/core/src/commands/toggleNode.ts index 13d168a1e..65eb7f3a2 100644 --- a/packages/core/src/commands/toggleNode.ts +++ b/packages/core/src/commands/toggleNode.ts @@ -3,9 +3,15 @@ import { AnyObject, Command, Commands } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' -/** - * Toggle a node with another node. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Toggle a node with another node. + */ + toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => { const type = getNodeType(typeOrName, state.schema) const toggleType = getNodeType(toggleTypeOrName, state.schema) @@ -17,9 +23,3 @@ export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, return commands.setNode(type, attributes) } - -declare module '@tiptap/core' { - interface Commands { - 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 f48dcdc2d..9ffd02a2e 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -4,9 +4,15 @@ import { AnyObject, Command, Commands } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' -/** - * Wraps nodes in another node, or removes an existing wrap. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Wraps nodes in another node, or removes an existing wrap. + */ + toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,9 +23,3 @@ export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) return wrapIn(type, attributes)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/undoInputRule.ts b/packages/core/src/commands/undoInputRule.ts index 31678716d..548ca0297 100644 --- a/packages/core/src/commands/undoInputRule.ts +++ b/packages/core/src/commands/undoInputRule.ts @@ -1,15 +1,15 @@ import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules' import { Command, Commands } from '../types' -/** - * Undo an input rule. - */ -export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => { - return originalUndoInputRule(state, dispatch) -} - declare module '@tiptap/core' { interface Commands { + /** + * Undo an input rule. + */ undoInputRule: () => Command, } } + +export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => { + return originalUndoInputRule(state, dispatch) +} diff --git a/packages/core/src/commands/unsetAllMarks.ts b/packages/core/src/commands/unsetAllMarks.ts index b353d0665..cdec2648e 100644 --- a/packages/core/src/commands/unsetAllMarks.ts +++ b/packages/core/src/commands/unsetAllMarks.ts @@ -1,8 +1,14 @@ import { Command, Commands } from '../types' -/** - * Remove all marks in the current selection. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Remove all marks in the current selection. + */ + unsetAllMarks: () => Command, + } +} + export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => { const { selection } = tr const { from, to, empty } = selection @@ -21,9 +27,3 @@ export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, disp return true } - -declare module '@tiptap/core' { - interface Commands { - unsetAllMarks: () => Command, - } -} diff --git a/packages/core/src/commands/unsetMark.ts b/packages/core/src/commands/unsetMark.ts index ef5bb339c..da56827d9 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -3,9 +3,15 @@ import { Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' -/** - * Remove all marks in the current selection. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Remove all marks in the current selection. + */ + unsetMark: (typeOrName: string | MarkType) => Command, + } +} + export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => { const { selection } = tr const type = getMarkType(typeOrName, state.schema) @@ -28,9 +34,3 @@ export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, disp return true } - -declare module '@tiptap/core' { - interface Commands { - unsetMark: (typeOrName: string | MarkType) => Command, - } -} diff --git a/packages/core/src/commands/updateNodeAttributes.ts b/packages/core/src/commands/updateNodeAttributes.ts index bff2f4ffd..000610b41 100644 --- a/packages/core/src/commands/updateNodeAttributes.ts +++ b/packages/core/src/commands/updateNodeAttributes.ts @@ -2,9 +2,15 @@ import { NodeType } from 'prosemirror-model' import getNodeType from '../helpers/getNodeType' import { AnyObject, Command, Commands } from '../types' -/** - * Update attributes of a node. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Update attributes of a node. + */ + updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command, + } +} + export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { selection } = tr @@ -21,9 +27,3 @@ export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrNam return true } - -declare module '@tiptap/core' { - interface Commands { - updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/wrapIn.ts b/packages/core/src/commands/wrapIn.ts index 5e278a844..b0ea8a82b 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -4,9 +4,15 @@ import { AnyObject, Command, Commands } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' -/** - * Wraps nodes in another node. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Wraps nodes in another node. + */ + wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,9 +23,3 @@ export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ st return originalWrapIn(type, attributes)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/core/src/commands/wrapInList.ts b/packages/core/src/commands/wrapInList.ts index 94ab955a3..e0d1894b4 100644 --- a/packages/core/src/commands/wrapInList.ts +++ b/packages/core/src/commands/wrapInList.ts @@ -3,17 +3,17 @@ import { NodeType } from 'prosemirror-model' import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' -/** - * Wrap a node in a list. - */ +declare module '@tiptap/core' { + interface Commands { + /** + * Wrap a node in a list. + */ + wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } +} + export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) return originalWrapInList(type, attributes)(state, dispatch) } - -declare module '@tiptap/core' { - interface Commands { - wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, - } -} diff --git a/packages/extension-blockquote/src/blockquote.ts b/packages/extension-blockquote/src/blockquote.ts index 686915345..16799e3b7 100644 --- a/packages/extension-blockquote/src/blockquote.ts +++ b/packages/extension-blockquote/src/blockquote.ts @@ -9,8 +9,17 @@ 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, } } @@ -43,21 +52,12 @@ export const Blockquote = Node.create({ addCommands() { return { - /** - * Set a blockquote node - */ setBlockquote: () => ({ commands }) => { return commands.wrapIn('blockquote') }, - /** - * Toggle a blockquote node - */ toggleBlockquote: () => ({ commands }) => { return commands.toggleWrap('blockquote') }, - /** - * Unset a blockquote node - */ unsetBlockquote: () => ({ commands }) => { return commands.lift('blockquote') }, diff --git a/packages/extension-bold/src/bold.ts b/packages/extension-bold/src/bold.ts index 76f4e8ef4..7e97d84c7 100644 --- a/packages/extension-bold/src/bold.ts +++ b/packages/extension-bold/src/bold.ts @@ -14,8 +14,17 @@ 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, } } @@ -54,21 +63,12 @@ export const Bold = Mark.create({ addCommands() { return { - /** - * Set a bold mark - */ setBold: () => ({ commands }) => { return commands.setMark('bold') }, - /** - * Toggle a bold mark - */ toggleBold: () => ({ commands }) => { return commands.toggleMark('bold') }, - /** - * Unset a bold mark - */ unsetBold: () => ({ commands }) => { return commands.unsetMark('bold') }, diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index c1499ee4a..4afb834a3 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -9,6 +9,9 @@ export interface BulletListOptions { declare module '@tiptap/core' { interface Commands { + /** + * Toggle a bullet list + */ toggleBulletList: () => Command, } } @@ -38,9 +41,6 @@ export const BulletList = Node.create({ addCommands() { return { - /** - * Toggle a bullet list - */ toggleBulletList: () => ({ commands }) => { return commands.toggleList('bulletList', 'listItem') }, diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index e7bf3a3b6..78bb02903 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -10,7 +10,13 @@ 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, } } @@ -81,15 +87,9 @@ export const CodeBlock = Node.create({ addCommands() { return { - /** - * Set a code block - */ setCodeBlock: attributes => ({ commands }) => { return commands.setNode('codeBlock', attributes) }, - /** - * Toggle a code block - */ toggleCodeBlock: attributes => ({ commands }) => { return commands.toggleNode('codeBlock', 'paragraph', attributes) }, diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index 64daf4baa..5020b00b3 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -14,8 +14,17 @@ 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, } } @@ -44,21 +53,12 @@ export const Code = Mark.create({ addCommands() { return { - /** - * Set a code mark - */ setCode: () => ({ commands }) => { return commands.setMark('code') }, - /** - * Toggle inline code - */ toggleCode: () => ({ commands }) => { return commands.toggleMark('code') }, - /** - * Unset a code mark - */ unsetCode: () => ({ commands }) => { return commands.unsetMark('code') }, diff --git a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts index c4d98d47b..2e42169bc 100644 --- a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts +++ b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts @@ -10,6 +10,9 @@ export interface CollaborationCursorOptions { declare module '@tiptap/core' { interface Commands { + /** + * Update details of the current user + */ user: (attributes: AnyObject) => Command, } } @@ -50,9 +53,6 @@ export const CollaborationCursor = Extension.create({ addCommands() { return { - /** - * Update details of the current user - */ user: attributes => () => { this.options.user = attributes diff --git a/packages/extension-collaboration/src/collaboration.ts b/packages/extension-collaboration/src/collaboration.ts index bbe729541..de6373756 100644 --- a/packages/extension-collaboration/src/collaboration.ts +++ b/packages/extension-collaboration/src/collaboration.ts @@ -8,7 +8,13 @@ import { declare module '@tiptap/core' { interface Commands { + /** + * Undo recent changes + */ undo: () => Command, + /** + * Reapply reverted changes + */ redo: () => Command, } } @@ -39,17 +45,11 @@ export const Collaboration = Extension.create({ addCommands() { return { - /** - * Undo recent changes - */ undo: () => ({ tr, state }) => { tr.setMeta('preventDispatch', true) return undo(state) }, - /** - * Reapply reverted changes - */ redo: () => ({ tr, state }) => { tr.setMeta('preventDispatch', true) diff --git a/packages/extension-font-family/src/font-family.ts b/packages/extension-font-family/src/font-family.ts index 2378a6e2e..44aae4dd5 100644 --- a/packages/extension-font-family/src/font-family.ts +++ b/packages/extension-font-family/src/font-family.ts @@ -7,7 +7,13 @@ type FontFamilyOptions = { declare module '@tiptap/core' { interface Commands { + /** + * Set the font family + */ setFontFamily: (fontFamily: string) => Command, + /** + * Unset the font family + */ unsetFontFamily: () => Command, } } @@ -46,17 +52,11 @@ export const FontFamily = Extension.create({ addCommands() { return { - /** - * Set the font family - */ setFontFamily: fontFamily => ({ chain }) => { return chain() .setMark('textStyle', { fontFamily }) .run() }, - /** - * Unset the font family - */ unsetFontFamily: () => ({ chain }) => { return chain() .setMark('textStyle', { fontFamily: null }) diff --git a/packages/extension-hard-break/src/hard-break.ts b/packages/extension-hard-break/src/hard-break.ts index 4770280aa..bc415f3e3 100644 --- a/packages/extension-hard-break/src/hard-break.ts +++ b/packages/extension-hard-break/src/hard-break.ts @@ -9,6 +9,9 @@ export interface HardBreakOptions { declare module '@tiptap/core' { interface Commands { + /** + * Add a hard break + */ setHardBreak: () => Command, } } @@ -39,9 +42,6 @@ export const HardBreak = Node.create({ addCommands() { return { - /** - * Add a hard break - */ setHardBreak: () => ({ commands, state, dispatch }) => { return commands.first([ () => exitCode(state, dispatch), diff --git a/packages/extension-heading/src/heading.ts b/packages/extension-heading/src/heading.ts index 694593c89..a4291d206 100644 --- a/packages/extension-heading/src/heading.ts +++ b/packages/extension-heading/src/heading.ts @@ -12,7 +12,13 @@ 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, } } @@ -59,9 +65,6 @@ export const Heading = Node.create({ addCommands() { return { - /** - * Set a heading node - */ setHeading: attributes => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false @@ -69,9 +72,6 @@ export const Heading = Node.create({ return commands.setNode('heading', attributes) }, - /** - * Toggle a heading node - */ toggleHeading: attributes => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false diff --git a/packages/extension-highlight/src/highlight.ts b/packages/extension-highlight/src/highlight.ts index fed06ceee..2bc63d0f5 100644 --- a/packages/extension-highlight/src/highlight.ts +++ b/packages/extension-highlight/src/highlight.ts @@ -15,8 +15,17 @@ 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, } } @@ -73,21 +82,12 @@ export const Highlight = Mark.create({ addCommands() { return { - /** - * Set a highlight mark - */ setHighlight: attributes => ({ commands }) => { return commands.setMark('highlight', attributes) }, - /** - * Toggle a highlight mark - */ toggleHighlight: attributes => ({ commands }) => { return commands.toggleMark('highlight', attributes) }, - /** - * Unset a highlight mark - */ unsetHighlight: () => ({ commands }) => { return commands.unsetMark('highlight') }, diff --git a/packages/extension-history/src/history.ts b/packages/extension-history/src/history.ts index a6b6c898f..92eab2824 100644 --- a/packages/extension-history/src/history.ts +++ b/packages/extension-history/src/history.ts @@ -8,7 +8,13 @@ export interface HistoryOptions { declare module '@tiptap/core' { interface Commands { + /** + * Undo recent changes + */ undo: () => Command, + /** + * Reapply reverted changes + */ redo: () => Command, } } @@ -23,15 +29,9 @@ export const History = Extension.create({ addCommands() { return { - /** - * Undo recent changes - */ undo: () => ({ state, dispatch }) => { return undo(state, dispatch) }, - /** - * Reapply reverted changes - */ redo: () => ({ state, dispatch }) => { return redo(state, dispatch) }, diff --git a/packages/extension-horizontal-rule/src/horizontal-rule.ts b/packages/extension-horizontal-rule/src/horizontal-rule.ts index a2ee82c55..d86371220 100644 --- a/packages/extension-horizontal-rule/src/horizontal-rule.ts +++ b/packages/extension-horizontal-rule/src/horizontal-rule.ts @@ -13,6 +13,9 @@ export interface HorizontalRuleOptions { declare module '@tiptap/core' { interface Commands { + /** + * Add a horizontal rule + */ setHorizontalRule: () => Command, } } @@ -38,9 +41,6 @@ export const HorizontalRule = Node.create({ addCommands() { return { - /** - * Add a horizontal rule - */ setHorizontalRule: () => ({ tr, dispatch }) => { if (dispatch) { tr.replaceSelectionWith(this.type.create()) diff --git a/packages/extension-image/src/image.ts b/packages/extension-image/src/image.ts index e2617ffe3..053926ec6 100644 --- a/packages/extension-image/src/image.ts +++ b/packages/extension-image/src/image.ts @@ -14,6 +14,9 @@ export interface ImageOptions { declare module '@tiptap/core' { interface Commands { + /** + * Add an image + */ setImage: (options: { src: string, alt?: string, title?: string }) => Command, } } @@ -66,9 +69,6 @@ export const Image = Node.create({ addCommands() { return { - /** - * Add an image - */ setImage: options => ({ tr, dispatch }) => { const { selection } = tr const node = this.type.create(options) diff --git a/packages/extension-italic/src/italic.ts b/packages/extension-italic/src/italic.ts index d6bf5f0ac..92d28d313 100644 --- a/packages/extension-italic/src/italic.ts +++ b/packages/extension-italic/src/italic.ts @@ -14,8 +14,17 @@ 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, } } @@ -53,21 +62,12 @@ export const Italic = Mark.create({ addCommands() { return { - /** - * Set an italic mark - */ setItalic: () => ({ commands }) => { return commands.setMark('italic') }, - /** - * Toggle an italic mark - */ toggleItalic: () => ({ commands }) => { return commands.toggleMark('italic') }, - /** - * Unset an italic mark - */ unsetItalic: () => ({ commands }) => { return commands.unsetMark('italic') }, diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index 5821ae3b6..1890bb657 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -15,8 +15,17 @@ 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, } } @@ -60,21 +69,12 @@ export const Link = Mark.create({ addCommands() { return { - /** - * Set a link mark - */ setLink: attributes => ({ commands }) => { return commands.setMark('link', attributes) }, - /** - * Toggle a link mark - */ toggleLink: attributes => ({ commands }) => { return commands.toggleMark('link', attributes) }, - /** - * Unset a link mark - */ unsetLink: () => ({ commands }) => { return commands.unsetMark('link') }, diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 82e02976d..6ff503ac1 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -9,6 +9,9 @@ export interface OrderedListOptions { declare module '@tiptap/core' { interface Commands { + /** + * Toggle an ordered list + */ toggleOrderedList: () => Command, } } @@ -57,9 +60,6 @@ export const OrderedList = Node.create({ addCommands() { return { - /** - * Toggle an ordered list - */ toggleOrderedList: () => ({ commands }) => { return commands.toggleList('orderedList', 'listItem') }, diff --git a/packages/extension-paragraph/src/paragraph.ts b/packages/extension-paragraph/src/paragraph.ts index af6466c22..da96242bd 100644 --- a/packages/extension-paragraph/src/paragraph.ts +++ b/packages/extension-paragraph/src/paragraph.ts @@ -8,6 +8,9 @@ export interface ParagraphOptions { declare module '@tiptap/core' { interface Commands { + /** + * Toggle a paragraph + */ setParagraph: () => Command, } } @@ -35,9 +38,6 @@ export const Paragraph = Node.create({ addCommands() { return { - /** - * Toggle a paragraph - */ setParagraph: () => ({ commands }) => { return commands.toggleNode('paragraph', 'paragraph') }, diff --git a/packages/extension-strike/src/strike.ts b/packages/extension-strike/src/strike.ts index 9d7c0f4b1..ed3c5f0b8 100644 --- a/packages/extension-strike/src/strike.ts +++ b/packages/extension-strike/src/strike.ts @@ -14,8 +14,17 @@ 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, } } @@ -53,21 +62,12 @@ export const Strike = Mark.create({ addCommands() { return { - /** - * Set a strike mark - */ setStrike: () => ({ commands }) => { return commands.setMark('strike') }, - /** - * Toggle a strike mark - */ toggleStrike: () => ({ commands }) => { return commands.toggleMark('strike') }, - /** - * Unset a strike mark - */ unsetStrike: () => ({ commands }) => { return commands.unsetMark('strike') }, diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index f30774f85..de5c3d64b 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -8,6 +8,9 @@ export interface TaskListOptions { declare module '@tiptap/core' { interface Commands { + /** + * Toggle a task list + */ toggleTaskList: () => Command, } } @@ -38,9 +41,6 @@ export const TaskList = Node.create({ addCommands() { return { - /** - * Toggle a task list - */ toggleTaskList: () => ({ commands }) => { return commands.toggleList('taskList', 'taskItem') }, diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index 838b1f5ff..1c6379121 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -8,7 +8,13 @@ type TextAlignOptions = { declare module '@tiptap/core' { interface Commands { + /** + * Set the text align attribute + */ setTextAlign: (alignment: string) => Command, + /** + * Unset the text align attribute + */ unsetTextAlign: () => Command, } } @@ -43,9 +49,6 @@ export const TextAlign = Extension.create({ addCommands() { return { - /** - * Set the text align attribute - */ setTextAlign: (alignment: string) => ({ commands }) => { if (!this.options.alignments.includes(alignment)) { return false @@ -53,9 +56,6 @@ export const TextAlign = Extension.create({ return this.options.types.every(type => commands.updateNodeAttributes(type, { textAlign: alignment })) }, - /** - * Unset the text align attribute - */ unsetTextAlign: () => ({ commands }) => { return this.options.types.every(type => commands.resetNodeAttributes(type, 'textAlign')) }, diff --git a/packages/extension-text-style/src/text-style.ts b/packages/extension-text-style/src/text-style.ts index c8098dc35..41d896e12 100644 --- a/packages/extension-text-style/src/text-style.ts +++ b/packages/extension-text-style/src/text-style.ts @@ -13,6 +13,9 @@ export interface TextStyleOptions { declare module '@tiptap/core' { interface Commands { + /** + * Remove spans without inline style attributes. + */ removeEmptyTextStyle: () => Command, } } @@ -47,9 +50,6 @@ export const TextStyle = Mark.create({ addCommands() { return { - /** - * Remove spans without inline style attributes. - */ removeEmptyTextStyle: () => ({ state, commands }) => { const attributes = getMarkAttributes(state, this.type) const hasStyles = Object.entries(attributes).every(([, value]) => !!value) diff --git a/packages/extension-underline/src/underline.ts b/packages/extension-underline/src/underline.ts index 80bda97f0..80ac800db 100644 --- a/packages/extension-underline/src/underline.ts +++ b/packages/extension-underline/src/underline.ts @@ -8,8 +8,17 @@ 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, } } @@ -38,21 +47,12 @@ export const Underline = Mark.create({ addCommands() { return { - /** - * Set an underline mark - */ setUnderline: () => ({ commands }) => { return commands.setMark('underline') }, - /** - * Toggle an underline mark - */ toggleUnderline: () => ({ commands }) => { return commands.toggleMark('underline') }, - /** - * Unset an underline mark - */ unsetUnderline: () => ({ commands }) => { return commands.unsetMark('underline') },