UNPKG

5.62 kBTypeScriptView Raw
1export declare type EditorSchema<Nodes extends string = string, Marks extends string = string> = import('../model').Schema<Nodes, Marks>;
2export declare type EditorView<Schema extends EditorSchema = EditorSchema> = import('../view').EditorView<Schema>;
3export declare type Selection<Schema extends EditorSchema = EditorSchema> = import('../state').Selection<Schema>;
4export declare type DecorationSet<Schema extends EditorSchema = EditorSchema> = import('../view').DecorationSet<Schema>;
5export declare type Transaction<Schema extends EditorSchema = EditorSchema> = import('../state').Transaction<Schema>;
6export declare type PluginKey<PluginState = EditorSchema> = import('../state').PluginKey<PluginState, EditorSchema>;
7export declare type Mark<Schema extends EditorSchema = EditorSchema> = import('../model').Mark<Schema>;
8export declare type ResolvedPos<Schema extends EditorSchema = EditorSchema> = import('../model').ResolvedPos<Schema>;
9export declare type InputRule<Schema extends EditorSchema = EditorSchema> = import('../inputrules').InputRule<Schema>;
10export declare type Fragment<Schema extends EditorSchema = EditorSchema> = import('../model').Fragment<Schema>;
11export declare type NodeView<Schema extends EditorSchema = EditorSchema> = import('../view').NodeView<Schema>;
12export declare type ProsemirrorNode<Schema extends EditorSchema = EditorSchema> = import('../model').Node<Schema>;
13export declare type ProsemirrorPlugin<PluginState = any> = import('../state').Plugin<PluginState, EditorSchema>;
14export declare type MarkType<Schema extends EditorSchema = EditorSchema> = import('../model').MarkType<Schema>;
15export declare type NodeType<Schema extends EditorSchema = EditorSchema> = import('../model').NodeType<Schema>;
16export declare type EditorState<Schema extends EditorSchema = EditorSchema> = Readonly<import('../state').EditorState<Schema>>;
17export declare type Slice<Schema extends EditorSchema = EditorSchema> = import('../model').Slice<Schema>;
18export declare type Decoration = import('../view').Decoration;
19export declare type Mapping = import('../transform').Mapping;
20declare const _brand: unique symbol;
21interface Branding<Type> {
22 readonly [_brand]: Type;
23}
24declare type Brand<Type, B> = Type & Branding<B>;
25/**
26 * Brands a command as non chainable so that it can be excluded from the
27 * inferred chainable commands.
28 */
29export declare type NonChainableCommandFunction<Schema extends EditorSchema = EditorSchema, Extra extends object = object> = Brand<CommandFunction<Schema, Extra>, 'non-chainable'>;
30/**
31 * Used to apply the Prosemirror transaction to the current {@link EditorState}.
32 *
33 * @template Schema - the underlying editor schema.
34 */
35export declare type DispatchFunction<Schema extends EditorSchema = EditorSchema> = (tr: Transaction<Schema>) => void;
36/**
37 * This is the type signature for commands within the prosemirror editor.
38 *
39 * @remarks
40 *
41 * A command function takes an editor state and optionally a dispatch function
42 * that it can use to dispatch a transaction. It should return a boolean that
43 * indicates whether it could perform any action.
44 *
45 * When no dispatch callback is passed, the command should do a 'dry run',
46 * determining whether it is applicable, but not actually performing any action.
47 *
48 * @template Schema - the underlying editor schema.
49 */
50export declare type ProsemirrorCommandFunction<Schema extends EditorSchema = EditorSchema> = (state: EditorState<Schema>, dispatch: DispatchFunction<Schema> | undefined, view: EditorView<Schema> | undefined) => boolean;
51/**
52 * A command method for running commands in your editor.
53 *
54 * @template Schema - the underlying editor schema.
55 * @template ExtraProps - extra parameters to add to the command function.
56 *
57 * @remarks
58 *
59 * This groups all the prosemirror command arguments into a single parameter.
60 *
61 * tldr; When `dispatch=undefined` make sure the command function is **idempotent**.
62 *
63 * One thing to be aware of is that when creating a command function the
64 * `tr` should only be updated when the `dispatch` method is available. This is
65 * because by convention calling the command function with `dispatch=undefined`
66 * is used to check if the function returns `true`, an indicator that it is
67 * enabled, or returns `false` to indicate it is not enabled.
68 *
69 * If the transaction has been updated outside of the `dispatch=true` condition
70 * then running the command again will result in multiple transaction updates
71 * and unpredictable behavior.
72 *
73 * @see {@link ProsemirrorCommandFunction}
74 */
75export declare type CommandFunction<Schema extends EditorSchema = EditorSchema, ExtraProps extends object = object> = (params: CommandFunctionProps<Schema> & ExtraProps) => boolean;
76/**
77 * A parameter builder interface for the remirror `CommandFunction`.
78 *
79 * @template Schema - the underlying editor schema.
80 */
81export interface CommandFunctionProps<Schema extends EditorSchema = EditorSchema> {
82 /**
83 * The shared ProseMirror Transaction.
84 */
85 tr: Transaction<Schema>;
86 /**
87 * A snapshot of the ProseMirror editor state.
88 */
89 state: EditorState<Schema>;
90 /**
91 * The dispatch function which causes the command to be performed.
92 *
93 * @remarks
94 *
95 * `dispatch` can be `undefined`. When no `dispatch` callback is provided the
96 * command should perform a 'dry run', determining whether the command is
97 * applicable (`return true`), but not actually performing the action.
98 */
99 dispatch?: DispatchFunction<Schema>;
100 /**
101 * An instance of the ProseMirror editor `view`.
102 */
103 view?: EditorView<Schema>;
104}
105export {};