From 290ff76e3730b30a6b5791a99ec74b027f8b726d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Wed, 10 Feb 2021 09:59:35 +0100 Subject: [PATCH] add Commands interface --- .eslintrc.js | 2 + .../demos/Examples/Savvy/ColorHighlighter.ts | 6 -- .../Annotation/extension/annotation.ts | 17 ++--- .../Experiments/Color/extension/Color.ts | 6 -- docs/src/demos/Experiments/Embeds/iframe.ts | 8 ++- .../Experiments/Linter/extension/Linter.ts | 6 -- packages/core/src/Editor.ts | 1 + packages/core/src/Extension.ts | 22 +++--- packages/core/src/ExtensionManager.ts | 1 + packages/core/src/Mark.ts | 22 +++--- packages/core/src/Node.ts | 27 ++++---- packages/core/src/commands/blur.ts | 10 ++- packages/core/src/commands/clearContent.ts | 10 ++- packages/core/src/commands/clearNodes.ts | 10 ++- packages/core/src/commands/command.ts | 10 ++- .../core/src/commands/createParagraphNear.ts | 10 ++- packages/core/src/commands/deleteRange.ts | 10 ++- packages/core/src/commands/deleteSelection.ts | 10 ++- packages/core/src/commands/enter.ts | 10 ++- packages/core/src/commands/exitCode.ts | 10 ++- packages/core/src/commands/extendMarkRange.ts | 10 ++- packages/core/src/commands/first.ts | 10 ++- packages/core/src/commands/focus.ts | 10 ++- packages/core/src/commands/insertHTML.ts | 10 ++- packages/core/src/commands/insertText.ts | 10 ++- packages/core/src/commands/joinBackward.ts | 10 ++- packages/core/src/commands/joinForward.ts | 10 ++- .../core/src/commands/keyboardShortcut.ts | 10 ++- packages/core/src/commands/lift.ts | 10 ++- packages/core/src/commands/liftEmptyBlock.ts | 10 ++- packages/core/src/commands/liftListItem.ts | 10 ++- packages/core/src/commands/newlineInCode.ts | 10 ++- packages/core/src/commands/replace.ts | 10 ++- packages/core/src/commands/replaceRange.ts | 15 ++++- .../core/src/commands/resetNodeAttributes.ts | 10 ++- packages/core/src/commands/scrollIntoView.ts | 10 ++- packages/core/src/commands/selectAll.ts | 10 ++- .../core/src/commands/selectNodeBackward.ts | 10 ++- .../core/src/commands/selectNodeForward.ts | 10 ++- .../core/src/commands/selectParentNode.ts | 10 ++- packages/core/src/commands/setContent.ts | 10 ++- packages/core/src/commands/setMark.ts | 10 ++- packages/core/src/commands/setNode.ts | 12 +++- packages/core/src/commands/sinkListItem.ts | 10 ++- packages/core/src/commands/splitBlock.ts | 10 ++- packages/core/src/commands/splitListItem.ts | 10 ++- packages/core/src/commands/toggleList.ts | 10 ++- packages/core/src/commands/toggleMark.ts | 10 ++- packages/core/src/commands/toggleNode.ts | 14 ++-- packages/core/src/commands/toggleWrap.ts | 10 ++- packages/core/src/commands/undoInputRule.ts | 10 ++- packages/core/src/commands/unsetAllMarks.ts | 10 ++- packages/core/src/commands/unsetMark.ts | 10 ++- .../core/src/commands/updateNodeAttributes.ts | 10 ++- packages/core/src/commands/wrapIn.ts | 10 ++- packages/core/src/commands/wrapInList.ts | 12 +++- .../src/extensions/clipboardTextSerializer.ts | 6 -- packages/core/src/extensions/commands.ts | 6 -- packages/core/src/extensions/editable.ts | 6 -- packages/core/src/extensions/focusEvents.ts | 6 -- packages/core/src/extensions/keymap.ts | 6 -- packages/core/src/index.ts | 1 + packages/core/src/types.ts | 34 +++++----- .../extension-blockquote/src/blockquote.ts | 21 +++--- packages/extension-bold/src/bold.ts | 20 +++--- .../extension-bullet-list/src/bullet-list.ts | 14 ++-- .../src/character-count.ts | 6 -- .../extension-code-block/src/code-block.ts | 17 ++--- packages/extension-code/src/code.ts | 20 +++--- .../src/collaboration-cursor.ts | 16 ++--- .../src/collaboration.ts | 17 ++--- packages/extension-document/src/document.ts | 6 -- .../extension-dropcursor/src/dropcursor.ts | 6 -- packages/extension-focus/src/focus.ts | 6 -- .../extension-font-family/src/font-family.ts | 17 ++--- packages/extension-gapcursor/src/gapcursor.ts | 6 -- .../extension-hard-break/src/hard-break.ts | 14 ++-- packages/extension-heading/src/heading.ts | 17 ++--- packages/extension-highlight/src/highlight.ts | 20 +++--- packages/extension-history/src/history.ts | 17 ++--- .../src/horizontal-rule.ts | 14 ++-- packages/extension-image/src/image.ts | 14 ++-- packages/extension-italic/src/italic.ts | 20 +++--- packages/extension-link/src/link.ts | 20 +++--- packages/extension-list-item/src/list-item.ts | 6 -- packages/extension-mention/src/mention.ts | 6 -- .../src/ordered-list.ts | 14 ++-- packages/extension-paragraph/src/paragraph.ts | 14 ++-- packages/extension-strike/src/strike.ts | 20 +++--- .../extension-table-cell/src/table-cell.ts | 6 -- .../src/table-header.ts | 6 -- packages/extension-table-row/src/table-row.ts | 6 -- packages/extension-table/src/table.ts | 67 ++++++++++++------- packages/extension-task-item/src/task-item.ts | 6 -- packages/extension-task-list/src/task-list.ts | 14 ++-- .../extension-text-align/src/text-align.ts | 17 ++--- .../extension-text-style/src/text-style.ts | 14 ++-- packages/extension-text/src/text.ts | 6 -- .../extension-typography/src/typography.ts | 6 -- packages/extension-underline/src/underline.ts | 20 +++--- 100 files changed, 695 insertions(+), 487 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 97f547480..6c04ef404 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -68,6 +68,8 @@ module.exports = { 'no-dupe-class-members': 'off', '@typescript-eslint/no-dupe-class-members': ['error'], 'lines-between-class-members': 'off', + 'no-shadow': 'off', + '@typescript-eslint/no-shadow': ['error'], '@typescript-eslint/lines-between-class-members': ['error'], '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-empty-interface': 'off', diff --git a/docs/src/demos/Examples/Savvy/ColorHighlighter.ts b/docs/src/demos/Examples/Savvy/ColorHighlighter.ts index c8a5e7a0d..01a059994 100644 --- a/docs/src/demos/Examples/Savvy/ColorHighlighter.ts +++ b/docs/src/demos/Examples/Savvy/ColorHighlighter.ts @@ -27,9 +27,3 @@ export const ColorHighlighter = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - ColorHighlighter: typeof ColorHighlighter, - } -} diff --git a/docs/src/demos/Experiments/Annotation/extension/annotation.ts b/docs/src/demos/Experiments/Annotation/extension/annotation.ts index 06c666b6b..f6b7092d7 100644 --- a/docs/src/demos/Experiments/Annotation/extension/annotation.ts +++ b/docs/src/demos/Experiments/Annotation/extension/annotation.ts @@ -13,6 +13,13 @@ export interface AnnotationOptions { onUpdate: (items: [any?]) => {}, } +declare module '@tiptap/core' { + interface Commands { + addAnnotation: (content: any) => Command, + deleteAnnotation: (id: number) => Command, + } +} + export const Annotation = Extension.create({ name: 'annotation', @@ -25,7 +32,7 @@ export const Annotation = Extension.create({ addCommands() { return { - addAnnotation: (content: any): Command => ({ dispatch, state }) => { + addAnnotation: (content: any) => ({ dispatch, state }) => { const { selection } = state if (selection.empty) { @@ -46,7 +53,7 @@ export const Annotation = Extension.create({ return true }, - deleteAnnotation: (id: number): Command => ({ dispatch, state }) => { + deleteAnnotation: (id: number) => ({ dispatch, state }) => { if (dispatch) { dispatch(state.tr.setMeta(AnnotationPluginKey, { type: 'deleteAnnotation', id })) } @@ -62,9 +69,3 @@ export const Annotation = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Annotation: typeof Annotation, - } -} diff --git a/docs/src/demos/Experiments/Color/extension/Color.ts b/docs/src/demos/Experiments/Color/extension/Color.ts index 0c5e98c66..9bf22475b 100644 --- a/docs/src/demos/Experiments/Color/extension/Color.ts +++ b/docs/src/demos/Experiments/Color/extension/Color.ts @@ -60,9 +60,3 @@ export const Color = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Color: typeof Color, - } -} diff --git a/docs/src/demos/Experiments/Embeds/iframe.ts b/docs/src/demos/Experiments/Embeds/iframe.ts index d2fdb6364..2ca2e9a4f 100644 --- a/docs/src/demos/Experiments/Embeds/iframe.ts +++ b/docs/src/demos/Experiments/Embeds/iframe.ts @@ -7,6 +7,12 @@ export interface IframeOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setIframe: (options: { src: string }) => Command, + } +} + export default Node.create({ name: 'iframe', @@ -55,7 +61,7 @@ export default Node.create({ /** * Add an iframe */ - setIframe: (options: { src: string }): Command => ({ tr, dispatch }) => { + setIframe: (options: { src: string }) => ({ tr, dispatch }) => { const { selection } = tr const node = this.type.create(options) diff --git a/docs/src/demos/Experiments/Linter/extension/Linter.ts b/docs/src/demos/Experiments/Linter/extension/Linter.ts index 4307ed660..7da886b32 100644 --- a/docs/src/demos/Experiments/Linter/extension/Linter.ts +++ b/docs/src/demos/Experiments/Linter/extension/Linter.ts @@ -90,9 +90,3 @@ export const Linter = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Linter: typeof Linter, - } -} diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index c43009502..4301ef7d2 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -16,6 +16,7 @@ import { EditorOptions, EditorContent, CommandSpec, + Commands, CanCommands, ChainedCommands, SingleCommands, diff --git a/packages/core/src/Extension.ts b/packages/core/src/Extension.ts index da6eb8a58..95fdf2539 100644 --- a/packages/core/src/Extension.ts +++ b/packages/core/src/Extension.ts @@ -2,9 +2,9 @@ import { Plugin, Transaction } from 'prosemirror-state' import { InputRule } from 'prosemirror-inputrules' import { Editor } from './Editor' import mergeDeep from './utilities/mergeDeep' -import { GlobalAttributes } from './types' +import { GlobalAttributes, Commands } from './types' -export interface ExtensionConfig { +export interface ExtensionConfig { /** * Name */ @@ -28,7 +28,7 @@ export interface ExtensionConfig { addCommands?: (this: { options: Options, editor: Editor, - }) => Commands, + }) => Partial, /** * Keyboard shortcuts @@ -136,7 +136,7 @@ export interface ExtensionConfig { }) => void) | null, } -export class Extension { +export class Extension { type = 'extension' config: Required = { @@ -159,7 +159,7 @@ export class Extension { options!: Options - constructor(config: ExtensionConfig) { + constructor(config: ExtensionConfig) { this.config = { ...this.config, ...config, @@ -168,13 +168,13 @@ export class Extension { this.options = this.config.defaultOptions } - static create(config: ExtensionConfig) { - return new Extension(config) + static create(config: ExtensionConfig) { + return new Extension(config) } configure(options: Partial = {}) { return Extension - .create(this.config as ExtensionConfig) + .create(this.config as ExtensionConfig) .#configure(options) } @@ -184,10 +184,10 @@ export class Extension { return this } - extend(extendedConfig: Partial>) { - return new Extension({ + extend(extendedConfig: Partial>) { + return new Extension({ ...this.config, ...extendedConfig, - } as ExtensionConfig) + } as ExtensionConfig) } } diff --git a/packages/core/src/ExtensionManager.ts b/packages/core/src/ExtensionManager.ts index 30979e6fb..521075539 100644 --- a/packages/core/src/ExtensionManager.ts +++ b/packages/core/src/ExtensionManager.ts @@ -34,6 +34,7 @@ export default class ExtensionManager { const commands = extension.config.addCommands.bind(context)() + // @ts-ignore editor.registerCommands(commands) if (typeof extension.config.onCreate === 'function') { diff --git a/packages/core/src/Mark.ts b/packages/core/src/Mark.ts index 801d395ea..57303485a 100644 --- a/packages/core/src/Mark.ts +++ b/packages/core/src/Mark.ts @@ -8,10 +8,10 @@ import { Plugin, Transaction } from 'prosemirror-state' import { InputRule } from 'prosemirror-inputrules' import { ExtensionConfig } from './Extension' import mergeDeep from './utilities/mergeDeep' -import { Attributes, Overwrite } from './types' +import { Attributes, Overwrite, Commands } from './types' import { Editor } from './Editor' -export interface MarkConfig extends Overwrite, { +export interface MarkConfig extends Overwrite, { /** * Inclusive */ @@ -70,7 +70,7 @@ export interface MarkConfig extends Overwrite Commands, + }) => Partial, /** * Keyboard shortcuts @@ -189,7 +189,7 @@ export interface MarkConfig extends Overwrite void) | null, }> {} -export class Mark { +export class Mark { type = 'mark' config: Required = { @@ -219,7 +219,7 @@ export class Mark { options!: Options - constructor(config: MarkConfig) { + constructor(config: MarkConfig) { this.config = { ...this.config, ...config, @@ -228,13 +228,13 @@ export class Mark { this.options = this.config.defaultOptions } - static create(config: MarkConfig) { - return new Mark(config) + static create(config: MarkConfig) { + return new Mark(config) } configure(options: Partial = {}) { return Mark - .create(this.config as MarkConfig) + .create(this.config as MarkConfig) .#configure(options) } @@ -244,10 +244,10 @@ export class Mark { return this } - extend(extendedConfig: Partial>) { - return new Mark({ + extend(extendedConfig: Partial>) { + return new Mark({ ...this.config, ...extendedConfig, - } as MarkConfig) + } as MarkConfig) } } diff --git a/packages/core/src/Node.ts b/packages/core/src/Node.ts index 6f04f2422..26f712484 100644 --- a/packages/core/src/Node.ts +++ b/packages/core/src/Node.ts @@ -9,10 +9,12 @@ import { Plugin, Transaction } from 'prosemirror-state' import { InputRule } from 'prosemirror-inputrules' import { ExtensionConfig } from './Extension' import mergeDeep from './utilities/mergeDeep' -import { Attributes, NodeViewRenderer, Overwrite } from './types' +import { + Attributes, NodeViewRenderer, Overwrite, Commands, +} from './types' import { Editor } from './Editor' -export interface NodeConfig extends Overwrite, { +export interface NodeConfig extends Overwrite, { /** * TopNode */ @@ -125,7 +127,7 @@ export interface NodeConfig extends Overwrite Commands, + }) => Partial, /** * Keyboard shortcuts @@ -135,7 +137,8 @@ export interface NodeConfig extends Overwrite { - [key: string]: any + // [key: string]: any + [key: string]: () => boolean }, /** @@ -253,7 +256,7 @@ export interface NodeConfig extends Overwrite void) | null, }> {} -export class Node { +export class Node { type = 'node' config: Required = { @@ -292,7 +295,7 @@ export class Node { options!: Options - constructor(config: NodeConfig) { + constructor(config: NodeConfig) { this.config = { ...this.config, ...config, @@ -301,13 +304,13 @@ export class Node { this.options = this.config.defaultOptions } - static create(config: NodeConfig) { - return new Node(config) + static create(config: NodeConfig) { + return new Node(config) } configure(options: Partial = {}) { return Node - .create(this.config as NodeConfig) + .create(this.config as NodeConfig) .#configure(options) } @@ -317,10 +320,10 @@ export class Node { return this } - extend(extendedConfig: Partial>) { - return new Node({ + extend(extendedConfig: Partial>) { + return new Node({ ...this.config, ...extendedConfig, - } as NodeConfig) + } as NodeConfig) } } diff --git a/packages/core/src/commands/blur.ts b/packages/core/src/commands/blur.ts index 0f1d260eb..41a67af84 100644 --- a/packages/core/src/commands/blur.ts +++ b/packages/core/src/commands/blur.ts @@ -1,12 +1,18 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Removes focus from the editor. */ -export const blur = (): Command => ({ view }) => { +export const blur: Commands['blur'] = () => ({ view }) => { const element = view.dom as HTMLElement element.blur() 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 748a48800..2624ef128 100644 --- a/packages/core/src/commands/clearContent.ts +++ b/packages/core/src/commands/clearContent.ts @@ -1,8 +1,14 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Clear the whole document. */ -export const clearContent = (emitUpdate: Boolean = false): Command => ({ commands }) => { +export const clearContent: Commands['clearContent'] = (emitUpdate = false) => ({ commands }) => { return commands.setContent('', emitUpdate) } + +declare module '@tiptap/core' { + interface Commands { + clearContent: (emitUpdate: Boolean) => Command, + } +} diff --git a/packages/core/src/commands/clearNodes.ts b/packages/core/src/commands/clearNodes.ts index 1aec3bbb0..fa92ff08d 100644 --- a/packages/core/src/commands/clearNodes.ts +++ b/packages/core/src/commands/clearNodes.ts @@ -1,10 +1,10 @@ import { liftTarget } from 'prosemirror-transform' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Normalize nodes to a simple paragraph. */ -export const clearNodes = (): Command => ({ state, tr, dispatch }) => { +export const clearNodes: Commands['clearNodes'] = () => ({ state, tr, dispatch }) => { const { selection } = tr const { from, to } = selection @@ -30,3 +30,9 @@ export const clearNodes = (): Command => ({ 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 a40322727..8ba9632e0 100644 --- a/packages/core/src/commands/command.ts +++ b/packages/core/src/commands/command.ts @@ -1,8 +1,14 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Define a command inline. */ -export const command = (fn: (props: Parameters[0]) => boolean): Command => props => { +export const command: Commands['command'] = fn => props => { return fn(props) } + +declare module '@tiptap/core' { + interface Commands { + command: (fn: (props: Parameters[0]) => boolean) => Command, + } +} diff --git a/packages/core/src/commands/createParagraphNear.ts b/packages/core/src/commands/createParagraphNear.ts index f37269b76..96947f16e 100644 --- a/packages/core/src/commands/createParagraphNear.ts +++ b/packages/core/src/commands/createParagraphNear.ts @@ -1,9 +1,15 @@ import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Create a paragraph nearby. */ -export const createParagraphNear = (): Command => ({ state, dispatch }) => { +export const createParagraphNear: Commands['createParagraphNear'] = () => ({ state, dispatch }) => { return originalCreateParagraphNear(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + createParagraphNear: () => Command, + } +} diff --git a/packages/core/src/commands/deleteRange.ts b/packages/core/src/commands/deleteRange.ts index 8c2d721e6..ac6389875 100644 --- a/packages/core/src/commands/deleteRange.ts +++ b/packages/core/src/commands/deleteRange.ts @@ -1,9 +1,9 @@ -import { Command, Range } from '../types' +import { Command, Commands, Range } from '../types' /** * Delete a given range. */ -export const deleteRange = (range: Range): Command => ({ tr, dispatch }) => { +export const deleteRange: Commands['deleteRange'] = range => ({ tr, dispatch }) => { const { from, to } = range if (dispatch) { @@ -12,3 +12,9 @@ export const deleteRange = (range: Range): Command => ({ 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 a79e47176..6459256a0 100644 --- a/packages/core/src/commands/deleteSelection.ts +++ b/packages/core/src/commands/deleteSelection.ts @@ -1,9 +1,15 @@ import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Delete the selection, if there is one. */ -export const deleteSelection = (): Command => ({ state, dispatch }) => { +export const deleteSelection: Commands['deleteSelection'] = () => ({ state, dispatch }) => { return originalDeleteSelection(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + deleteSelection: () => Command, + } +} diff --git a/packages/core/src/commands/enter.ts b/packages/core/src/commands/enter.ts index 60d52642b..660c13124 100644 --- a/packages/core/src/commands/enter.ts +++ b/packages/core/src/commands/enter.ts @@ -1,8 +1,14 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Trigger enter. */ -export const enter = (): Command => ({ commands }) => { +export const enter: Commands['enter'] = () => ({ commands }) => { return commands.keyboardShortcut('Enter') } + +declare module '@tiptap/core' { + interface Commands { + enter: () => Command, + } +} diff --git a/packages/core/src/commands/exitCode.ts b/packages/core/src/commands/exitCode.ts index e18457571..3e554a90d 100644 --- a/packages/core/src/commands/exitCode.ts +++ b/packages/core/src/commands/exitCode.ts @@ -1,9 +1,15 @@ import { exitCode as originalExitCode } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Exit from a code block. */ -export const exitCode = (): Command => ({ state, dispatch }) => { +export const exitCode: Commands['exitCode'] = () => ({ state, dispatch }) => { return originalExitCode(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + exitCode: () => Command, + } +} diff --git a/packages/core/src/commands/extendMarkRange.ts b/packages/core/src/commands/extendMarkRange.ts index c3615439e..a005be8e3 100644 --- a/packages/core/src/commands/extendMarkRange.ts +++ b/packages/core/src/commands/extendMarkRange.ts @@ -1,13 +1,13 @@ import { TextSelection } from 'prosemirror-state' import { MarkType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' /** * Extends the text selection to the current mark. */ -export const extendMarkRange = (typeOrName: string | MarkType): Command => ({ tr, state, dispatch }) => { +export const extendMarkRange: Commands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => { const type = getMarkType(typeOrName, state.schema) const { doc, selection } = tr const { $from, empty } = selection @@ -24,3 +24,9 @@ export const extendMarkRange = (typeOrName: string | MarkType): Command => ({ 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 ef5e052a4..b0b23537c 100644 --- a/packages/core/src/commands/first.ts +++ b/packages/core/src/commands/first.ts @@ -1,9 +1,9 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Runs one command after the other and stops at the first which returns true. */ -export const first = (commands: Command[] | ((props: Parameters[0]) => Command[])): Command => props => { +export const first: Commands['first'] = commands => props => { const items = typeof commands === 'function' ? commands(props) : commands @@ -16,3 +16,9 @@ export const first = (commands: Command[] | ((props: Parameters[0]) => 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 8b6d13d4a..9f987c2f7 100644 --- a/packages/core/src/commands/focus.ts +++ b/packages/core/src/commands/focus.ts @@ -1,5 +1,5 @@ import { EditorState, TextSelection } from 'prosemirror-state' -import { Command, FocusPosition } from '../types' +import { Command, Commands, FocusPosition } from '../types' import minMax from '../utilities/minMax' import isTextSelection from '../helpers/isTextSelection' @@ -33,7 +33,7 @@ function resolveSelection(state: EditorState, position: FocusPosition = null) { /** * Focus the editor at the given position. */ -export const focus = (position: FocusPosition = null): Command => ({ +export const focus: Commands['focus'] = (position = null) => ({ editor, view, tr, @@ -62,3 +62,9 @@ export const focus = (position: FocusPosition = null): Command => ({ 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 9a996ea45..7d63ae7e8 100644 --- a/packages/core/src/commands/insertHTML.ts +++ b/packages/core/src/commands/insertHTML.ts @@ -2,7 +2,7 @@ import { DOMParser } from 'prosemirror-model' import { Selection, Transaction } from 'prosemirror-state' import { ReplaceStep, ReplaceAroundStep } from 'prosemirror-transform' import elementFromString from '../utilities/elementFromString' -import { Command } from '../types' +import { Command, Commands } from '../types' // TODO: move to utils // https://github.com/ProseMirror/prosemirror-state/blob/master/src/selection.js#L466 @@ -20,7 +20,7 @@ function selectionToInsertionEnd(tr: Transaction, startLen: number, bias: number /** * Insert a string of HTML at the current position. */ -export const insertHTML = (value: string): Command => ({ tr, state, dispatch }) => { +export const insertHTML: Commands['insertHTML'] = value => ({ tr, state, dispatch }) => { const { selection } = tr const element = elementFromString(value) const slice = DOMParser.fromSchema(state.schema).parseSlice(element) @@ -32,3 +32,9 @@ export const insertHTML = (value: string): Command => ({ tr, state, dispatch }) 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 a6d7f3537..61fa1f926 100644 --- a/packages/core/src/commands/insertText.ts +++ b/packages/core/src/commands/insertText.ts @@ -1,12 +1,18 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Insert a string of text at the current position. */ -export const insertText = (value: string): Command => ({ tr, dispatch }) => { +export const insertText: Commands['insertText'] = value => ({ tr, dispatch }) => { if (dispatch) { tr.insertText(value) } 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 5ab6d46dc..ef8016800 100644 --- a/packages/core/src/commands/joinBackward.ts +++ b/packages/core/src/commands/joinBackward.ts @@ -1,9 +1,15 @@ import { joinBackward as originalJoinBackward } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Join two nodes backward. */ -export const joinBackward = (): Command => ({ state, dispatch }) => { +export const joinBackward: Commands['joinBackward'] = () => ({ state, dispatch }) => { return originalJoinBackward(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + joinBackward: () => Command, + } +} diff --git a/packages/core/src/commands/joinForward.ts b/packages/core/src/commands/joinForward.ts index c964e332d..979954953 100644 --- a/packages/core/src/commands/joinForward.ts +++ b/packages/core/src/commands/joinForward.ts @@ -1,9 +1,15 @@ import { joinForward as originalJoinForward } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Join two nodes forward. */ -export const joinForward = (): Command => ({ state, dispatch }) => { +export const joinForward: Commands['joinForward'] = () => ({ state, dispatch }) => { return originalJoinForward(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + joinForward: () => Command, + } +} diff --git a/packages/core/src/commands/keyboardShortcut.ts b/packages/core/src/commands/keyboardShortcut.ts index 31db9eed1..7921df134 100644 --- a/packages/core/src/commands/keyboardShortcut.ts +++ b/packages/core/src/commands/keyboardShortcut.ts @@ -1,4 +1,4 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' const mac = typeof navigator !== 'undefined' ? /Mac/.test(navigator.platform) : false @@ -59,7 +59,7 @@ function normalizeKeyName(name: string) { /** * Trigger a keyboard shortcut. */ -export const keyboardShortcut = (name: string): Command => ({ +export const keyboardShortcut: Commands['keyboardShortcut'] = name => ({ editor, view, tr, @@ -93,3 +93,9 @@ export const keyboardShortcut = (name: string): Command => ({ 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 53f7960ee..16498ce40 100644 --- a/packages/core/src/commands/lift.ts +++ b/packages/core/src/commands/lift.ts @@ -1,13 +1,13 @@ import { lift as originalLift } from 'prosemirror-commands' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands, AnyObject } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' /** * Removes an existing wrap. */ -export const lift = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => { +export const lift: Commands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,3 +17,9 @@ export const lift = (typeOrName: string | NodeType, attributes = {}): Command => 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 9b9337b5e..2986eebd0 100644 --- a/packages/core/src/commands/liftEmptyBlock.ts +++ b/packages/core/src/commands/liftEmptyBlock.ts @@ -1,9 +1,15 @@ import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Lift block if empty. */ -export const liftEmptyBlock = (): Command => ({ state, dispatch }) => { +export const liftEmptyBlock: Commands['liftEmptyBlock'] = () => ({ state, dispatch }) => { return originalLiftEmptyBlock(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + liftEmptyBlock: () => Command, + } +} diff --git a/packages/core/src/commands/liftListItem.ts b/packages/core/src/commands/liftListItem.ts index adf539e7d..09d68da78 100644 --- a/packages/core/src/commands/liftListItem.ts +++ b/packages/core/src/commands/liftListItem.ts @@ -1,13 +1,19 @@ import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' /** * Lift the list item into a wrapping list. */ -export const liftListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => { +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 633437501..1cf5c40a3 100644 --- a/packages/core/src/commands/newlineInCode.ts +++ b/packages/core/src/commands/newlineInCode.ts @@ -1,9 +1,15 @@ import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Add a newline character in code. */ -export const newlineInCode = (): Command => ({ state, dispatch }) => { +export const newlineInCode: Commands['newlineInCode'] = () => ({ state, dispatch }) => { return originalNewlineInCode(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + newlineInCode: () => Command, + } +} diff --git a/packages/core/src/commands/replace.ts b/packages/core/src/commands/replace.ts index 1535b09e7..24ae5910f 100644 --- a/packages/core/src/commands/replace.ts +++ b/packages/core/src/commands/replace.ts @@ -1,12 +1,18 @@ import { NodeType } from 'prosemirror-model' -import { Command, AnyObject } from '../types' +import { Command, Commands, AnyObject } from '../types' /** * Replaces text with a node. */ -export const replace = (typeOrName: string | NodeType, attributes: AnyObject = {}): Command => ({ state, commands }) => { +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 bb87a7746..111b78135 100644 --- a/packages/core/src/commands/replaceRange.ts +++ b/packages/core/src/commands/replaceRange.ts @@ -1,11 +1,16 @@ import { NodeType } from 'prosemirror-model' import getNodeType from '../helpers/getNodeType' -import { Command, Range, AnyObject } from '../types' +import { + Command, + Commands, + Range, + AnyObject, +} from '../types' /** * Replaces text with a node within a range. */ -export const replaceRange = (range: Range, typeOrName: string | NodeType, attributes: AnyObject = {}): Command => ({ tr, state, dispatch }) => { +export const replaceRange: Commands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { from, to } = range const $from = tr.doc.resolve(from) @@ -21,3 +26,9 @@ export const replaceRange = (range: Range, typeOrName: string | NodeType, 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 f8606de29..e179da0e0 100644 --- a/packages/core/src/commands/resetNodeAttributes.ts +++ b/packages/core/src/commands/resetNodeAttributes.ts @@ -1,12 +1,12 @@ import { NodeType } from 'prosemirror-model' import getNodeType from '../helpers/getNodeType' import deleteProps from '../utilities/deleteProps' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Resets node attributes to the default value. */ -export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: string | string[]): Command => ({ tr, state, dispatch }) => { +export const resetNodeAttributes: Commands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { selection } = tr const { from, to } = selection @@ -19,3 +19,9 @@ export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: s 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 e31946f17..b0cf8dac9 100644 --- a/packages/core/src/commands/scrollIntoView.ts +++ b/packages/core/src/commands/scrollIntoView.ts @@ -1,12 +1,18 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Scroll the selection into view. */ -export const scrollIntoView = (): Command => ({ tr, dispatch }) => { +export const scrollIntoView: Commands['scrollIntoView'] = () => ({ tr, dispatch }) => { if (dispatch) { tr.scrollIntoView() } 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 14b1c4bb9..4c1296144 100644 --- a/packages/core/src/commands/selectAll.ts +++ b/packages/core/src/commands/selectAll.ts @@ -1,9 +1,15 @@ import { selectAll as originalSelectAll } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Select the whole document. */ -export const selectAll = (): Command => ({ state, dispatch }) => { +export const selectAll: Commands['selectAll'] = () => ({ state, dispatch }) => { return originalSelectAll(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + selectAll: () => Command, + } +} diff --git a/packages/core/src/commands/selectNodeBackward.ts b/packages/core/src/commands/selectNodeBackward.ts index d785dbf39..174b50fe2 100644 --- a/packages/core/src/commands/selectNodeBackward.ts +++ b/packages/core/src/commands/selectNodeBackward.ts @@ -1,9 +1,15 @@ import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Select a node backward. */ -export const selectNodeBackward = (): Command => ({ state, dispatch }) => { +export const selectNodeBackward: Commands['selectNodeBackward'] = () => ({ state, dispatch }) => { return originalSelectNodeBackward(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + selectNodeBackward: () => Command, + } +} diff --git a/packages/core/src/commands/selectNodeForward.ts b/packages/core/src/commands/selectNodeForward.ts index a1ac72253..4a2feecec 100644 --- a/packages/core/src/commands/selectNodeForward.ts +++ b/packages/core/src/commands/selectNodeForward.ts @@ -1,9 +1,15 @@ import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Select a node forward. */ -export const selectNodeForward = (): Command => ({ state, dispatch }) => { +export const selectNodeForward: Commands['selectNodeForward'] = () => ({ state, dispatch }) => { return originalSelectNodeForward(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + selectNodeForward: () => Command, + } +} diff --git a/packages/core/src/commands/selectParentNode.ts b/packages/core/src/commands/selectParentNode.ts index 61686cafd..464ec68ac 100644 --- a/packages/core/src/commands/selectParentNode.ts +++ b/packages/core/src/commands/selectParentNode.ts @@ -1,9 +1,15 @@ import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Select the parent node. */ -export const selectParentNode = (): Command => ({ state, dispatch }) => { +export const selectParentNode: Commands['selectParentNode'] = () => ({ state, dispatch }) => { return originalSelectParentNode(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + selectParentNode: () => Command, + } +} diff --git a/packages/core/src/commands/setContent.ts b/packages/core/src/commands/setContent.ts index 669b6b2f5..0f57904c1 100644 --- a/packages/core/src/commands/setContent.ts +++ b/packages/core/src/commands/setContent.ts @@ -1,10 +1,10 @@ import { TextSelection } from 'prosemirror-state' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' /** * Replace the whole document with new content. */ -export const setContent = (content: string, emitUpdate: Boolean = false, parseOptions = {}): Command => ({ tr, editor, dispatch }) => { +export const setContent: Commands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => { const { createDocument } = editor const { doc } = tr const document = createDocument(content, parseOptions) @@ -18,3 +18,9 @@ export const setContent = (content: string, emitUpdate: Boolean = false, parseOp 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 bfd58dc6a..e1a74c5d0 100644 --- a/packages/core/src/commands/setMark.ts +++ b/packages/core/src/commands/setMark.ts @@ -1,12 +1,12 @@ import { MarkType } from 'prosemirror-model' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkAttributes from '../helpers/getMarkAttributes' /** * Add a mark with new attributes. */ -export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ tr, state, dispatch }) => { +export const setMark: Commands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const { selection } = tr const { from, to, empty } = selection const type = getMarkType(typeOrName, state.schema) @@ -26,3 +26,9 @@ export const setMark = (typeOrName: string | MarkType, attributes?: {}): Command 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 679366668..8531fa5c4 100644 --- a/packages/core/src/commands/setNode.ts +++ b/packages/core/src/commands/setNode.ts @@ -1,13 +1,19 @@ import { NodeType } from 'prosemirror-model' import { setBlockType } from 'prosemirror-commands' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' /** * Replace a given range with a node. */ -export const setNode = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => { +export const setNode: Commands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) - return setBlockType(type, attrs)(state, dispatch) + 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 b3a133f86..01ed0c2f9 100644 --- a/packages/core/src/commands/sinkListItem.ts +++ b/packages/core/src/commands/sinkListItem.ts @@ -1,13 +1,19 @@ import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' /** * Sink the list item down into an inner list. */ -export const sinkListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => { +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 46d4e8837..d79084354 100644 --- a/packages/core/src/commands/splitBlock.ts +++ b/packages/core/src/commands/splitBlock.ts @@ -1,7 +1,7 @@ import { canSplit } from 'prosemirror-transform' import { ContentMatch, Fragment } from 'prosemirror-model' import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state' -import { Command } from '../types' +import { Command, Commands } from '../types' import getSplittedAttributes from '../helpers/getSplittedAttributes' function defaultBlockAt(match: ContentMatch) { @@ -31,7 +31,7 @@ function keepMarks(state: EditorState) { /** * Forks a new node from an existing node. */ -export const splitBlock = (options: Partial = {}): Command => ({ +export const splitBlock: Commands['splitBlock'] = (options = {}) => ({ tr, state, dispatch, @@ -126,3 +126,9 @@ export const splitBlock = (options: Partial = {}): Command => 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 aca57dba8..28c85b986 100644 --- a/packages/core/src/commands/splitListItem.ts +++ b/packages/core/src/commands/splitListItem.ts @@ -6,14 +6,14 @@ import { } from 'prosemirror-model' import { canSplit } from 'prosemirror-transform' import { TextSelection } from 'prosemirror-state' -import { Command } from '../types' +import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' import getSplittedAttributes from '../helpers/getSplittedAttributes' /** * Splits one list item into two list items. */ -export const splitListItem = (typeOrName: string | NodeType): Command => ({ +export const splitListItem: Commands['splitListItem'] = typeOrName => ({ tr, state, dispatch, editor, }) => { const type = getNodeType(typeOrName, state.schema) @@ -110,3 +110,9 @@ export const splitListItem = (typeOrName: string | NodeType): Command => ({ 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 80a5f18ce..29bc47311 100644 --- a/packages/core/src/commands/toggleList.ts +++ b/packages/core/src/commands/toggleList.ts @@ -1,5 +1,5 @@ import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' import findParentNode from '../helpers/findParentNode' import isList from '../helpers/isList' @@ -7,7 +7,7 @@ import isList from '../helpers/isList' /** * Toggle between different list types. */ -export const toggleList = (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType): Command => ({ +export const toggleList: Commands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({ editor, tr, state, dispatch, chain, commands, can, }) => { const { extensions } = editor.options @@ -53,3 +53,9 @@ export const toggleList = (listTypeOrName: string | NodeType, itemTypeOrName: st 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 9a1922deb..d342ae331 100644 --- a/packages/core/src/commands/toggleMark.ts +++ b/packages/core/src/commands/toggleMark.ts @@ -1,12 +1,12 @@ import { MarkType } from 'prosemirror-model' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import isMarkActive from '../helpers/isMarkActive' /** * Toggle a mark on and off. */ -export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Command => ({ state, commands }) => { +export const toggleMark: Commands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => { const type = getMarkType(typeOrName, state.schema) const isActive = isMarkActive(state, type, attributes) @@ -16,3 +16,9 @@ export const toggleMark = (typeOrName: string | MarkType, attributes?: {}): Comm 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 6f880855f..13d168a1e 100644 --- a/packages/core/src/commands/toggleNode.ts +++ b/packages/core/src/commands/toggleNode.ts @@ -1,19 +1,25 @@ import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' /** * Toggle a node with another node. */ -export const toggleNode = (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs = {}): Command => ({ state, commands }) => { +export const toggleNode: Commands['toggleNode'] = (typeOrName, toggleTypeOrName, attributes = {}) => ({ state, commands }) => { const type = getNodeType(typeOrName, state.schema) const toggleType = getNodeType(toggleTypeOrName, state.schema) - const isActive = isNodeActive(state, type, attrs) + const isActive = isNodeActive(state, type, attributes) if (isActive) { return commands.setNode(toggleType) } - return commands.setNode(type, attrs) + 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 c70cdf059..f48dcdc2d 100644 --- a/packages/core/src/commands/toggleWrap.ts +++ b/packages/core/src/commands/toggleWrap.ts @@ -1,13 +1,13 @@ import { wrapIn, lift } from 'prosemirror-commands' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +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. */ -export const toggleWrap = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => { +export const toggleWrap: Commands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,3 +17,9 @@ export const toggleWrap = (typeOrName: string | NodeType, attributes = {}): Comm 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 12acb4ae2..31678716d 100644 --- a/packages/core/src/commands/undoInputRule.ts +++ b/packages/core/src/commands/undoInputRule.ts @@ -1,9 +1,15 @@ import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules' -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Undo an input rule. */ -export const undoInputRule = (): Command => ({ state, dispatch }) => { +export const undoInputRule: Commands['undoInputRule'] = () => ({ state, dispatch }) => { return originalUndoInputRule(state, dispatch) } + +declare module '@tiptap/core' { + interface Commands { + undoInputRule: () => Command, + } +} diff --git a/packages/core/src/commands/unsetAllMarks.ts b/packages/core/src/commands/unsetAllMarks.ts index 385d331d7..b353d0665 100644 --- a/packages/core/src/commands/unsetAllMarks.ts +++ b/packages/core/src/commands/unsetAllMarks.ts @@ -1,9 +1,9 @@ -import { Command } from '../types' +import { Command, Commands } from '../types' /** * Remove all marks in the current selection. */ -export const unsetAllMarks = (): Command => ({ tr, state, dispatch }) => { +export const unsetAllMarks: Commands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => { const { selection } = tr const { from, to, empty } = selection @@ -21,3 +21,9 @@ export const unsetAllMarks = (): Command => ({ tr, state, dispatch }) => { 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 1f2d28c5b..ef5bb339c 100644 --- a/packages/core/src/commands/unsetMark.ts +++ b/packages/core/src/commands/unsetMark.ts @@ -1,12 +1,12 @@ import { MarkType } from 'prosemirror-model' -import { Command } from '../types' +import { Command, Commands } from '../types' import getMarkType from '../helpers/getMarkType' import getMarkRange from '../helpers/getMarkRange' /** * Remove all marks in the current selection. */ -export const unsetMark = (typeOrName: string | MarkType): Command => ({ tr, state, dispatch }) => { +export const unsetMark: Commands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => { const { selection } = tr const type = getMarkType(typeOrName, state.schema) let { from, to } = selection @@ -28,3 +28,9 @@ export const unsetMark = (typeOrName: string | MarkType): Command => ({ tr, stat 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 690b813ab..bff2f4ffd 100644 --- a/packages/core/src/commands/updateNodeAttributes.ts +++ b/packages/core/src/commands/updateNodeAttributes.ts @@ -1,11 +1,11 @@ import { NodeType } from 'prosemirror-model' import getNodeType from '../helpers/getNodeType' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' /** * Update attributes of a node. */ -export const updateNodeAttributes = (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => { +export const updateNodeAttributes: Commands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const { selection } = tr const { from, to } = selection @@ -21,3 +21,9 @@ export const updateNodeAttributes = (typeOrName: string | NodeType, attributes: 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 bcf89da1b..5e278a844 100644 --- a/packages/core/src/commands/wrapIn.ts +++ b/packages/core/src/commands/wrapIn.ts @@ -1,13 +1,13 @@ import { wrapIn as originalWrapIn } from 'prosemirror-commands' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import isNodeActive from '../helpers/isNodeActive' import getNodeType from '../helpers/getNodeType' /** * Wraps nodes in another node. */ -export const wrapIn = (typeOrName: string | NodeType, attributes = {}): Command => ({ state, dispatch }) => { +export const wrapIn: Commands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) const isActive = isNodeActive(state, type, attributes) @@ -17,3 +17,9 @@ export const wrapIn = (typeOrName: string | NodeType, attributes = {}): Command 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 1ffa88df1..94ab955a3 100644 --- a/packages/core/src/commands/wrapInList.ts +++ b/packages/core/src/commands/wrapInList.ts @@ -1,13 +1,19 @@ import { wrapInList as originalWrapInList } from 'prosemirror-schema-list' import { NodeType } from 'prosemirror-model' -import { Command } from '../types' +import { AnyObject, Command, Commands } from '../types' import getNodeType from '../helpers/getNodeType' /** * Wrap a node in a list. */ -export const wrapInList = (typeOrName: string | NodeType, attrs?: {}): Command => ({ state, dispatch }) => { +export const wrapInList: Commands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => { const type = getNodeType(typeOrName, state.schema) - return originalWrapInList(type, attrs)(state, dispatch) + return originalWrapInList(type, attributes)(state, dispatch) +} + +declare module '@tiptap/core' { + interface Commands { + wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command, + } } diff --git a/packages/core/src/extensions/clipboardTextSerializer.ts b/packages/core/src/extensions/clipboardTextSerializer.ts index b6bb56be5..e92086713 100644 --- a/packages/core/src/extensions/clipboardTextSerializer.ts +++ b/packages/core/src/extensions/clipboardTextSerializer.ts @@ -52,9 +52,3 @@ export const ClipboardTextSerializer = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - ClipboardTextSerializer: typeof ClipboardTextSerializer, - } -} diff --git a/packages/core/src/extensions/commands.ts b/packages/core/src/extensions/commands.ts index cdab42832..39e770f00 100644 --- a/packages/core/src/extensions/commands.ts +++ b/packages/core/src/extensions/commands.ts @@ -98,9 +98,3 @@ export const Commands = Extension.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Commands: typeof Commands, - } -} diff --git a/packages/core/src/extensions/editable.ts b/packages/core/src/extensions/editable.ts index 7e70245e3..7bb996bdb 100644 --- a/packages/core/src/extensions/editable.ts +++ b/packages/core/src/extensions/editable.ts @@ -15,9 +15,3 @@ export const Editable = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Editable: typeof Editable, - } -} diff --git a/packages/core/src/extensions/focusEvents.ts b/packages/core/src/extensions/focusEvents.ts index 68e4cf152..f1ad1317b 100644 --- a/packages/core/src/extensions/focusEvents.ts +++ b/packages/core/src/extensions/focusEvents.ts @@ -43,9 +43,3 @@ export const FocusEvents = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - FocusEvents: typeof FocusEvents, - } -} diff --git a/packages/core/src/extensions/keymap.ts b/packages/core/src/extensions/keymap.ts index 388c3e174..c1a62db06 100644 --- a/packages/core/src/extensions/keymap.ts +++ b/packages/core/src/extensions/keymap.ts @@ -34,9 +34,3 @@ export const Keymap = Extension.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Keymap: typeof Keymap, - } -} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e3967ae8a..cfa75a8f7 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -22,3 +22,4 @@ export { default as isCellSelection } from './helpers/isCellSelection' export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos' export interface AllExtensions {} +export interface Commands {} diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index f1f5bcb63..a04edfdc5 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -14,7 +14,9 @@ import { Extension } from './Extension' import { Node } from './Node' import { Mark } from './Mark' import { Editor } from './Editor' -import { AllExtensions } from '.' +import { Commands } from '.' + +export { Commands } export type Extensions = (Extension | Node | Mark)[] @@ -106,29 +108,31 @@ export type NodeViewRendererProps = { export type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {}) -export type UnfilteredCommands = { - [Item in keyof AllExtensions]: AllExtensions[Item] extends Extension - ? ExtensionCommands - : AllExtensions[Item] extends Node - ? NodeCommands - : AllExtensions[Item] extends Mark - ? MarkCommands - : never -} +// export type UnfilteredCommands = { +// [Item in keyof AllExtensions]: AllExtensions[Item] extends Extension +// ? ExtensionCommands +// : AllExtensions[Item] extends Node +// ? NodeCommands +// : AllExtensions[Item] extends Mark +// ? MarkCommands +// : never +// } export type ValuesOf = T[keyof T]; export type KeysWithTypeOf = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T] -export type AllCommands = UnionToIntersection>>> +// export type Commands = UnionToIntersection>>> + +// export type Commands = Commands export type SingleCommands = { - [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => boolean + [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => boolean : never } export type ChainedCommands = { - [Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any - ? (...args: Parameters) => ChainedCommands + [Item in keyof Commands]: Commands[Item] extends (...args: any[]) => any + ? (...args: Parameters) => ChainedCommands : never } & { run: () => boolean diff --git a/packages/extension-blockquote/src/blockquote.ts b/packages/extension-blockquote/src/blockquote.ts index 2078dd741..686915345 100644 --- a/packages/extension-blockquote/src/blockquote.ts +++ b/packages/extension-blockquote/src/blockquote.ts @@ -7,9 +7,18 @@ export interface BlockquoteOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setBlockquote: () => Command, + toggleBlockquote: () => Command, + unsetBlockquote: () => Command, + } +} + export const inputRegex = /^\s*>\s$/gm export const Blockquote = Node.create({ + name: 'blockquote', defaultOptions: { @@ -37,19 +46,19 @@ export const Blockquote = Node.create({ /** * Set a blockquote node */ - setBlockquote: (): Command => ({ commands }) => { + setBlockquote: () => ({ commands }) => { return commands.wrapIn('blockquote') }, /** * Toggle a blockquote node */ - toggleBlockquote: (): Command => ({ commands }) => { + toggleBlockquote: () => ({ commands }) => { return commands.toggleWrap('blockquote') }, /** * Unset a blockquote node */ - unsetBlockquote: (): Command => ({ commands }) => { + unsetBlockquote: () => ({ commands }) => { return commands.lift('blockquote') }, } @@ -67,9 +76,3 @@ export const Blockquote = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Blockquote: typeof Blockquote, - } -} diff --git a/packages/extension-bold/src/bold.ts b/packages/extension-bold/src/bold.ts index 7ef4aef35..76f4e8ef4 100644 --- a/packages/extension-bold/src/bold.ts +++ b/packages/extension-bold/src/bold.ts @@ -12,6 +12,14 @@ export interface BoldOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setBold: () => Command, + toggleBold: () => Command, + unsetBold: () => Command, + } +} + export const starInputRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/gm export const starPasteRegex = /(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/gm export const underscoreInputRegex = /(?:^|\s)((?:__)((?:[^__]+))(?:__))$/gm @@ -49,19 +57,19 @@ export const Bold = Mark.create({ /** * Set a bold mark */ - setBold: (): Command => ({ commands }) => { + setBold: () => ({ commands }) => { return commands.setMark('bold') }, /** * Toggle a bold mark */ - toggleBold: (): Command => ({ commands }) => { + toggleBold: () => ({ commands }) => { return commands.toggleMark('bold') }, /** * Unset a bold mark */ - unsetBold: (): Command => ({ commands }) => { + unsetBold: () => ({ commands }) => { return commands.unsetMark('bold') }, } @@ -87,9 +95,3 @@ export const Bold = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Bold: typeof Bold, - } -} diff --git a/packages/extension-bullet-list/src/bullet-list.ts b/packages/extension-bullet-list/src/bullet-list.ts index 878759dd5..c1499ee4a 100644 --- a/packages/extension-bullet-list/src/bullet-list.ts +++ b/packages/extension-bullet-list/src/bullet-list.ts @@ -7,6 +7,12 @@ export interface BulletListOptions { }, } +declare module '@tiptap/core' { + interface Commands { + toggleBulletList: () => Command, + } +} + export const inputRegex = /^\s*([-+*])\s$/ export const BulletList = Node.create({ @@ -35,7 +41,7 @@ export const BulletList = Node.create({ /** * Toggle a bullet list */ - toggleBulletList: (): Command => ({ commands }) => { + toggleBulletList: () => ({ commands }) => { return commands.toggleList('bulletList', 'listItem') }, } @@ -53,9 +59,3 @@ export const BulletList = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - BulletList: typeof BulletList, - } -} diff --git a/packages/extension-character-count/src/character-count.ts b/packages/extension-character-count/src/character-count.ts index 9d6583cfb..4492b4985 100644 --- a/packages/extension-character-count/src/character-count.ts +++ b/packages/extension-character-count/src/character-count.ts @@ -33,9 +33,3 @@ export const CharacterCount = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - CharacterCount: typeof CharacterCount, - } -} diff --git a/packages/extension-code-block/src/code-block.ts b/packages/extension-code-block/src/code-block.ts index 6a0588bce..e7bf3a3b6 100644 --- a/packages/extension-code-block/src/code-block.ts +++ b/packages/extension-code-block/src/code-block.ts @@ -8,6 +8,13 @@ export interface CodeBlockOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setCodeBlock: (attributes?: { language: string }) => Command, + toggleCodeBlock: (attributes?: { language: string }) => Command, + } +} + export const backtickInputRegex = /^```(?[a-z]*)? $/ export const tildeInputRegex = /^~~~(?[a-z]*)? $/ @@ -77,13 +84,13 @@ export const CodeBlock = Node.create({ /** * Set a code block */ - setCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => { + setCodeBlock: attributes => ({ commands }) => { return commands.setNode('codeBlock', attributes) }, /** * Toggle a code block */ - toggleCodeBlock: (attributes?: { language: string }): Command => ({ commands }) => { + toggleCodeBlock: attributes => ({ commands }) => { return commands.toggleNode('codeBlock', 'paragraph', attributes) }, } @@ -102,9 +109,3 @@ export const CodeBlock = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - CodeBlock: typeof CodeBlock, - } -} diff --git a/packages/extension-code/src/code.ts b/packages/extension-code/src/code.ts index f0951e001..64daf4baa 100644 --- a/packages/extension-code/src/code.ts +++ b/packages/extension-code/src/code.ts @@ -12,6 +12,14 @@ export interface CodeOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setCode: () => Command, + toggleCode: () => Command, + unsetCode: () => Command, + } +} + export const inputRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))$/gm export const pasteRegex = /(?:^|\s)((?:`)((?:[^`]+))(?:`))/gm @@ -39,19 +47,19 @@ export const Code = Mark.create({ /** * Set a code mark */ - setCode: (): Command => ({ commands }) => { + setCode: () => ({ commands }) => { return commands.setMark('code') }, /** * Toggle inline code */ - toggleCode: (): Command => ({ commands }) => { + toggleCode: () => ({ commands }) => { return commands.toggleMark('code') }, /** * Unset a code mark */ - unsetCode: (): Command => ({ commands }) => { + unsetCode: () => ({ commands }) => { return commands.unsetMark('code') }, } @@ -75,9 +83,3 @@ export const Code = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Code: typeof Code, - } -} diff --git a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts index 4f91ce292..c4d98d47b 100644 --- a/packages/extension-collaboration-cursor/src/collaboration-cursor.ts +++ b/packages/extension-collaboration-cursor/src/collaboration-cursor.ts @@ -1,4 +1,4 @@ -import { Extension, Command } from '@tiptap/core' +import { Extension, Command, AnyObject } from '@tiptap/core' import { yCursorPlugin } from 'y-prosemirror' export interface CollaborationCursorOptions { @@ -8,6 +8,12 @@ export interface CollaborationCursorOptions { onUpdate: (users: { clientId: string, [key: string]: any }[]) => null, } +declare module '@tiptap/core' { + interface Commands { + user: (attributes: AnyObject) => Command, + } +} + const awarenessStatesToArray = (states: Map) => { return Array.from(states.entries()).map(([key, value]) => { return { @@ -47,7 +53,7 @@ export const CollaborationCursor = Extension.create({ /** * Update details of the current user */ - user: (attributes: { [key: string]: any }): Command => () => { + user: attributes => () => { this.options.user = attributes this.options.provider.awareness.setLocalStateField('user', this.options.user) @@ -87,9 +93,3 @@ export const CollaborationCursor = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - CollaborationCursor: typeof CollaborationCursor, - } -} diff --git a/packages/extension-collaboration/src/collaboration.ts b/packages/extension-collaboration/src/collaboration.ts index fa3fe8164..bbe729541 100644 --- a/packages/extension-collaboration/src/collaboration.ts +++ b/packages/extension-collaboration/src/collaboration.ts @@ -6,6 +6,13 @@ import { yUndoPlugin, } from 'y-prosemirror' +declare module '@tiptap/core' { + interface Commands { + undo: () => Command, + redo: () => Command, + } +} + export interface CollaborationOptions { /** * An initialized Y.js document. @@ -35,7 +42,7 @@ export const Collaboration = Extension.create({ /** * Undo recent changes */ - undo: (): Command => ({ tr, state }) => { + undo: () => ({ tr, state }) => { tr.setMeta('preventDispatch', true) return undo(state) @@ -43,7 +50,7 @@ export const Collaboration = Extension.create({ /** * Reapply reverted changes */ - redo: (): Command => ({ tr, state }) => { + redo: () => ({ tr, state }) => { tr.setMeta('preventDispatch', true) return redo(state) @@ -70,9 +77,3 @@ export const Collaboration = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Collaboration: typeof Collaboration, - } -} diff --git a/packages/extension-document/src/document.ts b/packages/extension-document/src/document.ts index bd9c69c14..2046dc654 100644 --- a/packages/extension-document/src/document.ts +++ b/packages/extension-document/src/document.ts @@ -5,9 +5,3 @@ export const Document = Node.create({ topNode: true, content: 'block+', }) - -declare module '@tiptap/core' { - interface AllExtensions { - Document: typeof Document, - } -} diff --git a/packages/extension-dropcursor/src/dropcursor.ts b/packages/extension-dropcursor/src/dropcursor.ts index 618414256..404ea8084 100644 --- a/packages/extension-dropcursor/src/dropcursor.ts +++ b/packages/extension-dropcursor/src/dropcursor.ts @@ -22,9 +22,3 @@ export const Dropcursor = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Dropcursor: typeof Dropcursor, - } -} diff --git a/packages/extension-focus/src/focus.ts b/packages/extension-focus/src/focus.ts index 56d8d5faa..291fb9799 100644 --- a/packages/extension-focus/src/focus.ts +++ b/packages/extension-focus/src/focus.ts @@ -79,9 +79,3 @@ export const FocusClasses = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - FocusClasses: typeof FocusClasses, - } -} diff --git a/packages/extension-font-family/src/font-family.ts b/packages/extension-font-family/src/font-family.ts index 24565aae3..2378a6e2e 100644 --- a/packages/extension-font-family/src/font-family.ts +++ b/packages/extension-font-family/src/font-family.ts @@ -5,6 +5,13 @@ type FontFamilyOptions = { types: string[], } +declare module '@tiptap/core' { + interface Commands { + setFontFamily: (fontFamily: string) => Command, + unsetFontFamily: () => Command, + } +} + export const FontFamily = Extension.create({ name: 'fontFamily', @@ -42,7 +49,7 @@ export const FontFamily = Extension.create({ /** * Set the font family */ - setFontFamily: (fontFamily: string): Command => ({ chain }) => { + setFontFamily: fontFamily => ({ chain }) => { return chain() .setMark('textStyle', { fontFamily }) .run() @@ -50,7 +57,7 @@ export const FontFamily = Extension.create({ /** * Unset the font family */ - unsetFontFamily: (): Command => ({ chain }) => { + unsetFontFamily: () => ({ chain }) => { return chain() .setMark('textStyle', { fontFamily: null }) .removeEmptyTextStyle() @@ -59,9 +66,3 @@ export const FontFamily = Extension.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - FontFamily: typeof FontFamily, - } -} diff --git a/packages/extension-gapcursor/src/gapcursor.ts b/packages/extension-gapcursor/src/gapcursor.ts index 2902eb517..6ec394164 100644 --- a/packages/extension-gapcursor/src/gapcursor.ts +++ b/packages/extension-gapcursor/src/gapcursor.ts @@ -10,9 +10,3 @@ export const Gapcursor = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Gapcursor: typeof Gapcursor, - } -} diff --git a/packages/extension-hard-break/src/hard-break.ts b/packages/extension-hard-break/src/hard-break.ts index 4ab7fa776..4770280aa 100644 --- a/packages/extension-hard-break/src/hard-break.ts +++ b/packages/extension-hard-break/src/hard-break.ts @@ -7,6 +7,12 @@ export interface HardBreakOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setHardBreak: () => Command, + } +} + export const HardBreak = Node.create({ name: 'hardBreak', @@ -36,7 +42,7 @@ export const HardBreak = Node.create({ /** * Add a hard break */ - setHardBreak: (): Command => ({ commands, state, dispatch }) => { + setHardBreak: () => ({ commands, state, dispatch }) => { return commands.first([ () => exitCode(state, dispatch), () => { @@ -58,9 +64,3 @@ export const HardBreak = Node.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - HardBreak: typeof HardBreak, - } -} diff --git a/packages/extension-heading/src/heading.ts b/packages/extension-heading/src/heading.ts index 10478f0a3..694593c89 100644 --- a/packages/extension-heading/src/heading.ts +++ b/packages/extension-heading/src/heading.ts @@ -10,6 +10,13 @@ export interface HeadingOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setHeading: (attributes: { level: Level }) => Command, + toggleHeading: (attributes: { level: Level }) => Command, + } +} + export const Heading = Node.create({ name: 'heading', @@ -55,7 +62,7 @@ export const Heading = Node.create({ /** * Set a heading node */ - setHeading: (attributes: { level: Level }): Command => ({ commands }) => { + setHeading: attributes => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false } @@ -65,7 +72,7 @@ export const Heading = Node.create({ /** * Toggle a heading node */ - toggleHeading: (attributes: { level: Level }): Command => ({ commands }) => { + toggleHeading: attributes => ({ commands }) => { if (!this.options.levels.includes(attributes.level)) { return false } @@ -90,9 +97,3 @@ export const Heading = Node.create({ }) }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Heading: typeof Heading, - } -} diff --git a/packages/extension-highlight/src/highlight.ts b/packages/extension-highlight/src/highlight.ts index ba8754c47..fed06ceee 100644 --- a/packages/extension-highlight/src/highlight.ts +++ b/packages/extension-highlight/src/highlight.ts @@ -13,6 +13,14 @@ export interface HighlightOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setHighlight: (attributes?: { color: string }) => Command, + toggleHighlight: (attributes?: { color: string }) => Command, + unsetHighlight: () => Command, + } +} + export const inputRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))$/gm export const pasteRegex = /(?:^|\s)((?:==)((?:[^~]+))(?:==))/gm @@ -68,19 +76,19 @@ export const Highlight = Mark.create({ /** * Set a highlight mark */ - setHighlight: (attributes?: { color: string }): Command => ({ commands }) => { + setHighlight: attributes => ({ commands }) => { return commands.setMark('highlight', attributes) }, /** * Toggle a highlight mark */ - toggleHighlight: (attributes?: { color: string }): Command => ({ commands }) => { + toggleHighlight: attributes => ({ commands }) => { return commands.toggleMark('highlight', attributes) }, /** * Unset a highlight mark */ - unsetHighlight: (): Command => ({ commands }) => { + unsetHighlight: () => ({ commands }) => { return commands.unsetMark('highlight') }, } @@ -104,9 +112,3 @@ export const Highlight = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Highlight: typeof Highlight, - } -} diff --git a/packages/extension-history/src/history.ts b/packages/extension-history/src/history.ts index d54ed76c0..a6b6c898f 100644 --- a/packages/extension-history/src/history.ts +++ b/packages/extension-history/src/history.ts @@ -6,6 +6,13 @@ export interface HistoryOptions { newGroupDelay: number, } +declare module '@tiptap/core' { + interface Commands { + undo: () => Command, + redo: () => Command, + } +} + export const History = Extension.create({ name: 'history', @@ -19,13 +26,13 @@ export const History = Extension.create({ /** * Undo recent changes */ - undo: (): Command => ({ state, dispatch }) => { + undo: () => ({ state, dispatch }) => { return undo(state, dispatch) }, /** * Reapply reverted changes */ - redo: (): Command => ({ state, dispatch }) => { + redo: () => ({ state, dispatch }) => { return redo(state, dispatch) }, } @@ -45,9 +52,3 @@ export const History = Extension.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - History: typeof History, - } -} diff --git a/packages/extension-horizontal-rule/src/horizontal-rule.ts b/packages/extension-horizontal-rule/src/horizontal-rule.ts index f1a94cfbe..a2ee82c55 100644 --- a/packages/extension-horizontal-rule/src/horizontal-rule.ts +++ b/packages/extension-horizontal-rule/src/horizontal-rule.ts @@ -11,6 +11,12 @@ export interface HorizontalRuleOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setHorizontalRule: () => Command, + } +} + export const HorizontalRule = Node.create({ name: 'horizontalRule', @@ -35,7 +41,7 @@ export const HorizontalRule = Node.create({ /** * Add a horizontal rule */ - setHorizontalRule: (): Command => ({ tr, dispatch }) => { + setHorizontalRule: () => ({ tr, dispatch }) => { if (dispatch) { tr.replaceSelectionWith(this.type.create()) } @@ -51,9 +57,3 @@ export const HorizontalRule = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - HorizontalRule: typeof HorizontalRule, - } -} diff --git a/packages/extension-image/src/image.ts b/packages/extension-image/src/image.ts index 400d84131..e2617ffe3 100644 --- a/packages/extension-image/src/image.ts +++ b/packages/extension-image/src/image.ts @@ -12,6 +12,12 @@ export interface ImageOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setImage: (options: { src: string, alt?: string, title?: string }) => Command, + } +} + export const inputRegex = /!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/ export const Image = Node.create({ @@ -63,7 +69,7 @@ export const Image = Node.create({ /** * Add an image */ - setImage: (options: { src: string, alt?: string, title?: string }): Command => ({ tr, dispatch }) => { + setImage: options => ({ tr, dispatch }) => { const { selection } = tr const node = this.type.create(options) @@ -86,9 +92,3 @@ export const Image = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Image: typeof Image, - } -} diff --git a/packages/extension-italic/src/italic.ts b/packages/extension-italic/src/italic.ts index 1f35e0fb2..d6bf5f0ac 100644 --- a/packages/extension-italic/src/italic.ts +++ b/packages/extension-italic/src/italic.ts @@ -12,6 +12,14 @@ export interface ItalicOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setItalic: () => Command, + toggleItalic: () => Command, + unsetItalic: () => Command, + } +} + export const starInputRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/gm export const starPasteRegex = /(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/gm export const underscoreInputRegex = /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/gm @@ -48,19 +56,19 @@ export const Italic = Mark.create({ /** * Set an italic mark */ - setItalic: (): Command => ({ commands }) => { + setItalic: () => ({ commands }) => { return commands.setMark('italic') }, /** * Toggle an italic mark */ - toggleItalic: (): Command => ({ commands }) => { + toggleItalic: () => ({ commands }) => { return commands.toggleMark('italic') }, /** * Unset an italic mark */ - unsetItalic: (): Command => ({ commands }) => { + unsetItalic: () => ({ commands }) => { return commands.unsetMark('italic') }, } @@ -86,9 +94,3 @@ export const Italic = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Italic: typeof Italic, - } -} diff --git a/packages/extension-link/src/link.ts b/packages/extension-link/src/link.ts index ee1738b06..5821ae3b6 100644 --- a/packages/extension-link/src/link.ts +++ b/packages/extension-link/src/link.ts @@ -13,6 +13,14 @@ export interface LinkOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setLink: (attributes: { href: string, target?: string }) => Command, + toggleLink: (attributes: { href: string, target?: string }) => Command, + unsetLink: () => Command, + } +} + export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)/gi export const pasteRegexWithBrackets = /(?:\()https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)(?:\))/gi @@ -55,19 +63,19 @@ export const Link = Mark.create({ /** * Set a link mark */ - setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { + setLink: attributes => ({ commands }) => { return commands.setMark('link', attributes) }, /** * Toggle a link mark */ - toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { + toggleLink: attributes => ({ commands }) => { return commands.toggleMark('link', attributes) }, /** * Unset a link mark */ - unsetLink: (): Command => ({ commands }) => { + unsetLink: () => ({ commands }) => { return commands.unsetMark('link') }, } @@ -105,9 +113,3 @@ export const Link = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Link: typeof Link, - } -} diff --git a/packages/extension-list-item/src/list-item.ts b/packages/extension-list-item/src/list-item.ts index 23e47f3c1..e4f79aa9b 100644 --- a/packages/extension-list-item/src/list-item.ts +++ b/packages/extension-list-item/src/list-item.ts @@ -37,9 +37,3 @@ export const ListItem = Node.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - ListItem: typeof ListItem, - } -} diff --git a/packages/extension-mention/src/mention.ts b/packages/extension-mention/src/mention.ts index f0dba98f8..e739a66bf 100644 --- a/packages/extension-mention/src/mention.ts +++ b/packages/extension-mention/src/mention.ts @@ -106,9 +106,3 @@ export const Mention = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Mention: typeof Mention, - } -} diff --git a/packages/extension-ordered-list/src/ordered-list.ts b/packages/extension-ordered-list/src/ordered-list.ts index 7edaa59be..82e02976d 100644 --- a/packages/extension-ordered-list/src/ordered-list.ts +++ b/packages/extension-ordered-list/src/ordered-list.ts @@ -7,6 +7,12 @@ export interface OrderedListOptions { }, } +declare module '@tiptap/core' { + interface Commands { + toggleOrderedList: () => Command, + } +} + export const inputRegex = /^(\d+)\.\s$/ export const OrderedList = Node.create({ @@ -54,7 +60,7 @@ export const OrderedList = Node.create({ /** * Toggle an ordered list */ - toggleOrderedList: (): Command => ({ commands }) => { + toggleOrderedList: () => ({ commands }) => { return commands.toggleList('orderedList', 'listItem') }, } @@ -77,9 +83,3 @@ export const OrderedList = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - OrderedList: typeof OrderedList, - } -} diff --git a/packages/extension-paragraph/src/paragraph.ts b/packages/extension-paragraph/src/paragraph.ts index e8b01a69c..af6466c22 100644 --- a/packages/extension-paragraph/src/paragraph.ts +++ b/packages/extension-paragraph/src/paragraph.ts @@ -6,6 +6,12 @@ export interface ParagraphOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setParagraph: () => Command, + } +} + export const Paragraph = Node.create({ name: 'paragraph', @@ -32,7 +38,7 @@ export const Paragraph = Node.create({ /** * Toggle a paragraph */ - setParagraph: (): Command => ({ commands }) => { + setParagraph: () => ({ commands }) => { return commands.toggleNode('paragraph', 'paragraph') }, } @@ -44,9 +50,3 @@ export const Paragraph = Node.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Paragraph: typeof Paragraph, - } -} diff --git a/packages/extension-strike/src/strike.ts b/packages/extension-strike/src/strike.ts index 83d77f011..9d7c0f4b1 100644 --- a/packages/extension-strike/src/strike.ts +++ b/packages/extension-strike/src/strike.ts @@ -12,6 +12,14 @@ export interface StrikeOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setStrike: () => Command, + toggleStrike: () => Command, + unsetStrike: () => Command, + } +} + export const inputRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/gm export const pasteRegex = /(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/gm @@ -48,19 +56,19 @@ export const Strike = Mark.create({ /** * Set a strike mark */ - setStrike: (): Command => ({ commands }) => { + setStrike: () => ({ commands }) => { return commands.setMark('strike') }, /** * Toggle a strike mark */ - toggleStrike: (): Command => ({ commands }) => { + toggleStrike: () => ({ commands }) => { return commands.toggleMark('strike') }, /** * Unset a strike mark */ - unsetStrike: (): Command => ({ commands }) => { + unsetStrike: () => ({ commands }) => { return commands.unsetMark('strike') }, } @@ -84,9 +92,3 @@ export const Strike = Mark.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Strike: typeof Strike, - } -} diff --git a/packages/extension-table-cell/src/table-cell.ts b/packages/extension-table-cell/src/table-cell.ts index 4faee8860..c5a4ef51b 100644 --- a/packages/extension-table-cell/src/table-cell.ts +++ b/packages/extension-table-cell/src/table-cell.ts @@ -43,9 +43,3 @@ export const TableCell = Node.create({ }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TableCell: typeof TableCell, - } -} diff --git a/packages/extension-table-header/src/table-header.ts b/packages/extension-table-header/src/table-header.ts index f7ebf2120..85acf65b8 100644 --- a/packages/extension-table-header/src/table-header.ts +++ b/packages/extension-table-header/src/table-header.ts @@ -43,9 +43,3 @@ export const TableHeader = Node.create({ }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TableHeader: typeof TableHeader, - } -} diff --git a/packages/extension-table-row/src/table-row.ts b/packages/extension-table-row/src/table-row.ts index bc85b9468..9f7d9dc1f 100644 --- a/packages/extension-table-row/src/table-row.ts +++ b/packages/extension-table-row/src/table-row.ts @@ -27,9 +27,3 @@ export const TableRow = Node.create({ return ['tr', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TableRow: typeof TableRow, - } -} diff --git a/packages/extension-table/src/table.ts b/packages/extension-table/src/table.ts index 45bee3d37..69422ca71 100644 --- a/packages/extension-table/src/table.ts +++ b/packages/extension-table/src/table.ts @@ -41,6 +41,29 @@ export interface TableOptions { allowTableNodeSelection: boolean, } +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, + } +} + export const Table = Node.create({ name: 'table', @@ -74,8 +97,8 @@ export const Table = Node.create({ addCommands() { return { - insertTable: (options = { rows: 3, cols: 3, withHeaderRow: true }): Command => ({ tr, dispatch, editor }) => { - const node = createTable(editor.schema, options.rows, options.cols, options.withHeaderRow) + insertTable: ({ rows = 3, cols = 3, withHeaderRow = true } = {}) => ({ tr, dispatch, editor }) => { + const node = createTable(editor.schema, rows, cols, withHeaderRow) if (dispatch) { const offset = tr.selection.anchor + 1 @@ -87,59 +110,59 @@ export const Table = Node.create({ return true }, - addColumnBefore: (): Command => ({ state, dispatch }) => { + addColumnBefore: () => ({ state, dispatch }) => { return addColumnBefore(state, dispatch) }, - addColumnAfter: (): Command => ({ state, dispatch }) => { + addColumnAfter: () => ({ state, dispatch }) => { return addColumnAfter(state, dispatch) }, - deleteColumn: (): Command => ({ state, dispatch }) => { + deleteColumn: () => ({ state, dispatch }) => { return deleteColumn(state, dispatch) }, - addRowBefore: (): Command => ({ state, dispatch }) => { + addRowBefore: () => ({ state, dispatch }) => { return addRowBefore(state, dispatch) }, - addRowAfter: (): Command => ({ state, dispatch }) => { + addRowAfter: () => ({ state, dispatch }) => { return addRowAfter(state, dispatch) }, - deleteRow: (): Command => ({ state, dispatch }) => { + deleteRow: () => ({ state, dispatch }) => { return deleteRow(state, dispatch) }, - deleteTable: (): Command => ({ state, dispatch }) => { + deleteTable: () => ({ state, dispatch }) => { return deleteTable(state, dispatch) }, - mergeCells: (): Command => ({ state, dispatch }) => { + mergeCells: () => ({ state, dispatch }) => { return mergeCells(state, dispatch) }, - splitCell: (): Command => ({ state, dispatch }) => { + splitCell: () => ({ state, dispatch }) => { return splitCell(state, dispatch) }, - toggleHeaderColumn: (): Command => ({ state, dispatch }) => { + toggleHeaderColumn: () => ({ state, dispatch }) => { return toggleHeaderColumn(state, dispatch) }, - toggleHeaderRow: (): Command => ({ state, dispatch }) => { + toggleHeaderRow: () => ({ state, dispatch }) => { return toggleHeaderRow(state, dispatch) }, - toggleHeaderCell: (): Command => ({ state, dispatch }) => { + toggleHeaderCell: () => ({ state, dispatch }) => { return toggleHeaderCell(state, dispatch) }, - mergeOrSplit: (): Command => ({ state, dispatch }) => { + mergeOrSplit: () => ({ state, dispatch }) => { if (mergeCells(state, dispatch)) { return true } return splitCell(state, dispatch) }, - setCellAttribute: (name: string, value: any): Command => ({ state, dispatch }) => { + setCellAttribute: (name, value) => ({ state, dispatch }) => { return setCellAttr(name, value)(state, dispatch) }, - goToNextCell: (): Command => ({ state, dispatch }) => { + goToNextCell: () => ({ state, dispatch }) => { return goToNextCell(1)(state, dispatch) }, - goToPreviousCell: (): Command => ({ state, dispatch }) => { + goToPreviousCell: () => ({ state, dispatch }) => { return goToNextCell(-1)(state, dispatch) }, - fixTables: (): Command => ({ state, dispatch }) => { + fixTables: () => ({ state, dispatch }) => { if (dispatch) { fixTables(state) } @@ -223,9 +246,3 @@ export const Table = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Table: typeof Table, - } -} diff --git a/packages/extension-task-item/src/task-item.ts b/packages/extension-task-item/src/task-item.ts index 7601211be..52d4af448 100644 --- a/packages/extension-task-item/src/task-item.ts +++ b/packages/extension-task-item/src/task-item.ts @@ -139,9 +139,3 @@ export const TaskItem = Node.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TaskItem: typeof TaskItem, - } -} diff --git a/packages/extension-task-list/src/task-list.ts b/packages/extension-task-list/src/task-list.ts index e6025f2fb..f30774f85 100644 --- a/packages/extension-task-list/src/task-list.ts +++ b/packages/extension-task-list/src/task-list.ts @@ -6,6 +6,12 @@ export interface TaskListOptions { }, } +declare module '@tiptap/core' { + interface Commands { + toggleTaskList: () => Command, + } +} + export const TaskList = Node.create({ name: 'taskList', @@ -35,7 +41,7 @@ export const TaskList = Node.create({ /** * Toggle a task list */ - toggleTaskList: (): Command => ({ commands }) => { + toggleTaskList: () => ({ commands }) => { return commands.toggleList('taskList', 'taskItem') }, } @@ -47,9 +53,3 @@ export const TaskList = Node.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TaskList: typeof TaskList, - } -} diff --git a/packages/extension-text-align/src/text-align.ts b/packages/extension-text-align/src/text-align.ts index 66e37a56e..838b1f5ff 100644 --- a/packages/extension-text-align/src/text-align.ts +++ b/packages/extension-text-align/src/text-align.ts @@ -6,6 +6,13 @@ type TextAlignOptions = { defaultAlignment: string, } +declare module '@tiptap/core' { + interface Commands { + setTextAlign: (alignment: string) => Command, + unsetTextAlign: () => Command, + } +} + export const TextAlign = Extension.create({ name: 'textAlign', @@ -39,7 +46,7 @@ export const TextAlign = Extension.create({ /** * Set the text align attribute */ - setTextAlign: (alignment: string): Command => ({ commands }) => { + setTextAlign: (alignment: string) => ({ commands }) => { if (!this.options.alignments.includes(alignment)) { return false } @@ -49,7 +56,7 @@ export const TextAlign = Extension.create({ /** * Unset the text align attribute */ - unsetTextAlign: (): Command => ({ commands }) => { + unsetTextAlign: () => ({ commands }) => { return this.options.types.every(type => commands.resetNodeAttributes(type, 'textAlign')) }, } @@ -64,9 +71,3 @@ export const TextAlign = Extension.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TextAlign: typeof TextAlign, - } -} diff --git a/packages/extension-text-style/src/text-style.ts b/packages/extension-text-style/src/text-style.ts index 61d9984bf..c8098dc35 100644 --- a/packages/extension-text-style/src/text-style.ts +++ b/packages/extension-text-style/src/text-style.ts @@ -11,6 +11,12 @@ export interface TextStyleOptions { }, } +declare module '@tiptap/core' { + interface Commands { + removeEmptyTextStyle: () => Command, + } +} + export const TextStyle = Mark.create({ name: 'textStyle', @@ -44,7 +50,7 @@ export const TextStyle = Mark.create({ /** * Remove spans without inline style attributes. */ - removeEmptyTextStyle: (): Command => ({ state, commands }) => { + removeEmptyTextStyle: () => ({ state, commands }) => { const attributes = getMarkAttributes(state, this.type) const hasStyles = Object.entries(attributes).every(([, value]) => !!value) @@ -58,9 +64,3 @@ export const TextStyle = Mark.create({ }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - TextStyle: typeof TextStyle, - } -} diff --git a/packages/extension-text/src/text.ts b/packages/extension-text/src/text.ts index f503a7eb8..0755d5e7a 100644 --- a/packages/extension-text/src/text.ts +++ b/packages/extension-text/src/text.ts @@ -4,9 +4,3 @@ export const Text = Node.create({ name: 'text', group: 'inline', }) - -declare module '@tiptap/core' { - interface AllExtensions { - Text: typeof Text, - } -} diff --git a/packages/extension-typography/src/typography.ts b/packages/extension-typography/src/typography.ts index f0ab4cfff..f0caf7dff 100644 --- a/packages/extension-typography/src/typography.ts +++ b/packages/extension-typography/src/typography.ts @@ -44,9 +44,3 @@ export const Typography = Extension.create({ ] }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Typography: typeof Typography, - } -} diff --git a/packages/extension-underline/src/underline.ts b/packages/extension-underline/src/underline.ts index 9ba220496..80bda97f0 100644 --- a/packages/extension-underline/src/underline.ts +++ b/packages/extension-underline/src/underline.ts @@ -6,6 +6,14 @@ export interface UnderlineOptions { }, } +declare module '@tiptap/core' { + interface Commands { + setUnderline: () => Command, + toggleUnderline: () => Command, + unsetUnderline: () => Command, + } +} + export const Underline = Mark.create({ name: 'underline', @@ -33,19 +41,19 @@ export const Underline = Mark.create({ /** * Set an underline mark */ - setUnderline: (): Command => ({ commands }) => { + setUnderline: () => ({ commands }) => { return commands.setMark('underline') }, /** * Toggle an underline mark */ - toggleUnderline: (): Command => ({ commands }) => { + toggleUnderline: () => ({ commands }) => { return commands.toggleMark('underline') }, /** * Unset an underline mark */ - unsetUnderline: (): Command => ({ commands }) => { + unsetUnderline: () => ({ commands }) => { return commands.unsetMark('underline') }, } @@ -57,9 +65,3 @@ export const Underline = Mark.create({ } }, }) - -declare module '@tiptap/core' { - interface AllExtensions { - Underline: typeof Underline, - } -}