Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@tiptap/core

Package Overview
Dependencies
Maintainers
2
Versions
331
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/core - npm Package Compare versions

Comparing version 2.0.0-alpha.16 to 2.0.0-alpha.17

dist/packages/core/src/commands/enter.d.ts

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

# [2.0.0-alpha.17](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.16...@tiptap/core@2.0.0-alpha.17) (2021-02-16)
**Note:** Version bump only for package @tiptap/core
# [2.0.0-alpha.16](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/core@2.0.0-alpha.15...@tiptap/core@2.0.0-alpha.16) (2021-02-07)

@@ -8,0 +16,0 @@

16

dist/packages/core/src/CommandManager.d.ts
import { EditorState, Transaction } from 'prosemirror-state';
import { Editor } from './Editor';
import { SingleCommands, ChainedCommands, CanCommands, CommandSpec, CommandProps } from './types';
import { SingleCommands, ChainedCommands, CanCommands, RawCommands, CommandProps } from './types';
export default class CommandManager {
editor: Editor;
commands: {
[key: string]: any;
};
methodNames: string[];
constructor(editor: Editor);
/**
* Register a command.
*
* @param name The name of your command
* @param callback The method of your command
*/
registerCommand(name: string, callback: CommandSpec): Editor;
commands: RawCommands;
constructor(editor: Editor, commands: RawCommands);
createCommands(): SingleCommands;

@@ -19,0 +9,0 @@ createChain(startTr?: Transaction, shouldDispatch?: boolean): ChainedCommands;

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Removes focus from the editor.
*/
export declare const blur: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
blur: {
/**
* Removes focus from the editor.
*/
blur: () => Command;
};
}
}
export declare const blur: RawCommands['blur'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Clear the whole document.
*/
export declare const clearContent: (emitUpdate?: Boolean) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
clearContent: {
/**
* Clear the whole document.
*/
clearContent: (emitUpdate: Boolean) => Command;
};
}
}
export declare const clearContent: RawCommands['clearContent'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Normalize nodes to a simple paragraph.
*/
export declare const clearNodes: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
clearNodes: {
/**
* Normalize nodes to a simple paragraph.
*/
clearNodes: () => Command;
};
}
}
export declare const clearNodes: RawCommands['clearNodes'];

@@ -1,5 +0,12 @@

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

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Create a paragraph nearby.
*/
export declare const createParagraphNear: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
createParagraphNear: {
/**
* Create a paragraph nearby.
*/
createParagraphNear: () => Command;
};
}
}
export declare const createParagraphNear: RawCommands['createParagraphNear'];

@@ -1,5 +0,12 @@

import { Command, Range } from '../types';
/**
* Delete a given range.
*/
export declare const deleteRange: (range: Range) => Command;
import { Command, RawCommands, Range } from '../types';
declare module '@tiptap/core' {
interface Commands {
deleteRange: {
/**
* Delete a given range.
*/
deleteRange: (range: Range) => Command;
};
}
}
export declare const deleteRange: RawCommands['deleteRange'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Delete the selection, if there is one.
*/
export declare const deleteSelection: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
deleteSelection: {
/**
* Delete the selection, if there is one.
*/
deleteSelection: () => Command;
};
}
}
export declare const deleteSelection: RawCommands['deleteSelection'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Exit from a code block.
*/
export declare const exitCode: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
exitCode: {
/**
* Exit from a code block.
*/
exitCode: () => Command;
};
}
}
export declare const exitCode: RawCommands['exitCode'];
import { MarkType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Extends the text selection to the current mark.
*/
export declare const extendMarkRange: (typeOrName: string | MarkType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
extendMarkRange: {
/**
* Extends the text selection to the current mark.
*/
extendMarkRange: (typeOrName: string | MarkType) => Command;
};
}
}
export declare const extendMarkRange: RawCommands['extendMarkRange'];

@@ -1,5 +0,12 @@

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

@@ -1,5 +0,12 @@

import { Command, FocusPosition } from '../types';
/**
* Focus the editor at the given position.
*/
export declare const focus: (position?: FocusPosition) => Command;
import { Command, RawCommands, FocusPosition } from '../types';
declare module '@tiptap/core' {
interface Commands {
focus: {
/**
* Focus the editor at the given position.
*/
focus: (position?: FocusPosition) => Command;
};
}
}
export declare const focus: RawCommands['focus'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Insert a string of HTML at the current position.
*/
export declare const insertHTML: (value: string) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
insertHTML: {
/**
* Insert a string of HTML at the current position.
*/
insertHTML: (value: string) => Command;
};
}
}
export declare const insertHTML: RawCommands['insertHTML'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Insert a string of text at the current position.
*/
export declare const insertText: (value: string) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
insertText: {
/**
* Insert a string of text at the current position.
*/
insertText: (value: string) => Command;
};
}
}
export declare const insertText: RawCommands['insertText'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Join two nodes backward.
*/
export declare const joinBackward: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
joinBackward: {
/**
* Join two nodes backward.
*/
joinBackward: () => Command;
};
}
}
export declare const joinBackward: RawCommands['joinBackward'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Join two nodes forward.
*/
export declare const joinForward: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
joinForward: {
/**
* Join two nodes forward.
*/
joinForward: () => Command;
};
}
}
export declare const joinForward: RawCommands['joinForward'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Removes an existing wrap.
*/
export declare const lift: (typeOrName: string | NodeType, attributes?: {}) => Command;
import { Command, RawCommands, AnyObject } from '../types';
declare module '@tiptap/core' {
interface Commands {
lift: {
/**
* Removes an existing wrap.
*/
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const lift: RawCommands['lift'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Lift block if empty.
*/
export declare const liftEmptyBlock: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
liftEmptyBlock: {
/**
* Lift block if empty.
*/
liftEmptyBlock: () => Command;
};
}
}
export declare const liftEmptyBlock: RawCommands['liftEmptyBlock'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Lift the list item into a wrapping list.
*/
export declare const liftListItem: (typeOrName: string | NodeType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
liftListItem: {
/**
* Lift the list item into a wrapping list.
*/
liftListItem: (typeOrName: string | NodeType) => Command;
};
}
}
export declare const liftListItem: RawCommands['liftListItem'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Add a newline character in code.
*/
export declare const newlineInCode: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
newlineInCode: {
/**
* Add a newline character in code.
*/
newlineInCode: () => Command;
};
}
}
export declare const newlineInCode: RawCommands['newlineInCode'];
import { NodeType } from 'prosemirror-model';
import { Command, AnyObject } from '../types';
/**
* Replaces text with a node.
*/
export declare const replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
import { Command, RawCommands, AnyObject } from '../types';
declare module '@tiptap/core' {
interface Commands {
replace: {
/**
* Replaces text with a node.
*/
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const replace: RawCommands['replace'];
import { NodeType } from 'prosemirror-model';
import { Command, Range, AnyObject } from '../types';
/**
* Replaces text with a node within a range.
*/
export declare const replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command;
import { Command, RawCommands, Range, AnyObject } from '../types';
declare module '@tiptap/core' {
interface Commands {
replaceRange: {
/**
* Replaces text with a node within a range.
*/
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const replaceRange: RawCommands['replaceRange'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Resets node attributes to the default value.
*/
export declare const resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
resetNodeAttributes: {
/**
* Resets node attributes to the default value.
*/
resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command;
};
}
}
export declare const resetNodeAttributes: RawCommands['resetNodeAttributes'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Scroll the selection into view.
*/
export declare const scrollIntoView: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
scrollIntoView: {
/**
* Scroll the selection into view.
*/
scrollIntoView: () => Command;
};
}
}
export declare const scrollIntoView: RawCommands['scrollIntoView'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Select the whole document.
*/
export declare const selectAll: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
selectAll: {
/**
* Select the whole document.
*/
selectAll: () => Command;
};
}
}
export declare const selectAll: RawCommands['selectAll'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Select a node backward.
*/
export declare const selectNodeBackward: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
selectNodeBackward: {
/**
* Select a node backward.
*/
selectNodeBackward: () => Command;
};
}
}
export declare const selectNodeBackward: RawCommands['selectNodeBackward'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Select a node forward.
*/
export declare const selectNodeForward: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
selectNodeForward: {
/**
* Select a node forward.
*/
selectNodeForward: () => Command;
};
}
}
export declare const selectNodeForward: RawCommands['selectNodeForward'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Select the parent node.
*/
export declare const selectParentNode: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
selectParentNode: {
/**
* Select the parent node.
*/
selectParentNode: () => Command;
};
}
}
export declare const selectParentNode: RawCommands['selectParentNode'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Replace the whole document with new content.
*/
export declare const setContent: (content: string, emitUpdate?: Boolean, parseOptions?: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
setContent: {
/**
* Replace the whole document with new content.
*/
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command;
};
}
}
export declare const setContent: RawCommands['setContent'];
import { MarkType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Add a mark with new attributes.
*/
export declare const setMark: (typeOrName: string | MarkType, attributes?: {} | undefined) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
setMark: {
/**
* Add a mark with new attributes.
*/
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command;
};
}
}
export declare const setMark: RawCommands['setMark'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Replace a given range with a node.
*/
export declare const setNode: (typeOrName: string | NodeType, attrs?: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
setNode: {
/**
* Replace a given range with a node.
*/
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const setNode: RawCommands['setNode'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Sink the list item down into an inner list.
*/
export declare const sinkListItem: (typeOrName: string | NodeType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
sinkListItem: {
/**
* Sink the list item down into an inner list.
*/
sinkListItem: (typeOrName: string | NodeType) => Command;
};
}
}
export declare const sinkListItem: RawCommands['sinkListItem'];

@@ -1,8 +0,14 @@

import { Command } from '../types';
export interface SplitBlockOptions {
keepMarks: boolean;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
splitBlock: {
/**
* Forks a new node from an existing node.
*/
splitBlock: (options?: {
keepMarks?: boolean;
}) => Command;
};
}
}
/**
* Forks a new node from an existing node.
*/
export declare const splitBlock: (options?: Partial<SplitBlockOptions>) => Command;
export declare const splitBlock: RawCommands['splitBlock'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Splits one list item into two list items.
*/
export declare const splitListItem: (typeOrName: string | NodeType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
splitListItem: {
/**
* Splits one list item into two list items.
*/
splitListItem: (typeOrName: string | NodeType) => Command;
};
}
}
export declare const splitListItem: RawCommands['splitListItem'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Toggle between different list types.
*/
export declare const toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
toggleList: {
/**
* Toggle between different list types.
*/
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command;
};
}
}
export declare const toggleList: RawCommands['toggleList'];
import { MarkType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Toggle a mark on and off.
*/
export declare const toggleMark: (typeOrName: string | MarkType, attributes?: {} | undefined) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
toggleMark: {
/**
* Toggle a mark on and off.
*/
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command;
};
}
}
export declare const toggleMark: RawCommands['toggleMark'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Toggle a node with another node.
*/
export declare const toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attrs?: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
toggleNode: {
/**
* Toggle a node with another node.
*/
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const toggleNode: RawCommands['toggleNode'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Wraps nodes in another node, or removes an existing wrap.
*/
export declare const toggleWrap: (typeOrName: string | NodeType, attributes?: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
toggleWrap: {
/**
* Wraps nodes in another node, or removes an existing wrap.
*/
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const toggleWrap: RawCommands['toggleWrap'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Undo an input rule.
*/
export declare const undoInputRule: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
undoInputRule: {
/**
* Undo an input rule.
*/
undoInputRule: () => Command;
};
}
}
export declare const undoInputRule: RawCommands['undoInputRule'];

@@ -1,5 +0,12 @@

import { Command } from '../types';
/**
* Remove all marks in the current selection.
*/
export declare const unsetAllMarks: () => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
unsetAllMarks: {
/**
* Remove all marks in the current selection.
*/
unsetAllMarks: () => Command;
};
}
}
export declare const unsetAllMarks: RawCommands['unsetAllMarks'];
import { MarkType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Remove all marks in the current selection.
*/
export declare const unsetMark: (typeOrName: string | MarkType) => Command;
import { Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
unsetMark: {
/**
* Remove all marks in the current selection.
*/
unsetMark: (typeOrName: string | MarkType) => Command;
};
}
}
export declare const unsetMark: RawCommands['unsetMark'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Update attributes of a node.
*/
export declare const updateNodeAttributes: (typeOrName: string | NodeType, attributes: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
updateNodeAttributes: {
/**
* Update attributes of a node.
*/
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command;
};
}
}
export declare const updateNodeAttributes: RawCommands['updateNodeAttributes'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Wraps nodes in another node.
*/
export declare const wrapIn: (typeOrName: string | NodeType, attributes?: {}) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
wrapIn: {
/**
* Wraps nodes in another node.
*/
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const wrapIn: RawCommands['wrapIn'];
import { NodeType } from 'prosemirror-model';
import { Command } from '../types';
/**
* Wrap a node in a list.
*/
export declare const wrapInList: (typeOrName: string | NodeType, attrs?: {} | undefined) => Command;
import { AnyObject, Command, RawCommands } from '../types';
declare module '@tiptap/core' {
interface Commands {
wrapInList: {
/**
* Wrap a node in a list.
*/
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command;
};
}
}
export declare const wrapInList: RawCommands['wrapInList'];

@@ -1,2 +0,2 @@

import { EditorState, Plugin } from 'prosemirror-state';
import { EditorState, Plugin, Transaction } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';

@@ -6,3 +6,3 @@ import { Schema, Node } from 'prosemirror-model';

import EventEmitter from './EventEmitter';
import { EditorOptions, EditorContent, CommandSpec, CanCommands, ChainedCommands, SingleCommands, AnyObject } from './types';
import { EditorOptions, EditorContent, CanCommands, ChainedCommands, SingleCommands, AnyObject } from './types';
import * as extensions from './extensions';

@@ -14,3 +14,2 @@ export { extensions };

export declare class Editor extends EventEmitter {
private proxy;
private commandManager;

@@ -25,12 +24,2 @@ extensionManager: ExtensionManager;

/**
* This method is called after the proxy is initialized.
*/
private init;
/**
* A magic method to call commands.
*
* @param name The name of the command
*/
private __get;
/**
* An object of all registered commands.

@@ -66,17 +55,2 @@ */

/**
* Register a list of commands.
*
* @param commands A list of commands
*/
registerCommands(commands: {
[key: string]: CommandSpec;
}): void;
/**
* Register a command.
*
* @param name The name of your command
* @param callback The method of your command
*/
registerCommand(name: string, callback: CommandSpec): Editor;
/**
* Register a ProseMirror plugin.

@@ -118,2 +92,5 @@ *

createDocument: (content: EditorContent, parseOptions?: import("prosemirror-model").ParseOptions<any>) => Node;
isCapturingTransaction: boolean;
private capturedTransaction;
captureTransaction(fn: Function): Transaction<any> | null;
/**

@@ -120,0 +97,0 @@ * The callback over which to send transactions (state updates) produced by the view.

import { Plugin, Transaction } from 'prosemirror-state';
import { InputRule } from 'prosemirror-inputrules';
import { Editor } from './Editor';
import { GlobalAttributes } from './types';
export interface ExtensionConfig<Options = any, Commands = {}> {
import { GlobalAttributes, RawCommands } from './types';
export interface ExtensionConfig<Options = any> {
/**

@@ -21,3 +21,3 @@ * Name

/**
* Commands
* Raw
*/

@@ -27,3 +27,3 @@ addCommands?: (this: {

editor: Editor;
}) => Commands;
}) => Partial<RawCommands>;
/**

@@ -115,3 +115,3 @@ * Keyboard shortcuts

}
export declare class Extension<Options = any, Commands = any> {
export declare class Extension<Options = any> {
#private;

@@ -121,6 +121,6 @@ type: string;

options: Options;
constructor(config: ExtensionConfig<Options, Commands>);
static create<O, C>(config: ExtensionConfig<O, C>): Extension<O, C>;
configure(options?: Partial<Options>): Extension<Options, Commands>;
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedCommands>>): Extension<ExtendedOptions, ExtendedCommands>;
constructor(config: ExtensionConfig<Options>);
static create<O>(config: ExtensionConfig<O>): Extension<O>;
configure(options?: Partial<Options>): Extension<Options>;
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>>): Extension<ExtendedOptions>;
}

@@ -5,3 +5,3 @@ import { Schema, Node as ProsemirrorNode } from 'prosemirror-model';

import { Editor } from './Editor';
import { Extensions } from './types';
import { Extensions, RawCommands } from './types';
export default class ExtensionManager {

@@ -12,2 +12,3 @@ editor: Editor;

constructor(extensions: Extensions, editor: Editor);
get commands(): RawCommands;
get plugins(): Plugin[];

@@ -14,0 +15,0 @@ get attributes(): import("./types").ExtensionAttribute[];

import { Extension } from '../Extension';
export declare const ClipboardTextSerializer: Extension<unknown, unknown>;
declare module '@tiptap/core' {
interface AllExtensions {
ClipboardTextSerializer: typeof ClipboardTextSerializer;
}
}
export declare const ClipboardTextSerializer: Extension<unknown>;
import { Extension } from '../Extension';
import * as splitBlock from '../commands/splitBlock';
export declare const Commands: Extension<unknown, {
wrapInList: (typeOrName: string | import("prosemirror-model").NodeType<any>, attrs?: {} | undefined) => import("@tiptap/core").Command;
wrapIn: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes?: {}) => import("@tiptap/core").Command;
updateNodeAttributes: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes: {}) => import("@tiptap/core").Command;
unsetMark: (typeOrName: string | import("prosemirror-model").MarkType<any>) => import("@tiptap/core").Command;
unsetAllMarks: () => import("@tiptap/core").Command;
undoInputRule: () => import("@tiptap/core").Command;
toggleWrap: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes?: {}) => import("@tiptap/core").Command;
toggleNode: (typeOrName: string | import("prosemirror-model").NodeType<any>, toggleTypeOrName: string | import("prosemirror-model").NodeType<any>, attrs?: {}) => import("@tiptap/core").Command;
toggleMark: (typeOrName: string | import("prosemirror-model").MarkType<any>, attributes?: {} | undefined) => import("@tiptap/core").Command;
toggleList: (listTypeOrName: string | import("prosemirror-model").NodeType<any>, itemTypeOrName: string | import("prosemirror-model").NodeType<any>) => import("@tiptap/core").Command;
splitListItem: (typeOrName: string | import("prosemirror-model").NodeType<any>) => import("@tiptap/core").Command;
splitBlock: (options?: Partial<splitBlock.SplitBlockOptions>) => import("@tiptap/core").Command;
sinkListItem: (typeOrName: string | import("prosemirror-model").NodeType<any>) => import("@tiptap/core").Command;
setNode: (typeOrName: string | import("prosemirror-model").NodeType<any>, attrs?: {}) => import("@tiptap/core").Command;
setMark: (typeOrName: string | import("prosemirror-model").MarkType<any>, attributes?: {} | undefined) => import("@tiptap/core").Command;
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: {}) => import("@tiptap/core").Command;
selectParentNode: () => import("@tiptap/core").Command;
selectNodeForward: () => import("@tiptap/core").Command;
selectNodeBackward: () => import("@tiptap/core").Command;
selectAll: () => import("@tiptap/core").Command;
scrollIntoView: () => import("@tiptap/core").Command;
resetNodeAttributes: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes: string | string[]) => import("@tiptap/core").Command;
replaceRange: (range: import("@tiptap/core").Range, typeOrName: string | import("prosemirror-model").NodeType<any>, attributes?: import("@tiptap/core").AnyObject) => import("@tiptap/core").Command;
replace: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes?: import("@tiptap/core").AnyObject) => import("@tiptap/core").Command;
newlineInCode: () => import("@tiptap/core").Command;
liftListItem: (typeOrName: string | import("prosemirror-model").NodeType<any>) => import("@tiptap/core").Command;
liftEmptyBlock: () => import("@tiptap/core").Command;
lift: (typeOrName: string | import("prosemirror-model").NodeType<any>, attributes?: {}) => import("@tiptap/core").Command;
joinForward: () => import("@tiptap/core").Command;
joinBackward: () => import("@tiptap/core").Command;
insertText: (value: string) => import("@tiptap/core").Command;
insertHTML: (value: string) => import("@tiptap/core").Command;
focus: (position?: import("@tiptap/core").FocusPosition) => import("@tiptap/core").Command;
first: (commands: import("@tiptap/core").Command[] | ((props: import("@tiptap/core").CommandProps) => import("@tiptap/core").Command[])) => import("@tiptap/core").Command;
extendMarkRange: (typeOrName: string | import("prosemirror-model").MarkType<any>) => import("@tiptap/core").Command;
exitCode: () => import("@tiptap/core").Command;
deleteSelection: () => import("@tiptap/core").Command;
deleteRange: (range: import("@tiptap/core").Range) => import("@tiptap/core").Command;
createParagraphNear: () => import("@tiptap/core").Command;
command: (fn: (props: import("@tiptap/core").CommandProps) => boolean) => import("@tiptap/core").Command;
clearNodes: () => import("@tiptap/core").Command;
clearContent: (emitUpdate?: Boolean) => import("@tiptap/core").Command;
blur: () => import("@tiptap/core").Command;
}>;
declare module '@tiptap/core' {
interface AllExtensions {
Commands: typeof Commands;
}
}
export declare const Commands: Extension<unknown>;
import { Extension } from '../Extension';
export declare const Editable: Extension<unknown, unknown>;
declare module '@tiptap/core' {
interface AllExtensions {
Editable: typeof Editable;
}
}
export declare const Editable: Extension<unknown>;
import { Extension } from '../Extension';
export declare const FocusEvents: Extension<unknown, unknown>;
declare module '@tiptap/core' {
interface AllExtensions {
FocusEvents: typeof FocusEvents;
}
}
export declare const FocusEvents: Extension<unknown>;
import { Extension } from '../Extension';
export declare const Keymap: Extension<unknown, unknown>;
declare module '@tiptap/core' {
interface AllExtensions {
Keymap: typeof Keymap;
}
}
export declare const Keymap: Extension<unknown>;

@@ -6,5 +6,5 @@ import { Extensions } from '../types';

export default function splitExtensions(extensions: Extensions): {
baseExtensions: Extension<any, any>[];
nodeExtensions: Node<any, {}>[];
markExtensions: Mark<any, {}>[];
baseExtensions: Extension<any>[];
nodeExtensions: Node<any>[];
markExtensions: Mark<any>[];
};

@@ -21,3 +21,3 @@ export * from './Editor';

export { default as findParentNodeClosestToPos } from './helpers/findParentNodeClosestToPos';
export interface AllExtensions {
export interface Commands {
}

@@ -5,5 +5,5 @@ import { DOMOutputSpec, MarkSpec, Mark as ProseMirrorMark, MarkType } from 'prosemirror-model';

import { ExtensionConfig } from './Extension';
import { Attributes, Overwrite } from './types';
import { Attributes, Overwrite, RawCommands } from './types';
import { Editor } from './Editor';
export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
export interface MarkConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
/**

@@ -63,3 +63,3 @@ * Inclusive

type: MarkType;
}) => Commands;
}) => Partial<RawCommands>;
/**

@@ -163,3 +163,3 @@ * Keyboard shortcuts

}
export declare class Mark<Options = any, Commands = {}> {
export declare class Mark<Options = any> {
#private;

@@ -169,6 +169,6 @@ type: string;

options: Options;
constructor(config: MarkConfig<Options, Commands>);
static create<O, C>(config: MarkConfig<O, C>): Mark<O, C>;
configure(options?: Partial<Options>): Mark<Options, Commands>;
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedCommands>>): Mark<ExtendedOptions, ExtendedCommands>;
constructor(config: MarkConfig<Options>);
static create<O>(config: MarkConfig<O>): Mark<O>;
configure(options?: Partial<Options>): Mark<Options>;
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>>): Mark<ExtendedOptions>;
}

@@ -5,5 +5,5 @@ import { DOMOutputSpec, NodeSpec, Node as ProseMirrorNode, NodeType } from 'prosemirror-model';

import { ExtensionConfig } from './Extension';
import { Attributes, NodeViewRenderer, Overwrite } from './types';
import { Attributes, NodeViewRenderer, Overwrite, RawCommands } from './types';
import { Editor } from './Editor';
export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
/**

@@ -119,3 +119,3 @@ * TopNode

type: NodeType;
}) => Commands;
}) => Partial<RawCommands>;
/**

@@ -129,3 +129,3 @@ * Keyboard shortcuts

}) => {
[key: string]: any;
[key: string]: () => boolean;
};

@@ -228,3 +228,3 @@ /**

}
export declare class Node<Options = any, Commands = {}> {
export declare class Node<Options = any> {
#private;

@@ -234,6 +234,6 @@ type: string;

options: Options;
constructor(config: NodeConfig<Options, Commands>);
static create<O, C>(config: NodeConfig<O, C>): Node<O, C>;
configure(options?: Partial<Options>): Node<Options, Commands>;
extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedCommands>>): Node<ExtendedOptions, ExtendedCommands>;
constructor(config: NodeConfig<Options>);
static create<O>(config: NodeConfig<O>): Node<O>;
configure(options?: Partial<Options>): Node<Options>;
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>): Node<ExtendedOptions>;
}

@@ -8,3 +8,4 @@ import { Node as ProseMirrorNode, Mark as ProseMirrorMark, ParseOptions } from 'prosemirror-model';

import { Editor } from './Editor';
import { AllExtensions } from '.';
import { Commands } from '.';
export { Commands };
export declare type Extensions = (Extension | Node | Mark)[];

@@ -89,2 +90,6 @@ export interface EditorOptions {

};
export declare type ValuesOf<T> = T[keyof T];
export declare type KeysWithTypeOf<T, Type> = ({
[P in keyof T]: T[P] extends Type ? P : never;
})[keyof T];
export declare type NodeViewRendererProps = {

@@ -101,15 +106,11 @@ editor: Editor;

export declare type NodeViewRenderer = (props: NodeViewRendererProps) => (NodeView | {});
export declare type UnfilteredCommands = {
[Item in keyof AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands> ? ExtensionCommands : AllExtensions[Item] extends Node<any, infer NodeCommands> ? NodeCommands : AllExtensions[Item] extends Mark<any, infer MarkCommands> ? MarkCommands : never;
export declare type UnionCommands = UnionToIntersection<ValuesOf<Pick<Commands, KeysWithTypeOf<Commands, {}>>>>;
export declare type RawCommands = {
[Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any ? (...args: Parameters<UnionCommands[Item]>) => Command : never;
};
export declare type ValuesOf<T> = T[keyof T];
export declare type KeysWithTypeOf<T, Type> = ({
[P in keyof T]: T[P] extends Type ? P : never;
})[keyof T];
export declare type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>;
export declare type SingleCommands = {
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any ? (...args: Parameters<AllCommands[Item]>) => boolean : never;
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any ? (...args: Parameters<RawCommands[Item]>) => boolean : never;
};
export declare type ChainedCommands = {
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any ? (...args: Parameters<AllCommands[Item]>) => ChainedCommands : never;
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any ? (...args: Parameters<RawCommands[Item]>) => ChainedCommands : never;
} & {

@@ -116,0 +117,0 @@ run: () => boolean;

{
"name": "@tiptap/core",
"description": "headless rich text editor",
"version": "2.0.0-alpha.16",
"version": "2.0.0-alpha.17",
"homepage": "https://tiptap.dev",

@@ -30,3 +30,3 @@ "keywords": [

"@types/prosemirror-keymap": "^1.0.4",
"@types/prosemirror-model": "^1.11.2",
"@types/prosemirror-model": "^1.11.3",
"@types/prosemirror-schema-list": "^1.0.2",

@@ -37,3 +37,3 @@ "@types/prosemirror-state": "^1.2.6",

"@types/prosemirror-view": "^1.17.1",
"prosemirror-commands": "^1.1.3",
"prosemirror-commands": "^1.1.6",
"prosemirror-inputrules": "^1.1.3",

@@ -45,6 +45,6 @@ "prosemirror-keymap": "^1.1.3",

"prosemirror-tables": "^1.1.1",
"prosemirror-transform": "^1.2.10",
"prosemirror-view": "^1.17.5"
"prosemirror-transform": "^1.2.11",
"prosemirror-view": "^1.17.6"
},
"gitHead": "6bdeb4615c7b6afba4a2fcac4e3c35d7a7c0030a"
"gitHead": "71d8fbbcb1eacd664bb6992e0086a589e4684e69"
}

@@ -7,6 +7,5 @@ import { EditorState, Transaction } from 'prosemirror-state'

CanCommands,
CommandSpec,
RawCommands,
CommandProps,
} from './types'
import getAllMethodNames from './utilities/getAllMethodNames'

@@ -17,31 +16,9 @@ export default class CommandManager {

commands: { [key: string]: any } = {}
commands: RawCommands
methodNames: string[] = []
constructor(editor: Editor) {
constructor(editor: Editor, commands: RawCommands) {
this.editor = editor
this.methodNames = getAllMethodNames(this.editor)
this.commands = commands
}
/**
* Register a command.
*
* @param name The name of your command
* @param callback The method of your command
*/
public registerCommand(name: string, callback: CommandSpec): Editor {
if (this.commands[name]) {
throw new Error(`tiptap: command '${name}' is already defined.`)
}
if (this.methodNames.includes(name)) {
throw new Error(`tiptap: '${name}' is a protected name.`)
}
this.commands[name] = callback
return this.editor
}
public createCommands(): SingleCommands {

@@ -77,19 +54,13 @@ const { commands, editor } = this

return new Proxy({}, {
get: (_, name: string, proxy) => {
if (name === 'run') {
if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch')) {
view.dispatch(tr)
}
const run = () => {
if (!hasStartTransaction && shouldDispatch && !tr.getMeta('preventDispatch')) {
view.dispatch(tr)
}
return () => callbacks.every(callback => callback === true)
}
return () => callbacks.every(callback => callback === true)
}
const command = commands[name]
if (!command) {
throw new Error(`tiptap: command '${name}' not found.`)
}
return (...args: any) => {
const chain = {
...Object.fromEntries(Object.entries(commands).map(([name, command]) => {
const chainedCommand = (...args: any[]) => {
const props = this.buildProps(tr, shouldDispatch)

@@ -100,6 +71,11 @@ const callback = command(...args)(props)

return proxy
return chain
}
},
}) as ChainedCommands
return [name, chainedCommand]
})),
run,
} as unknown as ChainedCommands
return chain
}

@@ -110,3 +86,3 @@

const { state } = editor
const dispatch = false
const dispatch = undefined
const tr = startTr || state.tr

@@ -134,3 +110,3 @@ const props = this.buildProps(tr, dispatch)

const props = {
const props: CommandProps = {
tr,

@@ -137,0 +113,0 @@ editor,

@@ -1,7 +0,15 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Removes focus from the editor.
*/
export const blur = (): Command => ({ view }) => {
declare module '@tiptap/core' {
interface Commands {
blur: {
/**
* Removes focus from the editor.
*/
blur: () => Command,
}
}
}
export const blur: RawCommands['blur'] = () => ({ view }) => {
const element = view.dom as HTMLElement

@@ -8,0 +16,0 @@

@@ -1,8 +0,16 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Clear the whole document.
*/
export const clearContent = (emitUpdate: Boolean = false): Command => ({ commands }) => {
declare module '@tiptap/core' {
interface Commands {
clearContent: {
/**
* Clear the whole document.
*/
clearContent: (emitUpdate: Boolean) => Command,
}
}
}
export const clearContent: RawCommands['clearContent'] = (emitUpdate = false) => ({ commands }) => {
return commands.setContent('', emitUpdate)
}
import { liftTarget } from 'prosemirror-transform'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Normalize nodes to a simple paragraph.
*/
export const clearNodes = (): Command => ({ state, tr, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
clearNodes: {
/**
* Normalize nodes to a simple paragraph.
*/
clearNodes: () => Command,
}
}
}
export const clearNodes: RawCommands['clearNodes'] = () => ({ state, tr, dispatch }) => {
const { selection } = tr

@@ -9,0 +17,0 @@ const { from, to } = selection

@@ -1,8 +0,16 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Define a command inline.
*/
export const command = (fn: (props: Parameters<Command>[0]) => boolean): Command => props => {
declare module '@tiptap/core' {
interface Commands {
command: {
/**
* Define a command inline.
*/
command: (fn: (props: Parameters<Command>[0]) => boolean) => Command,
}
}
}
export const command: RawCommands['command'] = fn => props => {
return fn(props)
}
import { createParagraphNear as originalCreateParagraphNear } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Create a paragraph nearby.
*/
export const createParagraphNear = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
createParagraphNear: {
/**
* Create a paragraph nearby.
*/
createParagraphNear: () => Command,
}
}
}
export const createParagraphNear: RawCommands['createParagraphNear'] = () => ({ state, dispatch }) => {
return originalCreateParagraphNear(state, dispatch)
}

@@ -1,7 +0,15 @@

import { Command, Range } from '../types'
import { Command, RawCommands, Range } from '../types'
/**
* Delete a given range.
*/
export const deleteRange = (range: Range): Command => ({ tr, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
deleteRange: {
/**
* Delete a given range.
*/
deleteRange: (range: Range) => Command,
}
}
}
export const deleteRange: RawCommands['deleteRange'] = range => ({ tr, dispatch }) => {
const { from, to } = range

@@ -8,0 +16,0 @@

import { deleteSelection as originalDeleteSelection } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Delete the selection, if there is one.
*/
export const deleteSelection = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
deleteSelection: {
/**
* Delete the selection, if there is one.
*/
deleteSelection: () => Command,
}
}
}
export const deleteSelection: RawCommands['deleteSelection'] = () => ({ state, dispatch }) => {
return originalDeleteSelection(state, dispatch)
}
import { exitCode as originalExitCode } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Exit from a code block.
*/
export const exitCode = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
exitCode: {
/**
* Exit from a code block.
*/
exitCode: () => Command,
}
}
}
export const exitCode: RawCommands['exitCode'] = () => ({ state, dispatch }) => {
return originalExitCode(state, dispatch)
}
import { TextSelection } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
extendMarkRange: {
/**
* Extends the text selection to the current mark.
*/
extendMarkRange: (typeOrName: string | MarkType) => Command,
}
}
}
export const extendMarkRange: RawCommands['extendMarkRange'] = typeOrName => ({ tr, state, dispatch }) => {
const type = getMarkType(typeOrName, state.schema)

@@ -12,0 +20,0 @@ const { doc, selection } = tr

@@ -1,7 +0,15 @@

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

@@ -8,0 +16,0 @@ ? commands(props)

import { EditorState, TextSelection } from 'prosemirror-state'
import { Command, FocusPosition } from '../types'
import { Command, RawCommands, FocusPosition } from '../types'
import minMax from '../utilities/minMax'

@@ -33,6 +33,14 @@ import isTextSelection from '../helpers/isTextSelection'

/**
* Focus the editor at the given position.
*/
export const focus = (position: FocusPosition = null): Command => ({
declare module '@tiptap/core' {
interface Commands {
focus: {
/**
* Focus the editor at the given position.
*/
focus: (position?: FocusPosition) => Command,
}
}
}
export const focus: RawCommands['focus'] = (position = null) => ({
editor,

@@ -39,0 +47,0 @@ view,

@@ -5,3 +5,3 @@ import { DOMParser } from 'prosemirror-model'

import elementFromString from '../utilities/elementFromString'
import { Command } from '../types'
import { Command, RawCommands } from '../types'

@@ -21,6 +21,14 @@ // TODO: move to utils

/**
* Insert a string of HTML at the current position.
*/
export const insertHTML = (value: string): Command => ({ tr, state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
insertHTML: {
/**
* Insert a string of HTML at the current position.
*/
insertHTML: (value: string) => Command,
}
}
}
export const insertHTML: RawCommands['insertHTML'] = value => ({ tr, state, dispatch }) => {
const { selection } = tr

@@ -27,0 +35,0 @@ const element = elementFromString(value)

@@ -1,7 +0,15 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Insert a string of text at the current position.
*/
export const insertText = (value: string): Command => ({ tr, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
insertText: {
/**
* Insert a string of text at the current position.
*/
insertText: (value: string) => Command,
}
}
}
export const insertText: RawCommands['insertText'] = value => ({ tr, dispatch }) => {
if (dispatch) {

@@ -8,0 +16,0 @@ tr.insertText(value)

import { joinBackward as originalJoinBackward } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Join two nodes backward.
*/
export const joinBackward = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
joinBackward: {
/**
* Join two nodes backward.
*/
joinBackward: () => Command,
}
}
}
export const joinBackward: RawCommands['joinBackward'] = () => ({ state, dispatch }) => {
return originalJoinBackward(state, dispatch)
}
import { joinForward as originalJoinForward } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Join two nodes forward.
*/
export const joinForward = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
joinForward: {
/**
* Join two nodes forward.
*/
joinForward: () => Command,
}
}
}
export const joinForward: RawCommands['joinForward'] = () => ({ state, dispatch }) => {
return originalJoinForward(state, dispatch)
}
import { lift as originalLift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands, 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 }) => {
declare module '@tiptap/core' {
interface Commands {
lift: {
/**
* Removes an existing wrap.
*/
lift: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const lift: RawCommands['lift'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -12,0 +20,0 @@ const isActive = isNodeActive(state, type, attributes)

import { liftEmptyBlock as originalLiftEmptyBlock } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Lift block if empty.
*/
export const liftEmptyBlock = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
liftEmptyBlock: {
/**
* Lift block if empty.
*/
liftEmptyBlock: () => Command,
}
}
}
export const liftEmptyBlock: RawCommands['liftEmptyBlock'] = () => ({ state, dispatch }) => {
return originalLiftEmptyBlock(state, dispatch)
}
import { liftListItem as originalLiftListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
/**
* Lift the list item into a wrapping list.
*/
export const liftListItem = (typeOrName: string | NodeType): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
liftListItem: {
/**
* Lift the list item into a wrapping list.
*/
liftListItem: (typeOrName: string | NodeType) => Command,
}
}
}
export const liftListItem: RawCommands['liftListItem'] = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -11,0 +19,0 @@

import { newlineInCode as originalNewlineInCode } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Add a newline character in code.
*/
export const newlineInCode = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
newlineInCode: {
/**
* Add a newline character in code.
*/
newlineInCode: () => Command,
}
}
}
export const newlineInCode: RawCommands['newlineInCode'] = () => ({ state, dispatch }) => {
return originalNewlineInCode(state, dispatch)
}
import { NodeType } from 'prosemirror-model'
import { Command, AnyObject } from '../types'
import { Command, RawCommands, AnyObject } from '../types'
/**
* Replaces text with a node.
*/
export const replace = (typeOrName: string | NodeType, attributes: AnyObject = {}): Command => ({ state, commands }) => {
declare module '@tiptap/core' {
interface Commands {
replace: {
/**
* Replaces text with a node.
*/
replace: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const replace: RawCommands['replace'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
const { from, to } = state.selection

@@ -9,0 +17,0 @@ const range = { from, to }

import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType'
import { Command, Range, AnyObject } from '../types'
import {
Command,
RawCommands,
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 }) => {
declare module '@tiptap/core' {
interface Commands {
replaceRange: {
/**
* Replaces text with a node within a range.
*/
replaceRange: (range: Range, typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const replaceRange: RawCommands['replaceRange'] = (range, typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -10,0 +23,0 @@ const { from, to } = range

import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType'
import deleteProps from '../utilities/deleteProps'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Resets node attributes to the default value.
*/
export const resetNodeAttributes = (typeOrName: string | NodeType, attributes: string | string[]): Command => ({ tr, state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
resetNodeAttributes: {
/**
* Resets node attributes to the default value.
*/
resetNodeAttributes: (typeOrName: string | NodeType, attributes: string | string[]) => Command,
}
}
}
export const resetNodeAttributes: RawCommands['resetNodeAttributes'] = (typeOrName, attributes) => ({ tr, state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -11,0 +19,0 @@ const { selection } = tr

@@ -1,7 +0,15 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Scroll the selection into view.
*/
export const scrollIntoView = (): Command => ({ tr, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
scrollIntoView: {
/**
* Scroll the selection into view.
*/
scrollIntoView: () => Command,
}
}
}
export const scrollIntoView: RawCommands['scrollIntoView'] = () => ({ tr, dispatch }) => {
if (dispatch) {

@@ -8,0 +16,0 @@ tr.scrollIntoView()

import { selectAll as originalSelectAll } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Select the whole document.
*/
export const selectAll = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
selectAll: {
/**
* Select the whole document.
*/
selectAll: () => Command,
}
}
}
export const selectAll: RawCommands['selectAll'] = () => ({ state, dispatch }) => {
return originalSelectAll(state, dispatch)
}
import { selectNodeBackward as originalSelectNodeBackward } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Select a node backward.
*/
export const selectNodeBackward = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
selectNodeBackward: {
/**
* Select a node backward.
*/
selectNodeBackward: () => Command,
}
}
}
export const selectNodeBackward: RawCommands['selectNodeBackward'] = () => ({ state, dispatch }) => {
return originalSelectNodeBackward(state, dispatch)
}
import { selectNodeForward as originalSelectNodeForward } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Select a node forward.
*/
export const selectNodeForward = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
selectNodeForward: {
/**
* Select a node forward.
*/
selectNodeForward: () => Command,
}
}
}
export const selectNodeForward: RawCommands['selectNodeForward'] = () => ({ state, dispatch }) => {
return originalSelectNodeForward(state, dispatch)
}
import { selectParentNode as originalSelectParentNode } from 'prosemirror-commands'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Select the parent node.
*/
export const selectParentNode = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
selectParentNode: {
/**
* Select the parent node.
*/
selectParentNode: () => Command,
}
}
}
export const selectParentNode: RawCommands['selectParentNode'] = () => ({ state, dispatch }) => {
return originalSelectParentNode(state, dispatch)
}
import { TextSelection } from 'prosemirror-state'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } from '../types'
/**
* Replace the whole document with new content.
*/
export const setContent = (content: string, emitUpdate: Boolean = false, parseOptions = {}): Command => ({ tr, editor, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
setContent: {
/**
* Replace the whole document with new content.
*/
setContent: (content: string, emitUpdate?: Boolean, parseOptions?: AnyObject) => Command,
}
}
}
export const setContent: RawCommands['setContent'] = (content, emitUpdate = false, parseOptions = {}) => ({ tr, editor, dispatch }) => {
const { createDocument } = editor

@@ -9,0 +17,0 @@ const { doc } = tr

import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
setMark: {
/**
* Add a mark with new attributes.
*/
setMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
}
}
}
export const setMark: RawCommands['setMark'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
const { selection } = tr

@@ -11,0 +19,0 @@ const { from, to, empty } = selection

import { NodeType } from 'prosemirror-model'
import { setBlockType } from 'prosemirror-commands'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
/**
* Replace a given range with a node.
*/
export const setNode = (typeOrName: string | NodeType, attrs = {}): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
setNode: {
/**
* Replace a given range with a node.
*/
setNode: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const setNode: RawCommands['setNode'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
return setBlockType(type, attrs)(state, dispatch)
return setBlockType(type, attributes)(state, dispatch)
}
import { sinkListItem as originalSinkListItem } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
sinkListItem: {
/**
* Sink the list item down into an inner list.
*/
sinkListItem: (typeOrName: string | NodeType) => Command,
}
}
}
export const sinkListItem: RawCommands['sinkListItem'] = typeOrName => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -11,0 +19,0 @@

import { canSplit } from 'prosemirror-transform'
import { ContentMatch, Fragment } from 'prosemirror-model'
import { EditorState, NodeSelection, TextSelection } from 'prosemirror-state'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
import getSplittedAttributes from '../helpers/getSplittedAttributes'

@@ -18,7 +18,3 @@

export interface SplitBlockOptions {
keepMarks: boolean,
}
function keepMarks(state: EditorState) {
function ensureMarks(state: EditorState) {
const marks = state.storedMarks

@@ -32,6 +28,14 @@ || (state.selection.$to.parentOffset && state.selection.$from.marks())

/**
* Forks a new node from an existing node.
*/
export const splitBlock = (options: Partial<SplitBlockOptions> = {}): Command => ({
declare module '@tiptap/core' {
interface Commands {
splitBlock: {
/**
* Forks a new node from an existing node.
*/
splitBlock: (options?: { keepMarks?: boolean }) => Command,
}
}
}
export const splitBlock: RawCommands['splitBlock'] = ({ keepMarks = true } = {}) => ({
tr,

@@ -42,6 +46,2 @@ state,

}) => {
const defaultOptions: SplitBlockOptions = {
keepMarks: true,
}
const config = { ...defaultOptions, ...options }
const { selection, doc } = tr

@@ -62,4 +62,4 @@ const { $from, $to } = selection

if (dispatch) {
if (config.keepMarks) {
keepMarks(state)
if (keepMarks) {
ensureMarks(state)
}

@@ -124,4 +124,4 @@

if (config.keepMarks) {
keepMarks(state)
if (keepMarks) {
ensureMarks(state)
}

@@ -128,0 +128,0 @@

@@ -9,10 +9,18 @@ import {

import { TextSelection } from 'prosemirror-state'
import { Command } from '../types'
import { Command, RawCommands } 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 => ({
declare module '@tiptap/core' {
interface Commands {
splitListItem: {
/**
* Splits one list item into two list items.
*/
splitListItem: (typeOrName: string | NodeType) => Command,
}
}
}
export const splitListItem: RawCommands['splitListItem'] = typeOrName => ({
tr, state, dispatch, editor,

@@ -19,0 +27,0 @@ }) => {

import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'

@@ -7,6 +7,14 @@ import findParentNode from '../helpers/findParentNode'

/**
* Toggle between different list types.
*/
export const toggleList = (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType): Command => ({
declare module '@tiptap/core' {
interface Commands {
toggleList: {
/**
* Toggle between different list types.
*/
toggleList: (listTypeOrName: string | NodeType, itemTypeOrName: string | NodeType) => Command,
}
}
}
export const toggleList: RawCommands['toggleList'] = (listTypeOrName, itemTypeOrName) => ({
editor, tr, state, dispatch, chain, commands, can,

@@ -13,0 +21,0 @@ }) => {

import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
toggleMark: {
/**
* Toggle a mark on and off.
*/
toggleMark: (typeOrName: string | MarkType, attributes?: AnyObject) => Command,
}
}
}
export const toggleMark: RawCommands['toggleMark'] = (typeOrName, attributes = {}) => ({ state, commands }) => {
const type = getMarkType(typeOrName, state.schema)

@@ -11,0 +19,0 @@ const isActive = isMarkActive(state, type, attributes)

import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
toggleNode: {
/**
* Toggle a node with another node.
*/
toggleNode: (typeOrName: string | NodeType, toggleTypeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const toggleNode: RawCommands['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)

@@ -18,3 +26,3 @@ if (isActive) {

return commands.setNode(type, attrs)
return commands.setNode(type, attributes)
}
import { wrapIn, lift } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
toggleWrap: {
/**
* Wraps nodes in another node, or removes an existing wrap.
*/
toggleWrap: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const toggleWrap: RawCommands['toggleWrap'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -12,0 +20,0 @@ const isActive = isNodeActive(state, type, attributes)

import { undoInputRule as originalUndoInputRule } from 'prosemirror-inputrules'
import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Undo an input rule.
*/
export const undoInputRule = (): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
undoInputRule: {
/**
* Undo an input rule.
*/
undoInputRule: () => Command,
}
}
}
export const undoInputRule: RawCommands['undoInputRule'] = () => ({ state, dispatch }) => {
return originalUndoInputRule(state, dispatch)
}

@@ -1,7 +0,15 @@

import { Command } from '../types'
import { Command, RawCommands } from '../types'
/**
* Remove all marks in the current selection.
*/
export const unsetAllMarks = (): Command => ({ tr, state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
unsetAllMarks: {
/**
* Remove all marks in the current selection.
*/
unsetAllMarks: () => Command,
}
}
}
export const unsetAllMarks: RawCommands['unsetAllMarks'] = () => ({ tr, state, dispatch }) => {
const { selection } = tr

@@ -8,0 +16,0 @@ const { from, to, empty } = selection

import { MarkType } from 'prosemirror-model'
import { Command } from '../types'
import { Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
unsetMark: {
/**
* Remove all marks in the current selection.
*/
unsetMark: (typeOrName: string | MarkType) => Command,
}
}
}
export const unsetMark: RawCommands['unsetMark'] = typeOrName => ({ tr, state, dispatch }) => {
const { selection } = tr

@@ -11,0 +19,0 @@ const type = getMarkType(typeOrName, state.schema)

import { NodeType } from 'prosemirror-model'
import getNodeType from '../helpers/getNodeType'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } from '../types'
/**
* Update attributes of a node.
*/
export const updateNodeAttributes = (typeOrName: string | NodeType, attributes: {}): Command => ({ tr, state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
updateNodeAttributes: {
/**
* Update attributes of a node.
*/
updateNodeAttributes: (typeOrName: string | NodeType, attributes: AnyObject) => Command,
}
}
}
export const updateNodeAttributes: RawCommands['updateNodeAttributes'] = (typeOrName, attributes = {}) => ({ tr, state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -10,0 +18,0 @@ const { selection } = tr

import { wrapIn as originalWrapIn } from 'prosemirror-commands'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } 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 }) => {
declare module '@tiptap/core' {
interface Commands {
wrapIn: {
/**
* Wraps nodes in another node.
*/
wrapIn: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const wrapIn: RawCommands['wrapIn'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)

@@ -12,0 +20,0 @@ const isActive = isNodeActive(state, type, attributes)

import { wrapInList as originalWrapInList } from 'prosemirror-schema-list'
import { NodeType } from 'prosemirror-model'
import { Command } from '../types'
import { AnyObject, Command, RawCommands } from '../types'
import getNodeType from '../helpers/getNodeType'
/**
* Wrap a node in a list.
*/
export const wrapInList = (typeOrName: string | NodeType, attrs?: {}): Command => ({ state, dispatch }) => {
declare module '@tiptap/core' {
interface Commands {
wrapInList: {
/**
* Wrap a node in a list.
*/
wrapInList: (typeOrName: string | NodeType, attributes?: AnyObject) => Command,
}
}
}
export const wrapInList: RawCommands['wrapInList'] = (typeOrName, attributes = {}) => ({ state, dispatch }) => {
const type = getNodeType(typeOrName, state.schema)
return originalWrapInList(type, attrs)(state, dispatch)
return originalWrapInList(type, attributes)(state, dispatch)
}
import { EditorState, Plugin, Transaction } from 'prosemirror-state'
import { EditorView } from 'prosemirror-view'
import { Schema, DOMParser, Node } from 'prosemirror-model'
import magicMethods from './utilities/magicMethods'
import elementFromString from './utilities/elementFromString'

@@ -18,3 +17,2 @@ import getNodeAttributes from './helpers/getNodeAttributes'

EditorContent,
CommandSpec,
CanCommands,

@@ -34,7 +32,4 @@ ChainedCommands,

@magicMethods
export class Editor extends EventEmitter {
private proxy!: Editor
private commandManager!: CommandManager

@@ -75,11 +70,4 @@

this.options = { ...this.options, ...options }
this.on('createdProxy', this.init)
}
/**
* This method is called after the proxy is initialized.
*/
private init(): void {
this.createExtensionManager()
this.createCommandManager()
this.createExtensionManager()
this.createSchema()

@@ -103,12 +91,2 @@ this.createView()

/**
* A magic method to call commands.
*
* @param name The name of the command
*/
// eslint-disable-next-line
private __get(name: string) {
// TODO: maybe remove proxy
}
/**
* An object of all registered commands.

@@ -171,25 +149,2 @@ */

/**
* Register a list of commands.
*
* @param commands A list of commands
*/
public registerCommands(commands: { [key: string]: CommandSpec }): void {
Object
.entries(commands)
.forEach(([name, command]) => this.registerCommand(name, command))
}
/**
* Register a command.
*
* @param name The name of your command
* @param callback The method of your command
*/
public registerCommand(name: string, callback: CommandSpec): Editor {
this.commandManager.registerCommand(name, callback)
return this.proxy
}
/**
* Register a ProseMirror plugin.

@@ -233,3 +188,3 @@ *

this.extensionManager = new ExtensionManager(allExtensions, this.proxy)
this.extensionManager = new ExtensionManager(allExtensions, this)
}

@@ -241,3 +196,3 @@

private createCommandManager(): void {
this.commandManager = new CommandManager(this.proxy)
this.commandManager = new CommandManager(this, this.extensionManager.commands)
}

@@ -277,3 +232,3 @@

const dom = this.view.dom as HTMLElement
dom.editor = this.proxy
dom.editor = this
}

@@ -318,2 +273,18 @@

public isCapturingTransaction = false
private capturedTransaction: Transaction | null = null
public captureTransaction(fn: Function) {
this.isCapturingTransaction = true
fn()
this.isCapturingTransaction = false
const tr = this.capturedTransaction
this.capturedTransaction = null
return tr
}
/**

@@ -325,2 +296,14 @@ * The callback over which to send transactions (state updates) produced by the view.

private dispatchTransaction(transaction: Transaction): void {
if (this.isCapturingTransaction) {
if (!this.capturedTransaction) {
this.capturedTransaction = transaction
return
}
transaction.steps.forEach(step => this.capturedTransaction?.step(step))
return
}
const state = this.state.apply(transaction)

@@ -327,0 +310,0 @@ const selectionHasChanged = !this.state.selection.eq(state.selection)

@@ -5,5 +5,5 @@ import { Plugin, Transaction } from 'prosemirror-state'

import mergeDeep from './utilities/mergeDeep'
import { GlobalAttributes } from './types'
import { GlobalAttributes, RawCommands } from './types'
export interface ExtensionConfig<Options = any, Commands = {}> {
export interface ExtensionConfig<Options = any> {
/**

@@ -27,3 +27,3 @@ * Name

/**
* Commands
* Raw
*/

@@ -33,3 +33,3 @@ addCommands?: (this: {

editor: Editor,
}) => Commands,
}) => Partial<RawCommands>,

@@ -142,3 +142,3 @@ /**

export class Extension<Options = any, Commands = any> {
export class Extension<Options = any> {
type = 'extension'

@@ -166,3 +166,3 @@

constructor(config: ExtensionConfig<Options, Commands>) {
constructor(config: ExtensionConfig<Options>) {
this.config = {

@@ -176,4 +176,4 @@ ...this.config,

static create<O, C>(config: ExtensionConfig<O, C>) {
return new Extension<O, C>(config)
static create<O>(config: ExtensionConfig<O>) {
return new Extension<O>(config)
}

@@ -183,3 +183,3 @@

return Extension
.create<Options, Commands>(this.config as ExtensionConfig<Options, Commands>)
.create<Options>(this.config as ExtensionConfig<Options>)
.#configure(options)

@@ -194,8 +194,8 @@ }

extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions, ExtendedCommands>>) {
return new Extension<ExtendedOptions, ExtendedCommands>({
extend<ExtendedOptions = Options>(extendedConfig: Partial<ExtensionConfig<ExtendedOptions>>) {
return new Extension<ExtendedOptions>({
...this.config,
...extendedConfig,
} as ExtensionConfig<ExtendedOptions, ExtendedCommands>)
} as ExtensionConfig<ExtendedOptions>)
}
}

@@ -7,3 +7,3 @@ import { keymap } from 'prosemirror-keymap'

import { Editor } from './Editor'
import { Extensions, NodeViewRenderer } from './types'
import { Extensions, NodeViewRenderer, RawCommands } from './types'
import getSchema from './helpers/getSchema'

@@ -36,6 +36,2 @@ import getSchemaTypeByName from './helpers/getSchemaTypeByName'

const commands = extension.config.addCommands.bind(context)()
editor.registerCommands(commands)
if (typeof extension.config.onCreate === 'function') {

@@ -71,2 +67,17 @@ this.editor.on('create', extension.config.onCreate.bind(context))

get commands(): RawCommands {
return this.extensions.reduce((extensions, extension) => {
const context = {
options: extension.options,
editor: this.editor,
type: getSchemaTypeByName(extension.config.name, this.schema),
}
return {
...extensions,
...extension.config.addCommands.bind(context)(),
}
}, {} as RawCommands)
}
get plugins(): Plugin[] {

@@ -73,0 +84,0 @@ return [...this.extensions]

@@ -55,7 +55,1 @@ import { Editor } from '@tiptap/core'

})
declare module '@tiptap/core' {
interface AllExtensions {
ClipboardTextSerializer: typeof ClipboardTextSerializer,
}
}

@@ -9,2 +9,3 @@ import { Extension } from '../Extension'

import * as deleteSelection from '../commands/deleteSelection'
import * as enter from '../commands/enter'
import * as exitCode from '../commands/exitCode'

@@ -18,2 +19,3 @@ import * as extendMarkRange from '../commands/extendMarkRange'

import * as joinForward from '../commands/joinForward'
import * as keyboardShortcut from '../commands/keyboardShortcut'
import * as lift from '../commands/lift'

@@ -60,2 +62,3 @@ import * as liftEmptyBlock from '../commands/liftEmptyBlock'

...deleteSelection,
...enter,
...exitCode,

@@ -69,2 +72,3 @@ ...extendMarkRange,

...joinForward,
...keyboardShortcut,
...lift,

@@ -101,7 +105,1 @@ ...liftEmptyBlock,

})
declare module '@tiptap/core' {
interface AllExtensions {
Commands: typeof Commands,
}
}

@@ -18,7 +18,1 @@ import { Plugin, PluginKey } from 'prosemirror-state'

})
declare module '@tiptap/core' {
interface AllExtensions {
Editable: typeof Editable,
}
}

@@ -46,7 +46,1 @@ import { Plugin, PluginKey } from 'prosemirror-state'

})
declare module '@tiptap/core' {
interface AllExtensions {
FocusEvents: typeof FocusEvents,
}
}

@@ -37,7 +37,1 @@ import { Extension } from '../Extension'

})
declare module '@tiptap/core' {
interface AllExtensions {
Keymap: typeof Keymap,
}
}

@@ -24,2 +24,2 @@ export * from './Editor'

export interface AllExtensions {}
export interface Commands {}

@@ -11,6 +11,6 @@ import {

import mergeDeep from './utilities/mergeDeep'
import { Attributes, Overwrite } from './types'
import { Attributes, Overwrite, RawCommands } from './types'
import { Editor } from './Editor'
export interface MarkConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
export interface MarkConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
/**

@@ -74,3 +74,3 @@ * Inclusive

type: MarkType,
}) => Commands,
}) => Partial<RawCommands>,

@@ -194,3 +194,3 @@ /**

export class Mark<Options = any, Commands = {}> {
export class Mark<Options = any> {
type = 'mark'

@@ -225,3 +225,3 @@

constructor(config: MarkConfig<Options, Commands>) {
constructor(config: MarkConfig<Options>) {
this.config = {

@@ -235,4 +235,4 @@ ...this.config,

static create<O, C>(config: MarkConfig<O, C>) {
return new Mark<O, C>(config)
static create<O>(config: MarkConfig<O>) {
return new Mark<O>(config)
}

@@ -242,3 +242,3 @@

return Mark
.create<Options, Commands>(this.config as MarkConfig<Options, Commands>)
.create<Options>(this.config as MarkConfig<Options>)
.#configure(options)

@@ -253,8 +253,8 @@ }

extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<MarkConfig<ExtendedOptions, ExtendedCommands>>) {
return new Mark<ExtendedOptions, ExtendedCommands>({
extend<ExtendedOptions = Options>(extendedConfig: Partial<MarkConfig<ExtendedOptions>>) {
return new Mark<ExtendedOptions>({
...this.config,
...extendedConfig,
} as MarkConfig<ExtendedOptions, ExtendedCommands>)
} as MarkConfig<ExtendedOptions>)
}
}

@@ -12,6 +12,8 @@ // @ts-nocheck

import mergeDeep from './utilities/mergeDeep'
import { Attributes, NodeViewRenderer, Overwrite } from './types'
import {
Attributes, NodeViewRenderer, Overwrite, RawCommands,
} from './types'
import { Editor } from './Editor'
export interface NodeConfig<Options = any, Commands = {}> extends Overwrite<ExtensionConfig<Options, Commands>, {
export interface NodeConfig<Options = any> extends Overwrite<ExtensionConfig<Options>, {
/**

@@ -72,2 +74,3 @@ * TopNode

// TODO: extend via extension-table
/**

@@ -130,3 +133,3 @@ * Table Role

type: NodeType,
}) => Commands,
}) => Partial<RawCommands>,

@@ -141,3 +144,4 @@ /**

}) => {
[key: string]: any
// [key: string]: any
[key: string]: () => boolean
},

@@ -260,3 +264,3 @@

export class Node<Options = any, Commands = {}> {
export class Node<Options = any> {
type = 'node'

@@ -300,3 +304,3 @@

constructor(config: NodeConfig<Options, Commands>) {
constructor(config: NodeConfig<Options>) {
this.config = {

@@ -310,4 +314,4 @@ ...this.config,

static create<O, C>(config: NodeConfig<O, C>) {
return new Node<O, C>(config)
static create<O>(config: NodeConfig<O>) {
return new Node<O>(config)
}

@@ -317,3 +321,3 @@

return Node
.create<Options, Commands>(this.config as NodeConfig<Options, Commands>)
.create<Options>(this.config as NodeConfig<Options>)
.#configure(options)

@@ -328,8 +332,8 @@ }

extend<ExtendedOptions = Options, ExtendedCommands = Commands>(extendedConfig: Partial<NodeConfig<ExtendedOptions, ExtendedCommands>>) {
return new Node<ExtendedOptions, ExtendedCommands>({
extend<ExtendedOptions = Options>(extendedConfig: Partial<NodeConfig<ExtendedOptions>>) {
return new Node<ExtendedOptions>({
...this.config,
...extendedConfig,
} as NodeConfig<ExtendedOptions, ExtendedCommands>)
} as NodeConfig<ExtendedOptions>)
}
}

@@ -17,4 +17,6 @@ import {

import { Editor } from './Editor'
import { AllExtensions } from '.'
import { Commands } from '.'
export { Commands }
export type Extensions = (Extension | Node | Mark)[]

@@ -99,2 +101,6 @@

export type ValuesOf<T> = T[keyof T];
export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
export type NodeViewRendererProps = {

@@ -111,19 +117,13 @@ editor: Editor,

export type UnfilteredCommands = {
[Item in keyof AllExtensions]: AllExtensions[Item] extends Extension<any, infer ExtensionCommands>
? ExtensionCommands
: AllExtensions[Item] extends Node<any, infer NodeCommands>
? NodeCommands
: AllExtensions[Item] extends Mark<any, infer MarkCommands>
? MarkCommands
: never
export type UnionCommands = UnionToIntersection<ValuesOf<Pick<Commands, KeysWithTypeOf<Commands, {}>>>>
export type RawCommands = {
[Item in keyof UnionCommands]: UnionCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<UnionCommands[Item]>) => Command
: never
}
export type ValuesOf<T> = T[keyof T];
export type KeysWithTypeOf<T, Type> = ({[P in keyof T]: T[P] extends Type ? P : never })[keyof T]
export type AllCommands = UnionToIntersection<ValuesOf<Pick<UnfilteredCommands, KeysWithTypeOf<UnfilteredCommands, {}>>>>
export type SingleCommands = {
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<AllCommands[Item]>) => boolean
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<RawCommands[Item]>) => boolean
: never

@@ -133,4 +133,4 @@ }

export type ChainedCommands = {
[Item in keyof AllCommands]: AllCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<AllCommands[Item]>) => ChainedCommands
[Item in keyof RawCommands]: RawCommands[Item] extends (...args: any[]) => any
? (...args: Parameters<RawCommands[Item]>) => ChainedCommands
: never

@@ -137,0 +137,0 @@ } & {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc