Skip to main content

core-types

package @remirror/core-types

interface AnchorHeadProps

A parameter for a non empty selection which defines the anchor (the non movable part of the selection) and the head (the movable part of the selection).

Signature:

export interface AnchorHeadProps 

property anchor

The non-movable part of the selection.

Signature:

anchor: number;

property head

The movable part of the selection.

Signature:

head: number;

interface ApplySchemaAttributes

Signature:

export interface ApplySchemaAttributes 

property defaults

A function which returns the object of defaults. Since this is for extra attributes a default must be provided.

Signature:

defaults: () => Record<string, {
default?: JsonPrimitive;
}>;

property dom

Take the node attributes and create the object of string attributes for storage on the dom node.

Signature:

dom: (nodeOrMark: ProsemirrorNode | Mark) => Record<string, string>;

property parse

Read a value from the dome and convert it into prosemirror attributes.

Signature:

parse: (domNode: Node | string) => ProsemirrorAttributes;

interface AttributesProps

A parameter builder interface containing the attrs property.

Signature:

export interface AttributesProps 

property attrs

An object describing the attrs for a prosemirror mark / node

Signature:

attrs: ProsemirrorAttributes;

interface Coords

Defines coordinates returned by the [[EditorView.coordsAtPos]] function.

Signature:

export interface Coords 

property bottom

Vertical distance from the top of the page viewport to the bottom side of the described position (px).

Signature:

bottom: number;

property left

Horizontal distance from the left of the page viewport to the left side of the described position (px).

Signature:

left: number;

property right

Horizontal distance from the left of the page viewport to the right side of the described position (px).

Signature:

right: number;

property top

Vertical distance from the top of the page viewport to the top side of the described position (px).

Signature:

top: number;

interface DOMCompatibleAttributes

Signature:

export interface DOMCompatibleAttributes 

Signature:

[attribute: string]: string | number | undefined;

interface EditorStateProps

A parameter builder interface containing the state property.

Signature:

export interface EditorStateProps 

property state

A snapshot of the prosemirror editor state.

Signature:

state: EditorState;

interface EditorViewProps

A parameter builder interface containing the view property.

Signature:

export interface EditorViewProps 

property view

An instance of the Prosemirror editor view.

Signature:

view: EditorView;

interface Flavoring

Used by Flavor to mark a type in a readable way.

Signature:

export interface Flavoring<Name> 

property [_flavor]

Signature:

readonly [_flavor]?: Name;

interface FromToProps

A parameter builder interface describing a from/to range.

Signature:

export interface FromToProps 

property from

The starting position in the document.

Signature:

from: number;

property to

The ending position in the document.

Signature:

to: number;

interface GetAttributesProps

Signature:

export interface GetAttributesProps 

property getAttributes

A helper function for setting the attributes for a transformation .

Signature:

getAttributes: GetAttributes;

interface KeyBindingProps

Signature:

export interface KeyBindingProps extends CommandFunctionProps 

Extends: CommandFunctionProps

(Some inherited members may not be shown because they are not represented in the documentation.)

property next

A method to run the next (lower priority) command in the chain of keybindings.

Signature:

next: () => boolean;

Remarks:

This can be used to chain together keyboard commands between extensions. It's possible that you will need to combine actions when a key is pressed while still running the default action. This method allows for the greater degree of control.

By default, matching keyboard commands from the different extension are chained together (in order of priority) until one returns true. Calling next changes this default behaviour. The default keyboard chaining stops and you are given full control of the keyboard command chain.

interface MarkExtensionSpec

The schema spec definition for a mark extension

Signature:

export interface MarkExtensionSpec extends Pick<MarkSpec, 'attrs' | 'inclusive' | 'excludes' | 'group' | 'spanning' | 'parseDOM'> 

Extends: Pick<MarkSpec, 'attrs' | 'inclusive' | 'excludes' | 'group' | 'spanning' | 'parseDOM'>

(Some inherited members may not be shown because they are not represented in the documentation.)

property toDOM

Defines the default way marks of this type should be serialized to DOM/HTML.

Signature:

toDOM?: (mark: MarkWithAttributes, inline: boolean) => DOMOutputSpec;

interface MarkTypeProps

A parameter builder interface containing the mark type property.

Signature:

export interface MarkTypeProps 

property type

The prosemirror mark type instance.

Signature:

type: MarkType | string;

interface MarkTypesProps

A parameter builder interface containing the types property which takes a single type or multiple types.

Signature:

export interface MarkTypesProps 

Remarks:

This can be used to check whether a certain type matches any of these types.

property types

The prosemirror node types to use.

Signature:

types: MarkType | MarkType[];

interface MarkWithAttributesProps

Signature:

export interface MarkWithAttributesProps<Attributes extends object = object> 

property mark

A mark with a specific shape for node.attrs

Signature:

mark: MarkWithAttributes<Attributes>;

interface NodeExtensionSpec

The schema spec definition for a node extension

Signature:

export interface NodeExtensionSpec extends Partial<Pick<NodeSpec, 'content' | 'marks' | 'group' | 'inline' | 'atom' | 'attrs' | 'selectable' | 'draggable' | 'code' | 'defining' | 'isolating' | 'parseDOM' | 'toDebugString' | 'allowGapCursor' | 'leafText'>> 

Extends: Partial<Pick<NodeSpec, 'content' | 'marks' | 'group' | 'inline' | 'atom' | 'attrs' | 'selectable' | 'draggable' | 'code' | 'defining' | 'isolating' | 'parseDOM' | 'toDebugString' | 'allowGapCursor' | 'leafText'>>

(Some inherited members may not be shown because they are not represented in the documentation.)

property toDOM

Defines the default way a node of this type should be serialized to DOM/HTML (as used by [[DOMSerializer.fromSchema]].

Should return a [[DOMOutputSpec]] that describes a DOM node, with an optional number zero (“hole”) in it to indicate where the node's content should be inserted.

Signature:

toDOM?: (node: NodeWithAttributes) => DOMOutputSpec;

interface NodeMarkOptions

Signature:

export interface NodeMarkOptions 

property mark

Signature:

mark?: Mark;

property node

Signature:

node?: ProsemirrorNode;

interface NodeTypeProps

A parameter builder interface containing the node type property.

Signature:

export interface NodeTypeProps 

property type

A prosemirror node type instance.

Signature:

type: NodeType | string;

interface NodeTypesProps

A parameter builder interface containing the types property which takes a single type or multiple types.

Signature:

export interface NodeTypesProps 

Remarks:

This can be used to check whether a certain type matches any of these types.

property types

The prosemirror node types to use.

Signature:

types: NodeType | string | Array<NodeType | string>;

interface NodeWithAttributesProps

Signature:

export interface NodeWithAttributesProps<Attributes extends object = object> 

property node

A prosemirror node with a specific shape for node.attrs

Signature:

node: NodeWithAttributes<Attributes>;

interface ObjectMark

A JSON representation of a prosemirror Mark.

Signature:

export interface ObjectMark 

property attrs

Signature:

attrs?: Record<string, Literal>;

property type

Signature:

type: string;

interface OptionalMarkProps

Signature:

export interface OptionalMarkProps 

property mark

The nullable prosemirror mark which may or may not exist.

Signature:

mark: Mark | null | undefined;

interface OptionalProsemirrorNodeProps

Signature:

export interface OptionalProsemirrorNodeProps 

property node

The nullable prosemirror node which may or may not exist. Please note that the find will fail if this does not exists.

To prevent cryptic errors this should always be the doc node.

Signature:

node: ProsemirrorNode | null | undefined;

interface PosProps

Signature:

export interface PosProps 

property pos

The position of the referenced prosemirror item.

Signature:

pos: number;

interface PredicateProps

Signature:

export interface PredicateProps<Type> 

property predicate

The predicate function

Signature:

predicate: (value: Type) => boolean;

interface ProsemirrorNodeProps

Signature:

export interface ProsemirrorNodeProps 

property node

The prosemirror node

Signature:

node: ProsemirrorNode;

interface RangeProps

Signature:

export interface RangeProps 

property range

The from/to interface.

Signature:

range: FromToProps;

interface RegExpProps

Signature:

export interface RegExpProps 

property regexp

The regular expression to test against.

Signature:

regexp: RegExp;

interface RemirrorIdentifierShape

The core shape of any remirror specific object.

Signature:

export interface RemirrorIdentifierShape 

property [__INTERNAL_REMIRROR_IDENTIFIER_KEY__]

Signature:

[__INTERNAL_REMIRROR_IDENTIFIER_KEY__]: RemirrorIdentifier;

interface RemirrorJSON

A JSON representation of the prosemirror Node.

Signature:

export interface RemirrorJSON 

Remarks:

This is used to represent the top level doc nodes content.

property attrs

Signature:

attrs?: Record<string, Literal>;

property content

Signature:

content?: RemirrorJSON[];

property marks

Signature:

marks?: Array<ObjectMark | string>;

property text

Signature:

text?: string;

property type

Signature:

type: string;

interface ResolvedPosProps

Signature:

export interface ResolvedPosProps 

property $pos

A prosemirror resolved pos with provides helpful context methods when working with a position in the editor.

Signature:

$pos: ResolvedPos;

interface SchemaAttributesObject

The configuration object for adding extra attributes to the node or mark in the editor schema.

Please note that using this will alter the schema, so changes here can cause breaking changes for users if not managed carefully.

TODO #462 is being added to support migrations so that breaking changes can be handled automatically.

Signature:

export interface SchemaAttributesObject 

property default

The default value for the attribute being added, if set to null then the initial value for any nodes is not required.

If set to undefined then a value must be provided whenever a node or mark that has this extra attribute is created. ProseMirror will throw if the value isn't required. Make sure you know what you're doing before setting it to undefined as it could cause unintended errors.

This can also be a function which enables dynamically setting the attribute based on the value returned.

Signature:

default: JsonPrimitive | DynamicAttributeCreator;

property parseDOM

A function used to extract the attribute from the dom and must be applied to the parseDOM method.

If a string is set this will automatically call domNode.getAttribute('<name>').

Signature:

parseDOM?: ((domNode: HTMLElement) => JsonPrimitive | undefined) | string;

property toDOM

Takes the node attributes and applies them to the dom.

This is called in the toDOM method.

  • If a string is set this will always be the constant value set in the dom. - If a tuple with two items is set then the first string is the attribute to set in the dom and the second string is the value that will be stored.

Return undefined from the function call to skip adding the attribute.

Signature:

toDOM?: string | [string, string?] | Record<string, string> | ((attrs: ProsemirrorAttributes, options: NodeMarkOptions) => string | [string, string?] | Record<string, string> | null | undefined);

interface SchemaProps

A parameter builder interface containing the schema property.

Signature:

export interface SchemaProps 

property schema

Each Remirror Editor has an automatically generated schema associated with it. The schema is a ProseMirror primitive which describes the kind of nodes that may occur in the document, and the way they are nested. For example, it might say that the top-level node can contain one or more blocks, and that paragraph nodes can contain any number of inline nodes, with any marks applied to them.

Read more about it [here](https://prosemirror.net/docs/guide/\#schema).

Signature:

schema: EditorSchema;

interface SelectionProps

Signature:

export interface SelectionProps 

property selection

The text editor selection

Signature:

selection: Selection;

interface Shape

An object with string keys and values of type any

Signature:

export interface Shape 

Signature:

[key: string]: any;

interface StateJSON

Signature:

export interface StateJSON 

property doc

The main ProseMirror doc.

Signature:

doc: RemirrorJSON;

property selection

The current selection.

Signature:

selection: FromToProps;

This allows for plugin state to be stored, although this is not currently used in remirror.

Signature:

[key: string]: unknown;

interface TextProps

Signature:

export interface TextProps 

property text

The text to insert or work with.

Signature:

text: string;

interface TransactionProps

Signature:

export interface TransactionProps 

property tr

The prosemirror transaction

Signature:

tr: Transaction;

interface TrStateProps

Signature:

export interface TrStateProps 

property trState

The shared types between a state and a transaction. Allows for commands to operate on either a state object or a transaction object.

Signature:

trState: EditorState | Transaction;

interface ValidOptions

This constrains the valid options that can be passed into your extensions or presets.

Signature:

export interface ValidOptions 

Signature:

[option: string]: any;

type AcceptUndefined

Wrap a type in this to let the DefaultOptions know that it can accept undefined as the default value.

Signature:

export declare type AcceptUndefined<Type> = Type & AcceptUndefinedAnnotation;

type And

A shorthand for creating and intersection of two object types.

Signature:

export declare type And<Type extends Shape, Other extends Shape> = Type & Other;

References: Shape

type AnyConstructor

Matches any constructor type.

Signature:

export declare type AnyConstructor<Type = any> = new (...args: any[]) => Type;

type AnyFunction

Concisely and cleanly define an arbitrary function.

Signature:

export declare type AnyFunction<Type = any> = (...args: any[]) => Type;

Remarks:

Taken from simplytyped Useful when designing many api's that don't care what function they take in, they just need to know what it returns.

type Array1

An array which must include the first item.

Signature:

export declare type Array1<Type> = MinArray<Type, 1>;

References: MinArray

type Array2

An array which must include the first 2 items.

Signature:

export declare type Array2<Type> = MinArray<Type, 2>;

References: MinArray

type Array3

An array which must include the first 3 items.

Signature:

export declare type Array3<Type> = MinArray<Type, 3>;

References: MinArray

type Brand

Create a "branded" version of a type. TypeScript won't allow implicit conversion to this type

Signature:

export declare type Brand<Type, B> = Type & Branding<B>;

type ConditionalReturnKeys

Conditionally pick keys which are functions and have the requested return type.

Signature:

export declare type ConditionalReturnKeys<Base, Return> = NonNullable<{
[Key in keyof Base]: Base[Key] extends AnyFunction<infer R> ? R extends Return ? Key : never : never;
}[keyof Base]>;

References: AnyFunction

type ConditionalReturnPick

Pick the properties from an object that are methods with the requested Return type.

Signature:

export declare type ConditionalReturnPick<Base, Return> = Pick<Base, ConditionalReturnKeys<Base, Return>>;

References: ConditionalReturnKeys

type CustomHandler

A handler type which gives you full control of what the handler can do and what is can return.

For example with keybindings you will probably receive an object of event handlers which need to be added to the keymap plugin. The custom handler annotation allows you to accept functions or objects which return non void values and set upt the handler for yourself.

For custom handlers the options value is meaningless and can only be changed through the addCustomHandler method.

Signature:

export declare type CustomHandler<Type> = Type & CustomHandlerAnnotation;

type CustomHandlerKey

Signature:

export declare type CustomHandlerKey<Options extends ValidOptions> = StringKey<GetCustomHandler<Options>>;

References: ValidOptions, StringKey, GetCustomHandler

type CustomHandlerKeyList

Signature:

export declare type CustomHandlerKeyList<Options extends ValidOptions> = Array<CustomHandlerKey<Options>>;

References: ValidOptions, CustomHandlerKey

type CustomHandlerShape

Signature:

export declare type CustomHandlerShape<Type extends Shape> = {
[Key in keyof Type]: CustomHandler<Type[Key]>;
};

References: Shape, CustomHandler

type DeepPartial

A recursive partial type. Useful for object that will be merged with defaults.

Signature:

export declare type DeepPartial<Type> = Type extends object ? {
[K in keyof Type]?: DeepPartial<Type[K]>;
} : Type;

References: DeepPartial

type DeepString

Converts every nested type to a string.

Signature:

export declare type DeepString<Type> = Type extends object ? {
[K in keyof Type]: DeepString<Type[K]>;
} : string;

References: DeepString

type Diff

Get the diff between two types. All identical keys are stripped away.

Signature:

export declare type Diff<A, B> = Omit<A, keyof B> & Omit<B, keyof A>;

Remarks:

type Fun = Diff<{notFun: false, fun: true}, {notFun: true, wow: string}>;
// => { fun: true, wow: string }

type Dispose

A function used to cleanup any effects from the Handler or Custom options.

In react you would use the return value from the addHandler or setCustom as the clean up function for your useEffect hooks.

Signature:

export declare type Dispose = () => void;

type DOMOutputSpec

Defines the return type of the toDOM methods for both nodes and marks

Signature:

export declare type DOMOutputSpec = string | DOMOutputSpecArray;

Remarks:

This differs from the default Prosemirror type definition which seemed didn't work at the time of writing.

Additionally we don't want to support domNodes in the toDOM spec since this will create problems once SSR is fully supported

DOMOutputSpec is a description of a DOM structure. Can be either a string, which is interpreted as a text node, a DOM node (not supported by remirror), which is interpreted as itself, a {dom: Node, contentDOM: ?Node} object (not supported by remirror), or an array (DOMOutputSpecArray).

An array (DOMOutputSpecArray) describes a DOM element. The first value in the array should be a string—the name of the DOM element, optionally prefixed by a namespace URL and a space. If the second element is plain object (DOMCompatibleAttributes), it is interpreted as a set of attributes for the element. Any elements after that (including the 2nd if it's not an attribute object) are interpreted as children of the DOM elements, and must either be valid DOMOutputSpec values, or the number zero.

The number zero (pronounced “hole”) is used to indicate the place where a node's child nodes should be inserted. If it occurs in an output spec, it should be the only child element in its parent node.

type Dynamic

Wrap an option in this type to indicate to the TypeScript compiler that it is a dynamic property. It can be set through the constructor parameter at instantiation and can by updated throughout the lifetime of your editor.

Signature:

export declare type Dynamic<Type> = Type & DynamicAnnotation;

Remarks:

This is the default type assumed and it can be left unused.

import { Dynamic, PlainExtension } from 'remirror';

interface MyExtensionOptions {
isSwitchedOn: Dynamic<boolean>;
}

export class MyExtension extends PlainExtension<MyExtensionOptions> {
get name() {
return 'my' as const';
}
}

new extension = new MyExtension({ isSwitchedOn: false });
extension.setOptions({ isSwitchedOn: true });

type DynamicAttributeCreator

A dynamic attributes creator. This is used to create attributes that are dynamically set when a node is first added to the dom.

Signature:

export declare type DynamicAttributeCreator = (nodeOrMark: ProsemirrorNode | Mark) => JsonPrimitive;

References: JsonPrimitive

type DynamicKey

Signature:

export declare type DynamicKey<Options extends ValidOptions> = StringKey<GetDynamic<Options>>;

References: ValidOptions, StringKey, GetDynamic

type DynamicKeyList

Signature:

export declare type DynamicKeyList<Options extends ValidOptions> = Array<DynamicKey<Options>>;

References: ValidOptions, DynamicKey

type DynamicShape

Signature:

export declare type DynamicShape<Type extends object> = {
[Key in keyof Type]: Dynamic<Type[Key]>;
};

References: Dynamic

type EmptyShape

An alternative to usage of {} as a type.

Signature:

export declare type EmptyShape = Record<never, never>;

type Flavor

Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding.

Signature:

export declare type Flavor<Type, Name> = Type & Flavoring<Name>;

References: Flavoring

type FlipPartialAndRequired

Reverses the partial and required keys for the type provided. If it was a required property it becomes a partial property and if it was a partial property it becomes a required property.

Signature:

export declare type FlipPartialAndRequired<Type extends Shape> = PickPartial<Type> & Partial<PickRequired<Type>>;

References: Shape, PickPartial, PickRequired

type GetAcceptUndefined

Get the properties that accept undefined as a default.

Signature:

export declare type GetAcceptUndefined<Options extends Shape> = ConditionalPick<Options, AcceptUndefinedAnnotation> & Partial<ConditionalPick<PickPartial<Options>, AcceptUndefinedAnnotation>>;

References: Shape, PickPartial

type GetAttributes

A function which takes a regex match array (strings) or a single string match and transforms it into an Attributes object.

Signature:

export declare type GetAttributes = ProsemirrorAttributes | GetAttributesFunction;

References: ProsemirrorAttributes

type GetConstructorProps

The options that can be passed into a constructor.

Signature:

export declare type GetConstructorProps<Options extends ValidOptions> = GetStatic<Options> & GetDynamic<Options>;

References: ValidOptions, GetStatic, GetDynamic

type GetCustomHandler

Get the object event handler Options from the options type.

Signature:

export declare type GetCustomHandler<Options extends Shape> = ConditionalPick<Options, CustomHandlerAnnotation> & Partial<ConditionalPick<PickPartial<Options>, CustomHandlerAnnotation>>;

References: Shape, PickPartial

type GetDynamic

Get the dynamic Options from the options type.

Signature:

export declare type GetDynamic<Options extends Shape> = Omit<ConditionalExcept<Options, Exclude<Remirror.ValidOptionsExtender[keyof Remirror.ValidOptionsExtender], DynamicAnnotation>>, keyof ConditionalPick<PickPartial<Options>, Exclude<Remirror.ValidOptionsExtender[keyof Remirror.ValidOptionsExtender], DynamicAnnotation>>>;

References: Shape, PickPartial

type GetFixed

Signature:

export declare type GetFixed<Options extends ValidOptions> = Readonly<Required<Options>>;

References: ValidOptions

type GetFixedCustomHandler

Signature:

export declare type GetFixedCustomHandler<Options extends ValidOptions> = Readonly<Required<GetCustomHandler<Options>>>;

References: ValidOptions, GetCustomHandler

type GetFixedDynamic

Signature:

export declare type GetFixedDynamic<Options extends ValidOptions> = Readonly<Required<GetDynamic<Options>>>;

References: ValidOptions, GetDynamic

type GetFixedProps

Signature:

export declare type GetFixedProps<Options extends ValidOptions> = GetFixedDynamic<Options> & GetFixedStatic<Options>;

References: ValidOptions, GetFixedDynamic, GetFixedStatic

type GetFixedStatic

Signature:

export declare type GetFixedStatic<Options extends ValidOptions> = Readonly<Required<GetStatic<Options>>>;

References: ValidOptions, GetStatic

type GetFlippedStatic

Signature:

export declare type GetFlippedStatic<Options extends ValidOptions> = FlipPartialAndRequired<Options>;

References: ValidOptions, FlipPartialAndRequired

type GetHandler

Get the event handler Options from the options type.

Signature:

export declare type GetHandler<Options extends Shape> = ConditionalPick<Options, HandlerAnnotation> & Partial<ConditionalPick<PickPartial<Options>, HandlerAnnotation>>;

References: Shape, PickPartial

type GetMappedCustomHandler

Signature:

export declare type GetMappedCustomHandler<Options extends ValidOptions> = {
[Key in keyof GetCustomHandler<Options>]: Array<GetCustomHandler<Options>[Key]>;
};

References: ValidOptions, GetCustomHandler

type GetMappedHandler

Signature:

export declare type GetMappedHandler<Options extends ValidOptions> = {
[Key in keyof GetHandler<Options>]: Array<[
priority: ExtensionPriority,
handler: GetHandler<Options>[Key]
]>;
};

References: ValidOptions, GetHandler

type GetPartialDynamic

Signature:

export declare type GetPartialDynamic<Options extends ValidOptions> = Partial<GetDynamic<Options>>;

References: ValidOptions, GetDynamic

type GetRequiredKeys

Get all the keys for required properties on this type.

Signature:

export declare type GetRequiredKeys<Type extends Shape> = keyof ConditionalPick<KeepPartialProperties<Type>, NeverBrand>;

References: Shape, KeepPartialProperties

type GetStatic

Get the static Options from the options type.

Signature:

export declare type GetStatic<Options extends Shape> = ConditionalPick<Options, StaticAnnotation> & Partial<ConditionalPick<PickPartial<Options>, StaticAnnotation>>;

References: Shape, PickPartial

type GetStaticAndDynamic

Options excluding the handlers.

Signature:

export declare type GetStaticAndDynamic<Options extends Shape> = GetDynamic<Options> & GetStatic<Options>;

References: Shape, GetDynamic, GetStatic

type Handler

A handler is a callback provided by the user to respond to events from your extension. Often times it's helpful to be able to consume a handler in multiple places. Remirror can help automate the registration of handlers that can be consumed multiple times.

Signature:

export declare type Handler<Type extends AnyFunction<void>> = Type & HandlerAnnotation;

References: AnyFunction

Remarks:

Use this type to annotate a method in your options as an event handler. This will tell the TypeScript compiler to include this event in the relevant methods for composing events together.

To automate the creation of handler code you will also need to set the handlerKeys static property for your Extension or Preset to be an array with the keys you've annotated as a handler. An **eslint** rule will be created to automate this.

import { PlainExtension, extensionDecorator } from 'remirror';
interface CustomOptions {
simple: boolean; // Automatically a dynamic property
onChange: Handler<(value: string) => void>;
}

@extensionDecorator({ handlerKeys: ['onChange'] }) class CustomExtension
extends PlainExtension<CustomOptions> {get name() {return 'custom' as const;
}
}

// No prompt to include the `onChange` handler due to the annotation. const
extension = new CustomExtension({simple: false});

const dispose = extension.addHandlers('onChange', (value) => {sideEffect();
});

// Later

dispose();

type HandlerKey

Signature:

export declare type HandlerKey<Options extends ValidOptions> = StringKey<GetHandler<Options>>;

References: ValidOptions, StringKey, GetHandler

type HandlerKeyList

Signature:

export declare type HandlerKeyList<Options extends ValidOptions> = Array<HandlerKey<Options>>;

References: ValidOptions, HandlerKey

type HandlerShape

Signature:

export declare type HandlerShape<Type extends Shape> = {
[Key in keyof Type]: Handler<Type[Key]>;
};

References: Shape, Handler

type IfEmpty

Conditional type which checks if the provided Type is and empty object (no properties). If it is uses the Then type if not falls back to the Else type.

Signature:

export declare type IfEmpty<Type extends object, Then, Else> = keyof Type extends never ? Then : Else;

type IfHasRequiredProperties

Checks the type provided and if it has any properties which are required it will return the Then type. When none of the properties are required it will return the Else type.

Signature:

export declare type IfHasRequiredProperties<Type extends object, Then, Else> = IfNoRequiredProperties<Type, Else, Then>;

References: IfNoRequiredProperties

Remarks:

This is a reverse of the IfNoRequiredProperties type.

type IfMatches

Condition that checks if the keys of the two objects match. If so, respond with Then otherwise Else.

Signature:

export declare type IfMatches<A, B, Then, Else> = IfEmpty<Diff<A, B>, Then, Else>;

References: IfEmpty, Diff

type IfNoRequiredProperties

A conditional check on the type. When there are no required keys it outputs the Then type, otherwise it outputs the Else type.

Signature:

export declare type IfNoRequiredProperties<Type extends object, Then, Else> = GetRequiredKeys<Type> extends NeverBrand ? Then : Else;

References: GetRequiredKeys

Remarks:

This is useful for dynamically setting the parameter list of a method call depending on whether keys are required.

type IndexUnionFromTuple

Extract the valid index union from a provided tuple.

import { IndexUnionFromTuple } from '@remirror/core-types';

const tuple = ['a', 'b', 'c'];
type Index = IndexUnionFromTuple<typeof tuple> => 0 | 1 | 2

Signature:

export declare type IndexUnionFromTuple<Tuple extends readonly unknown[]> = Tuple extends Tuple ? number extends Tuple['length'] ? number : _IndexUnionFromTuple<[], Tuple['length']> : never;

type JsonPrimitive

Matches any valid JSON primitive value.

Signature:

export declare type JsonPrimitive = string | number | boolean | null;

type KeepPartialProperties

Keeps the partial properties of a type unchanged. Transforms the rest to never.

Signature:

export declare type KeepPartialProperties<Type extends Shape> = {
[Key in keyof Type]: Type[Key] extends undefined ? Type[Key] : NeverBrand;
};

References: Shape

type KeyBindingCommandFunction

The command function passed to any of the keybindings.

Signature:

export declare type KeyBindingCommandFunction = (params: KeyBindingProps) => boolean;

References: KeyBindingProps

type KeyBindingNames

Some commonly used keybinding names to help with auto complete.

Signature:

export declare type KeyBindingNames = 'Enter' | 'ArrowDown' | 'ArrowUp' | 'ArrowLeft' | 'ArrowRight' | 'PageUp' | 'PageDown' | 'Home' | 'End' | 'Escape' | 'Delete' | 'Backspace' | 'Tab' | 'Shift-Tab';

type KeyBindings

A map of keyboard bindings and their corresponding command functions (a.k.a editing actions).

Signature:

export declare type KeyBindings = Partial<Record<KeyBindingNames, KeyBindingCommandFunction>> & Record<string, KeyBindingCommandFunction>;

References: KeyBindingNames, KeyBindingCommandFunction

Remarks:

Each keyboard binding returns an object mapping the keys pressed to the KeyBindingCommandFunction. By default the highest priority extension will be run first. If it returns true, then nothing else will be run after. If it returns false then the next (lower priority) extension defining the same keybinding will be run.

It is possible to combine the commands being run by using the next parameter. When called it will run the keybinding command function for the proceeding (lower priority) extension. The act of calling the next method will prevent the default flow from executing.

type Listable

Allow a type of a list of types.

Signature:

export declare type Listable<Type> = Type | Type[];

type Literal

All the literal types

Signature:

export declare type Literal = string | number | boolean | undefined | null | void | object;

type MakeNullable

Makes specified keys of an interface nullable while the rest stay the same.

Signature:

export declare type MakeNullable<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]: Type[Key] | null;
};

type MakeOptional

Makes specified keys of an interface optional while the rest stay the same.

Signature:

export declare type MakeOptional<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]+?: Type[Key];
};

type MakeReadonly

Makes specified keys of an interface readonly.

Signature:

export declare type MakeReadonly<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
+readonly [Key in Keys]: NonNullable<Type[Key]>;
};

type MakeRequired

Makes specified keys of an interface Required while the rest remain unchanged.

Signature:

export declare type MakeRequired<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]-?: Type[Key];
};

type MakeUndefined

Makes specified keys of an interface optional while the rest stay the same.

Signature:

export declare type MakeUndefined<Type extends object, Keys extends keyof Type> = Omit<Type, Keys> & {
[Key in Keys]: Type[Key] | undefined;
};

type MarkSpecOverride

Signature:

export declare type MarkSpecOverride = Pick<MarkSpec, 'inclusive' | 'excludes' | 'group' | 'spanning' | 'parseDOM'>;

type MarkWithAttributes

Signature:

export declare type MarkWithAttributes<Attributes extends object = object> = Mark & {
attrs: ProsemirrorAttributes<Attributes>;
};

References: ProsemirrorAttributes

type MinArray

Create a type for an array (as a tuple) which has at least the provided Length.

This can be useful when noUncheckedIndexedAccess is set to true in the compiler options. Annotate types when you are sure the provided index will always be available.

import { MinArray } from '@remirror/core-types';

MinArray<string, 2>; // => [string, string, ...string[]];

Signature:

export declare type MinArray<Type, Length extends number> = Length extends Length ? number extends Length ? Type[] : _MinArray<Type, Length, []> : never;

type NodeSpecOverride

Signature:

export declare type NodeSpecOverride = Pick<NodeSpec, 'content' | 'marks' | 'group' | 'inline' | 'atom' | 'selectable' | 'draggable' | 'code' | 'defining' | 'isolating' | 'parseDOM'>;

type NodeViewMethod

The method signature used to call the Prosemirror nodeViews

Signature:

export declare type NodeViewMethod<View extends NodeView = NodeView> = (node: ProsemirrorNode, view: EditorView, getPos: (() => number) | boolean, decorations: readonly Decoration[]) => View;

type NodeWithAttributes

Signature:

export declare type NodeWithAttributes<Attributes extends object = object> = ProsemirrorNode & {
attrs: ProsemirrorAttributes<Attributes>;
};

References: ProsemirrorAttributes

type NonNullableShape

Signature:

export declare type NonNullableShape<Type extends object> = {
[Key in keyof Type]: NonNullable<Type[Key]>;
};

type Nullable

Makes a type nullable or undefined.

Signature:

export declare type Nullable<Type> = Type | null | undefined;

type PartialWithRequiredKeys

Make the whole interface partial except for some specified keys which will be made required.

Signature:

export declare type PartialWithRequiredKeys<Type extends object, Keys extends keyof Type> = Partial<Pick<Type, Exclude<keyof Type, Keys>>> & Required<Pick<Type, Keys>>;

type PickPartial

Pick the partial properties from the provided Type and make them all required.

Signature:

export declare type PickPartial<Type extends Shape> = {
[Key in keyof ConditionalExcept<KeepPartialProperties<Type>, NeverBrand>]-?: Type[Key];
};

References: Shape, KeepPartialProperties

type PickRequired

Only pick the required (non-partial) types from the given Type.

Signature:

export declare type PickRequired<Type extends Shape> = {
[Key in keyof ConditionalPick<KeepPartialProperties<Type>, NeverBrand>]: Type[Key];
};

References: Shape, KeepPartialProperties

type Predicate

Creates a predicate type.

Signature:

export declare type Predicate<Type> = (value: unknown) => value is Type;

type PrimitiveSelection

The type of arguments acceptable for a selection.

  • Can be a selection - A range of { from: number; to: number } - A single position with a number - 'start' | 'end' | 'all' - { anchor: number, head: number }

Signature:

export declare type PrimitiveSelection = Selection | FromToProps | AnchorHeadProps | number | ResolvedPos | 'start' | 'end' | 'all';

References: FromToProps, AnchorHeadProps

type ProsemirrorAttributes

Used for attributes which can be added to prosemirror nodes and marks.

Signature:

export declare type ProsemirrorAttributes<Extra extends object = object> = Record<string, unknown> & Remirror.Attributes & Extra & {
class?: string;
};

type ProsemirrorKeyBindings

Signature:

export declare type ProsemirrorKeyBindings = Record<string, ProsemirrorCommandFunction>;

type RemirrorContentType

Supported content for the remirror editor.

Signature:

export declare type RemirrorContentType = string | RemirrorJSON | ProsemirrorNode | EditorState;

References: RemirrorJSON

Remarks:

Content can either be - a string (which will be parsed by the stringHandler) - JSON object matching Prosemirror expected shape - A top level ProsemirrorNode

type RemoveAnnotation

Signature:

export declare type RemoveAnnotation<Type> = RemoveFlavoring<RemoveFlavoring<RemoveFlavoring<RemoveFlavoring<RemoveFlavoring<Type, 'StaticAnnotation'>, 'DynamicAnnotation'>, 'HandlerAnnotation'>, 'CustomHandlerAnnotation'>, 'AcceptUndefinedAnnotation'>;

References: RemoveFlavoring

type RemoveAnnotations

Signature:

export declare type RemoveAnnotations<Options extends Shape> = {
[Key in keyof Options]: RemoveAnnotation<Options[Key]>;
};

References: Shape, RemoveAnnotation

type RemoveFlavoring

Remove the flavoring from a type.

Signature:

export declare type RemoveFlavoring<Type, Name> = Type extends Flavor<infer T, Name> ? T : Type;

References: Flavor

type Replace

Replace and extend any object keys.

Signature:

export declare type Replace<Type, Replacements extends Shape> = Omit<Type, keyof Replacements> & Replacements;

References: Shape

type SchemaAttributes

A mapping of the attribute name to it's default, getter and setter. If the value is set to a string then it will be resolved as the default.

If it is set to a function then it will be a dynamic node or mark.

Signature:

export declare type SchemaAttributes = Record<string, SchemaAttributesObject | string | DynamicAttributeCreator>;

References: SchemaAttributesObject, DynamicAttributeCreator

type Simplify

When a type is really deep and has retained an unnecessary amount of type information, this flattens it to a single array/object/value.

TODO not using it right now as it's breaking with globally available types via namespace.

Signature:

export declare type Simplify<T> = T extends object | any[] ? {
[K in keyof T]: T[K];
} : T;

type Static

Wrap your type in this to represent a static option, which can only be set at instantiation.

import { Static, PlainExtension } from 'remirror';

interface MyExtensionOptions {
content: Static<string>;
}

export class MyExtension extends PlainExtension<MyExtensionOptions> {
get name() {
return 'my' as const';
}
}

new extension = new MyExtension({ content: 'awesome string' });

The above example creates an extension with the content options set to 'awesome string'. This value is set and can never be updated.

One slight downside to the Static annotation is that is does mess up auto suggestions for string literals.

Signature:

export declare type Static<Type> = Type & StaticAnnotation;

type StaticKey

Signature:

export declare type StaticKey<Options extends ValidOptions> = StringKey<GetStatic<Options>>;

References: ValidOptions, StringKey, GetStatic

type StaticKeyList

Signature:

export declare type StaticKeyList<Options extends ValidOptions> = Array<StaticKey<Options>>;

References: ValidOptions, StaticKey

type StaticShape

Signature:

export declare type StaticShape<Type extends object> = {
[Key in keyof Type]: Static<Type[Key]>;
};

References: Static

type StrictReplace

Replace only the current keys with different types.

Signature:

export declare type StrictReplace<Type, Replacements extends Record<keyof Type, unknown>> = Omit<Type, keyof Replacements> & Replacements;

type StringKey

An alternative to keyof that only extracts the string keys.

Signature:

export declare type StringKey<Type> = Extract<keyof Type, string>;

type TransactionTransformer

Receives a transaction and returns an new transaction.

Can be used to update the transaction and customise commands.

Signature:

export declare type TransactionTransformer = (tr: Transaction, state: EditorState) => Transaction;

type TupleOf

Create a tuple of Size from the provided Type.

Signature:

export declare type TupleOf<Type, Size extends number> = Size extends Size ? number extends Size ? Type[] : _TupleOf<Type, Size, []> : never;

type TupleUnion

Returns tuple types that include every string in union TupleUnion<keyof {bar: string; leet: number }>; ["bar", "leet"] | ["leet", "bar"];

Taken from ❤️ https://github.com/microsoft/TypeScript/issues/13298\#issuecomment-692864087

Problem it is recursive and has quickly eats into the maximum depth.

Signature:

export declare type TupleUnion<T> = ((T extends any ? (t: T) => T : never) extends infer U ? (U extends any ? (u: U) => any : never) extends (v: infer V) => any ? V : never : never) extends (_: any) => infer W ? [...TupleUnion<Exclude<T, W>>, W] : [];

References: TupleUnion

type TupleValue

Extract the values of a tuple as a union type.

Signature:

export declare type TupleValue<Tuple extends readonly unknown[]> = Tuple[number];

Remarks:

const myTuple = ['a', 'b', 'c'] as const;

type MyTuple = TupleValue<typeof myTuple>; // 'a' | 'b' | 'c'

type UndefinedFlipPartialAndRequired

Reverses the partial and required keys for the type provided. If it was a required property it becomes a partial property and if it was a partial property it becomes a required property.

Signature:

export declare type UndefinedFlipPartialAndRequired<Type extends Shape> = UndefinedPickPartial<Type> & Partial<PickRequired<Type>>;

References: Shape, UndefinedPickPartial, PickRequired

type UndefinedPickPartial

Like pick partial but all types can still specify undefined.

Signature:

export declare type UndefinedPickPartial<Type extends Shape> = {
[Key in keyof PickPartial<Type>]: PickPartial<Type>[Key] | undefined;
};

References: Shape, PickPartial

type UnknownShape

An object with string keys and values of type unknown

Signature:

export declare type UnknownShape<Type = unknown> = Record<string, Type>;

type UseDefault

When the type is never use a default type instead.

TODO why doesn't this work

Signature:

export declare type UseDefault<Type, Default> = Type extends never ? Default : Type;

type Value

Extract the values of an object as a union type.

Signature:

export declare type Value<Type> = Type[keyof Type];

Remarks:

const myRecord = { A: 'a', B: 'b', C: 'c' } as const;

type MyRecord = Value<typeof myRecord>; // 'a' | 'b' | 'c'

type Writeable

Remove all readonly modifiers from the provided type.

Signature:

export declare type Writeable<Type> = {
-readonly [Key in keyof Type]: Type[Key];
};