import type { AnchorHeadProps, CommandFunction, EditorState, EditorStateProps, InputRule, PosProps, PrimitiveSelection, ProsemirrorCommandFunction, ProsemirrorNode, ProsemirrorPlugin, ResolvedPos, SelectionProps, Shape, TextProps } from '@remirror/core-types'; import { Schema, Slice } from '@remirror/pm/model'; import { Selection } from '@remirror/pm/state'; import { DirectEditorProps, EditorView } from '@remirror/pm/view'; import { EventType } from './jest-prosemirror-events'; import type { TaggedDocProps, TestEditorView, TestEditorViewProps } from './jest-prosemirror-types'; export declare const parseFromClipboard: (view: EditorView, text: string, html: string | null, plainText: boolean, $context: ResolvedPos) => Slice | null; /** * @deprecated You can now use `view.serializeForClipboard()` directly. */ export declare function serializeForClipboard(view: EditorView, slice: Slice): { dom: HTMLElement; text: string; slice: Slice; }; /** * Create a test prosemirror editor an pass back helper properties and methods. * * @remarks * * The call to create editor can be chained with various commands to enable * testing of the editor at each step along it's state without the need for * intermediate holding variables. * * The created editor is automatically cleaned after each test. * * ```ts * import { createEditor } from 'jest-remirror'; * * test('`keyBindings`', () => { * const keyBindings = { * Enter: jest.fn((params: SuggestKeyBindingProps) => { * params.command(); * }), * }; * * const plugin = suggest({char: '@', name: 'at', keyBindings, matchOffset: 0, * createCommand: ({ view }) => () => * view.dispatch(view.state.tr.insertText('awesome')), * }); * * createEditor(doc(p('')), { plugins: [plugin] }) .insertText('@') * .press('Enter') * .callback(content => { * expect(content.state.doc).toEqualProsemirrorNode(doc(p('@awesome'))); * }); * }); * ``` * * @param taggedDoc - the tagged prosemirror node to inject into the editor. * @param options - the {@link CreateEditorOptions} interface which includes all * {@link http://prosemirror.net/docs/ref/#view.DirectEditorProps | DirectEditorProps} * except for `state`. */ export declare function createEditor(taggedDocument: ProsemirrorNode, options?: CreateEditorOptions): ProsemirrorTestChain; /** * Flushes the dom */ export declare function flush(view: TestEditorView): void; /** * A paste implementation for jsdom and prosemirror. * * @remark * * It accepts an object with the `html` and `text` properties. The `text` * property is used to set the `text/plain` clipboard data. The `html` property * is used to set the `text/html` clipboard data. It also accepts an option * `plainText` property which is used to simulate a plain text paste (e.g. press * `Ctrl-Shift-V` or `Command-Shift-V`). * * @internal */ export declare function pasteContent(props: { view: EditorView; content: ProsemirrorNode | string | { text: string; html: string; plainText?: boolean; }; }): void; /** * A copy implementation for jsdom and prosemirror. * * @remark * * This function will return the copied content of selected content as an object * with the `html` and `text` properties. The `text` property is the * `text/plain` clipboard data. The `html` property is the `text/html` clipboard * data. * * @internal */ export declare function copyContent(props: { view: EditorView; }): { html: string; text: string; }; export interface InsertTextProps extends TestEditorViewProps, TextProps { /** * The start point of text insertion */ start: number; } /** * Insert text from the provided index. Each key is entered individually to * better simulate calls to handleTextInput. */ export declare function insertText(props: InsertTextProps): void; interface DispatchTextSelectionProps extends TestEditorViewProps { /** * This defaults to the anchor. */ start: number; end?: number; } /** * Dispatch a text selection from start to [end] */ export declare function dispatchTextSelection(props: DispatchTextSelectionProps): void; interface DispatchAnchorTextSelectionProps extends TestEditorViewProps, AnchorHeadProps { } /** * Dispatch a text selection from start to [end] */ export declare function dispatchAnchorTextSelection(props: DispatchAnchorTextSelectionProps): void; /** * Select everything in the current doc. */ export declare function dispatchAllSelection(view: TestEditorView): void; interface DispatchNodeSelectionProps extends TestEditorViewProps, PosProps { } /** * Dispatch a text selection from the provided pos. */ export declare function dispatchNodeSelection(props: DispatchNodeSelectionProps): void; export declare function dispatchCellSelection(props: DispatchNodeSelectionProps): void; interface PressProps extends TestEditorViewProps { /** * The keyboard shortcut to run */ char: string; } /** * Press a key. */ export declare function press(props: PressProps): void; interface BackspaceProps extends TestEditorViewProps { /** * The number of times to activate backspace. * * @defaultValue 1 */ times?: number; } /** * Simulate a backspace key press. */ export declare function backspace(props: BackspaceProps): void; /** * Simulate a backspace key press. */ export declare function forwardDelete(props: BackspaceProps): void; interface KeyboardShortcutProps extends TestEditorViewProps { /** * The keyboard shortcut to run */ shortcut: string; } /** * Runs a keyboard shortcut. */ export declare function shortcut(props: KeyboardShortcutProps): void; export interface FireProps { /** * The event to fire on the view */ event: EventType; /** * Options passed into the event */ options?: Shape; /** * Override the default position to use */ position?: number; } interface FireEventAtPositionProps extends TestEditorViewProps, FireProps { } /** * Fires an event at the provided position or the current selected position in * the dom. */ export declare function fireEventAtPosition(props: FireEventAtPositionProps): void; /** * The return type for the apply method which * @remarks * * @typeParam Schema - the editor schema used node. */ export interface ApplyReturn extends TaggedDocProps, EditorStateProps { /** * True when the command was applied successfully. */ pass: boolean; } export interface CreateEditorOptions extends Omit { /** * Whether to auto remove the editor from the dom after each test. It is * advisable to leave this unchanged. * * @defaultValue true */ autoClean?: boolean; /** * The plugins that the test editor should use. * * @defaultValue [] */ plugins?: ProsemirrorPlugin[]; /** * The input rules that the test editor should use. * * @defaultValue [] */ rules?: InputRule[]; } /** * An instance of this class is returned when using `createEditor`. It allows * for chaining of test operations and adds some useful helpers to your testing * toolkit. */ export declare class ProsemirrorTestChain { /** * A static helper utility for creating new TestReturn values. */ static of(view: TestEditorView): ProsemirrorTestChain; /** * The prosemirror view. */ view: TestEditorView; /** * The current prosemirror node document */ get doc(): ProsemirrorNode; /** * The prosemirror schema. */ get schema(): Schema; /** * The prosemirror state. */ get state(): EditorState; /** * The prosemirror selection. */ get selection(): Selection; /** * The start of the current selection. */ get start(): number; /** * The end of the current selection. */ get end(): number; /** * The content to write to the clipboard if copy the current selection. */ get copied(): { text: string; html: string; }; constructor(view: TestEditorView); /** * Overwrite all the current content within the editor. * * @param newDoc - the new content to use */ overwrite(newDocument: ProsemirrorNode): this; /** * Run the command within the prosemirror editor. * * @remarks * * ```ts * test('commands are run', () => { * createEditor(doc(p(''))) * .command((state, dispatch) => { * if (dispatch) { * dispatch(state.tr.insertText('hello')); * } * }) * .callback(content => { * expect(content.state.doc).toEqualProsemirrorDocument(doc(p('hello'))); * }) * }) * ``` * * @param command - the command function to run */ command(command: ProsemirrorCommandFunction): this; /** * Takes any remirror command as an input and dispatches it within the * document context. * * @param command - the command function to run with the current state and * view */ readonly remirrorCommand: (command: CommandFunction) => this; /** * Insert text into the editor at the current position. * * @param text - the text to insert */ insertText(text: string): this; /** * Selects the text between the provided selection primitive. */ readonly selectText: (selection: PrimitiveSelection) => this; /** * Type a keyboard shortcut - e.g. `Mod-Enter`. * * **NOTE** This only simulates the events. For example an `Mod-Enter` would * run all enter key handlers but not actually create a new line. * * @param mod - the keyboard shortcut to type */ shortcut(mod: string): this; /** * Simulate a keypress which is run through the editor's key handlers. * * **NOTE** This only simulates the events. For example an `Enter` would run * all enter key handlers but not actually create a new line. * * @param char - the character to type */ press(char: string): this; /** * Simulates a backspace keypress and deletes text backwards. */ backspace(times?: number): this; /** * Logs to the dom for help debugging your tests. */ debug: () => this; /** * Fire an event in the editor (very hit and miss). * * @param props - the props when firing an event */ fire(props: Omit): this; /** * Callback function which receives the `start`, `end`, `state`, `view`, * `schema` and `selection` properties and allows for easier testing of the * current state of the editor. */ callback(fn: (content: ReturnValueCallbackProps) => void): this; /** * Paste text into the editor. */ paste(content: ProsemirrorNode | string | { text: string; html: string; plainText?: boolean; }): this; } export interface ReturnValueCallbackProps extends TestEditorViewProps, EditorStateProps, SelectionProps { start: number; end: number; schema: Schema; doc: ProsemirrorNode; /** * Pretty log the current view to the dom. */ debug: () => void; } /** * Apply the command to the prosemirror node passed in. * * Returns a tuple matching the following structure * [ * bool => was the command successfully applied taggedDoc => the new doc as a * result of the command state => The new editor state after applying the * command * ] */ export declare function apply(taggedDocument: ProsemirrorNode, command: ProsemirrorCommandFunction, result?: ProsemirrorNode): ApplyReturn; /** * Find the first text node with the provided string. */ export declare function findTextNode(node: Node, text: string): Node | undefined; export {};