@types/slate
Version:
TypeScript definitions for slate
1,490 lines (1,333 loc) • 115 kB
TypeScript
import * as Immutable from "immutable";
import { SyntheticEvent } from "react";
export interface Data extends Immutable.Map<any, any> {}
export namespace Data {
function create(properties: Immutable.Map<string, any> | { [key: string]: any }): Data;
function fromJSON(object: { [key: string]: any }): Data;
function fromJS(object: { [key: string]: any }): Data;
}
export interface RulesByNodeType {
[key: string]: Rules;
}
export interface ObjectAndType {
object?: string | undefined;
type?: string | undefined;
}
export interface Rules {
data?: {
[key: string]: (v: any) => boolean;
} | undefined;
first?: ObjectAndType | ObjectAndType[] | undefined;
isAtomic?: boolean | undefined;
isVoid?: boolean | undefined;
last?: ObjectAndType | ObjectAndType[] | undefined;
marks?:
| Array<{
type: string | ((type: string) => boolean);
}>
| undefined;
next?: ObjectAndType | ObjectAndType[] | undefined;
nodes?:
| Array<{
min?: number | undefined;
max?: number | undefined;
match?: ObjectAndType | ObjectAndType[] | undefined;
}>
| undefined;
normalize?: ((editor: Editor, error: SlateError) => void) | undefined;
parent?: ObjectAndType | ObjectAndType[] | undefined;
text?: RegExp | ((text: string) => boolean) | undefined;
previous?: ObjectAndType | ObjectAndType[] | undefined;
}
export interface SchemaProperties {
rules?: Array<{ match: ObjectAndType | ObjectAndType[] } & Rules> | undefined;
document?: Rules | undefined;
blocks?: RulesByNodeType | undefined;
inlines?: RulesByNodeType | undefined;
marks?: RulesByNodeType | undefined;
annotations?: RulesByNodeType | undefined;
decorations?: RulesByNodeType | undefined;
}
export type Path = Immutable.List<number> | number[] | string;
export interface ValueProperties {
object?: "value" | undefined;
annotations?: Immutable.Map<string, Annotation> | { [key: string]: AnnotationJSON } | undefined;
data?: Data | { [key: string]: any } | undefined;
document?: Document | undefined;
selection?: Selection | undefined;
}
export interface ValueJSON {
object?: "value" | undefined;
annotations?: { [key: string]: AnnotationJSON } | undefined;
data?: { [key: string]: any } | undefined;
document?: DocumentJSON | undefined;
selection?: SelectionJSON | undefined;
}
export class Value extends Immutable.Record({}) {
object: "value";
annotations: Immutable.Map<string, Annotation>;
data: Data;
document: Document;
selection: Selection;
readonly startBlock: Block;
readonly endBlock: Block;
readonly anchorBlock: Block;
readonly focusBlock: Block;
readonly nextBlock: Block;
readonly previousBlock: Block;
readonly startInline: Inline;
readonly endInline: Inline;
readonly anchorInline: Inline;
readonly focusInline: Inline;
readonly nextInline: Inline;
readonly previousInline: Inline;
readonly startText: Text;
readonly endText: Text;
readonly anchorText: Text;
readonly focusText: Text;
readonly nextText: Text;
readonly previousText: Text;
readonly marks: Immutable.OrderedSet<Mark>;
readonly activeMarks: Immutable.OrderedSet<Mark>;
readonly blocks: Immutable.List<Block>;
readonly fragment: Document;
readonly inlines: Immutable.List<Inline>;
readonly texts: Immutable.List<Text>;
static create(properties?: ValueProperties | ValueJSON | Value): Value;
static createProperties(attrs: ValueProperties | ValueJSON | Value): ValueProperties;
static fromJSON(properties: ValueProperties | ValueJSON): Value;
static fromJS(properties: ValueProperties | ValueJSON): Value;
static isValue(maybeValue: any): maybeValue is Value;
toJSON(options?: {
preserveAnnotations?: boolean | undefined;
preserveData?: boolean | undefined;
preserveSelection?: boolean | undefined;
}): ValueJSON;
toJS(options?: {
preserveAnnotations?: boolean | undefined;
preserveData?: boolean | undefined;
preserveSelection?: boolean | undefined;
}): ValueJSON;
addAnnotation(annotation: Annotation | AnnotationProperties | AnnotationJSON): Value;
addMark(path: Path, mark: MarkProperties | MarkJSON | Mark | string): Value;
insertNode(path: Path, node: Node): Value;
insertText(
path: Path,
offset: number,
text: string,
): Value;
mergeNode(path: Path): Value;
moveNode(path: Immutable.List<number>, newPath: Immutable.List<number>, newIndex?: number): Value;
removeAnnotation(annotation: Annotation | AnnotationProperties | AnnotationJSON): Value;
removeMark(path: Path, mark: MarkProperties | MarkJSON | Mark | string): Value;
removeNode(path: Path): Value;
removeText(path: Path, offset: number, text: string): Value;
setAnnotation(
properties: AnnotationProperties | AnnotationJSON | Annotation,
newProperties: AnnotationProperties | AnnotationJSON | Annotation,
): Value;
setNode(path: Path, properties: NodeProperties): Value;
setMark(
path: Path,
properties: MarkProperties,
newProperties: MarkProperties,
): Value;
setProperties(properties: ValueProperties): Value;
setSelection(
properties:
| RangeTypeProperties
| RangeTypeJSON
| RangeType
| string,
): Value;
splitNode(
path: Path,
position: number,
properties: NodeProperties,
): Value;
mapRanges(iterator: (val: Selection | Annotation) => any): Value;
mapPoints(iterator: (point: Point) => Point): Value;
}
export interface DocumentProperties {
object?: "document" | undefined;
nodes?: Immutable.List<Node> | Node[] | undefined;
key?: string | undefined;
data?: Data | { [key: string]: any } | undefined;
}
export interface DocumentJSON {
object?: "document" | undefined;
nodes?: NodeJSON[] | undefined;
key?: string | undefined;
data?: { [key: string]: any } | undefined;
}
export class Document extends BaseNode {
object: "document";
static create(
properties:
| DocumentProperties
| DocumentJSON
| Document
| Array<NodeJSON | NodeProperties | Node>
| Immutable.List<NodeJSON | NodeProperties | Node>,
): Document;
static fromJSON(properties: DocumentJSON | DocumentProperties | Document): Document;
static fromJS(properties: DocumentJSON | DocumentProperties | Document): Document;
static isDocument(maybeDocument: any): maybeDocument is Document;
toJSON(): DocumentJSON;
toJS(): DocumentJSON;
}
export interface BlockProperties {
object?: "block" | undefined;
type: string;
key?: string | undefined;
nodes?: Immutable.List<Block | Text | Inline> | Array<Block | Text | Inline> | undefined;
data?: Data | { [key: string]: any } | undefined;
}
export interface BlockJSON {
object?: "block" | undefined;
type: string;
key?: string | undefined;
nodes?: Array<BlockJSON | InlineJSON | TextJSON> | undefined;
data?: { [key: string]: any } | undefined;
}
export class Block extends BaseNode {
object: "block";
nodes: Immutable.List<Block | Text | Inline>;
static create(
properties:
| BlockProperties
| BlockJSON
| Block
| string,
): Block;
static createList(
array?:
| Array<BlockProperties | BlockJSON | Block | string>
| Immutable.List<BlockProperties | BlockJSON | Block | string>,
): Immutable.List<Block>;
static fromJSON(properties: BlockJSON | BlockProperties | Block): Block;
static fromJS(properties: BlockJSON | BlockProperties | Block): Block;
static isBlock(maybeBlock: any): maybeBlock is Block;
static isBlockList(
maybeBlockList: any,
): maybeBlockList is Immutable.List<Block>;
toJSON(): BlockJSON;
toJS(): BlockJSON;
}
export interface InlineProperties {
object?: "inline" | undefined;
type: string;
key?: string | undefined;
nodes?: Immutable.List<Inline | Text> | Array<Inline | Text> | undefined;
data?: Data | { [key: string]: any } | undefined;
}
export interface InlineJSON {
object?: "inline" | undefined;
type: string;
key?: string | undefined;
nodes?: Array<InlineJSON | TextJSON> | undefined;
data?: { [key: string]: any } | undefined;
}
export class Inline extends BaseNode {
object: "inline";
nodes: Immutable.List<Inline | Text>;
static create(
properties:
| InlineProperties
| InlineJSON
| Inline
| string,
): Inline;
static createList(
elements?:
| Immutable.List<InlineProperties | InlineJSON | Inline | string>
| Array<InlineProperties | InlineJSON | Inline | string>,
): Immutable.List<Inline>;
static fromJSON(
properties:
| InlineProperties
| InlineJSON
| Inline,
): Inline;
static fromJS(
properties:
| InlineProperties
| InlineJSON
| Inline,
): Inline;
static isInline(maybeInline: any): maybeInline is Inline;
static isInlineList(
maybeInlineList: any,
): maybeInlineList is Immutable.List<Inline>;
toJSON(): InlineJSON;
toJS(): InlineJSON;
}
export interface TextProperties {
object?: "text" | undefined;
key?: string | undefined;
text?: string | undefined;
marks?: Immutable.Set<Mark> | Mark[] | undefined;
}
export interface TextJSON {
object?: "text" | undefined;
key?: string | undefined;
text?: string | undefined;
marks?: MarkJSON[] | undefined;
}
export interface LeafAndOffset {
startOffset: number;
endOffset: number;
index: number;
leaf: Leaf;
}
export class Text extends Immutable.Record({}) {
object: "text";
key: string;
readonly text: string;
readonly marks: Immutable.Set<Mark> | null;
static create(properties?: TextProperties | TextJSON | Text | string): Text;
static createList(
elements?:
| Array<TextProperties | TextJSON | Text | string>
| Immutable.List<TextProperties | TextJSON | Text | string>,
): Immutable.List<Text>;
static fromJSON(properties: TextJSON | TextProperties | Text): Text;
static fromJS(properties: TextJSON | TextProperties | Text): Text;
static isText(maybeText: any): maybeText is Text;
static isTextList(maybeTextList: any): maybeTextList is Immutable.List<Text>;
toJSON(options?: { preserveKeys?: boolean | undefined }): TextJSON;
toJS(options?: { preserveKeys?: boolean | undefined }): TextJSON;
addMark(mark: MarkProperties | MarkJSON | Mark | string): Text;
addMarks(
marks:
| Array<MarkProperties | MarkJSON | Mark | string>
| Immutable.Set<MarkProperties | MarkJSON | Mark | string>,
): Text;
getKeysToPathsTable(): { [key: string]: number[] };
getLeaves(
annotations: Immutable.Map<string, Annotation>,
decorations?: Decoration[] | Immutable.List<Decoration>,
): Immutable.List<Leaf>;
getFirstText(): Text | null;
getLastText(): Text | null;
getText(): string;
getNode(path: Path): Node | null;
getPath(key: Immutable.List<number> | string | Node): Immutable.List<number> | null;
hasNode(path: Path): boolean;
insertText(index: number, string: string): Text;
regenerateKey(): Text;
removeMark(mark: MarkProperties | MarkJSON | Mark | string): Text;
removeText(index: number, length: number): Text;
resolvePath(path: Path, index?: number): Immutable.List<number>;
setMark(
properties: MarkProperties | MarkJSON | Mark | string,
newProperties: MarkProperties,
): Text;
splitText(index: number): Text[];
mergeText(other: Text): Text;
normalize(editor: Editor): () => void | void;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
validate(editor: Editor): Error | void;
}
export interface LeafProperties {
object?: "leaf" | undefined;
marks?: Immutable.Set<Mark> | Mark[] | undefined;
text?: string | undefined;
}
export interface LeafJSON {
object?: "leaf" | undefined;
marks?: MarkJSON[] | undefined;
text?: string | undefined;
}
export class Leaf extends Immutable.Record({}) {
object: "leaf";
marks: Immutable.Set<Mark> | null;
text: string;
static create(properties: LeafProperties | LeafJSON | Leaf): Leaf;
static createLeaves(leaves: Immutable.List<Leaf>): Immutable.List<Leaf>;
static splitLeaves(
leaves: Immutable.List<Leaf>,
offset: number,
): Array<Immutable.List<Leaf>>;
static createList(
attrs?:
| Array<LeafProperties | LeafJSON | Leaf>
| Immutable.List<LeafProperties | LeafJSON | Leaf>,
): Immutable.List<Leaf>;
static fromJSON(properties: LeafJSON | LeafProperties): Leaf;
static fromJS(properties: LeafJSON | LeafProperties): Leaf;
static isLeaf(maybeLeaf: any): maybeLeaf is Leaf;
static isLeafList(
maybeLeafList: any,
): maybeLeafList is Immutable.List<Leaf>;
updateMark(mark: Mark, newMark: Mark): Leaf;
addMarks(marks: Immutable.Set<Mark>): Leaf;
addMark(mark: Mark): Leaf;
removeMark(mark: Mark): Leaf;
insertText(offset: number, string: string): Leaf;
toJSON(): LeafJSON;
toJS(): LeafJSON;
}
interface IterableOptions {
direction?: string | undefined;
downward?: boolean | undefined;
upward?: boolean | undefined;
includeBlocks?: boolean | undefined;
includeDocument?: boolean | undefined;
includeInlines?: boolean | undefined;
includeRoot?: boolean | undefined;
includeTarget?: boolean | undefined;
includeTargetAncestors?: boolean | undefined;
includeTexts?: boolean | undefined;
match?: ((node: Node, path: Immutable.List<number>) => boolean | null) | undefined;
range?: RangeProperties | RangeJSON | Range | undefined;
path?: Path | undefined;
}
export namespace NodeFactory {
function create(attrs: Node | NodeJSON | NodeProperties): Node;
function createList(
elements?:
| Array<Node | NodeJSON | NodeProperties>
| Immutable.List<Node | NodeJSON | NodeProperties>,
): Immutable.List<Node>;
function createProperties(
attrs?: Block | Inline | string | { type?: string | undefined; data?: object | undefined },
): NodeProperties;
function fromJSON(value: { [key: string]: any }): NodeJSON;
function fromJS(value: { [key: string]: any }): NodeJSON;
function isNode(maybeNode: any): maybeNode is Node;
function isNodeList(maybeNodeList: any): maybeNodeList is Immutable.List<Node>;
}
export type Node = Document | Block | Inline | Text;
export type NodeJSON = DocumentJSON | BlockJSON | InlineJSON | TextJSON;
export type NodeProperties =
| DocumentProperties
| BlockProperties
| InlineProperties
| TextProperties;
declare class BaseNode extends Immutable.Record({}) {
data: Data;
type: string;
key: string;
object: "document" | "block" | "inline" | "text";
nodes: Immutable.List<Node>;
readonly text: string;
static isNode(maybeNode: any): maybeNode is Node;
static isNodeList(
maybeNodeList: any,
): maybeNodeList is Immutable.List<Node>;
static createProperties(
attrs: NodeProperties | string | Node,
): NodeProperties;
static fromJSON(value: NodeJSON | NodeProperties | Node): Node;
static fromJS(value: NodeJSON | NodeProperties | Node): Node;
addMark(path: Path, mark: Mark): Node;
ancestors(path: Path): Iterable<[Node, Immutable.List<number>]>;
blocks(
options?: IterableOptions & {
onlyLeaves?: boolean | undefined;
onlyRoots?: boolean | undefined;
onlyTypes?: string[] | undefined;
},
): Iterable<[Block, Immutable.List<number>]>;
createAnnotation(properties: AnnotationProperties | AnnotationJSON | Annotation): Annotation;
createDecoration(properties: DecorationProperties | DecorationJSON | Decoration): Decoration;
createIterable(options?: IterableOptions): Iterable<[Node, Immutable.List<number>]>;
createPoint(properties: PointProperties | PointJSON | Point): Point;
createRange(properties: RangeTypeProperties | RangeTypeJSON | RangeType): Range;
createSelection(properties: SelectionProperties | SelectionJSON | Selection | Range): Selection;
descendants(options?: IterableOptions): Iterable<[Node, Immutable.List<number>]>;
filterDescendants(predicate?: (node: Node, path: Immutable.List<number>) => boolean): Immutable.List<Node>;
findDescendant(predicate?: (node: Node, path: Immutable.List<number>) => boolean): Node | null;
forEachDescendant(predicate?: (node: Node, path: Immutable.List<number>) => boolean): void;
getActiveMarksAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.Set<Mark>;
getAncestors(path: Path): Immutable.List<Node> | null;
getBlocks(): Immutable.List<Block>;
getBlocksByType(type: string): Immutable.List<Block>;
getChild(path: Path): Node | null;
getClosest(path: Path, predicate: (node: Node, path: Immutable.List<number>) => boolean): Node | null;
getClosestBlock(path: Path): Block | null;
getClosestInline(path: Path): Inline | null;
getClosestVoid(path: Path, editor: Editor): Node | null;
getCommonAncestor(a: Path, b: Path): Node | null;
getDecorations(editor: Editor): Immutable.List<Decoration>;
getDepth(path: Path, startAt?: number): number | null;
getDescendant(path: Path): Node | null;
getDescendantsAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Node>;
getFirstText(): Text | null;
getFragmentAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Document;
getFurthest(path: Path, predicate?: (node: Node, path: Immutable.List<number>) => boolean): Node | null;
getFurthestBlock(path: Path): Block | null;
getFurthestChild(path: Path): Node | null;
getFurthestInline(path: Path): Inline | null;
getInlines(): Immutable.List<Inline>;
getInlinesByType(type: string): Immutable.List<Inline>;
getInsertMarksAtPoint(point: PointProperties | PointJSON | Point): Immutable.Set<Mark>;
getInsertMarksAtRange(range: RangeProperties | RangeJSON | Range): Immutable.Set<Mark>;
getKeysToPathsTable(): { [key: string]: number[] };
getLastText(): Text | null;
getLeafBlocksAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Block>;
getLeafInlinesAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Inline>;
getNode(path: Path): Node | null;
getNodesToPathsMap(): Map<Node, Immutable.List<number>>;
getMarks(): Immutable.OrderedSet<Mark>;
getMarksAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.OrderedSet<Mark>;
getMarksByType(type: string): Immutable.OrderedSet<Mark>;
getNextBlock(path: Path): Block | null;
getNextNode(path: Path): Node | null;
getNextSibling(path: Path): Node | null;
getNextText(path: Path): Text | null;
getOffset(path: Path): number;
getOffsetAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): number;
getParent(path: Path): Node | null;
getPath(key: Immutable.List<number> | string | Node): Immutable.List<number> | null;
getPreviousBlock(path: Path): Block | null;
getPreviousNode(path: Path): Node | null;
getPreviousSibling(path: Path): Node | null;
getPreviousText(path: Path): Text | null;
getRootBlocksAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Block>;
getRootInlinesAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Inline>;
getText(): string;
getTextAtOffset(offset: number): Text | null;
getTextDirection(): string | null;
getTexts(): Immutable.List<Text>;
getTextsAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.List<Text>;
hasBlockChildren(): boolean;
hasChild(path: Path): boolean;
hasInlineChildren(): boolean;
hasDescendant(path: Path): boolean;
hasNode(path: Path): boolean;
hasVoidParent(path: Path, editor: Editor): boolean;
inlines(
options?: IterableOptions & {
onlyLeaves?: boolean | undefined;
onlyRoots?: boolean | undefined;
onlyTypes?: string[] | undefined;
},
): Iterable<[Inline, Immutable.List<number>]>;
insertNode(path: Path, node: Node): Node;
insertText(
path: Path,
offset: number,
text: string,
): Node;
isLeafBlock(): this is Block;
isLeafInline(): this is Inline;
isInRange(path: Path, range: RangeTypeProperties | RangeTypeJSON | RangeType): boolean;
mapChildren(predicate?: (node: Node, index: number, nodes: Immutable.List<Node>) => Node): Node;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
mapDescendants(predicate?: (node: Node, index: number, nodes: Immutable.List<Node>) => Node): Node | void;
marks(options?: IterableOptions & { onlyTypes: string[] }): Iterable<[Mark, Node, Immutable.List<number>]>;
mergeNode(path: Path): Node;
moveNode(path: Path, newPath: Path, newIndex?: number): Node;
normalize(editor: Editor): () => void | void;
regenerateKey(): Node;
removeMark(path: Path, mark: Mark): Node;
removeNode(path: Path): Node;
removeText(path: Path, offset: number, text: string): Node;
replaceNode(path: Path, node: Node): Node;
resolveAnnotation(annotation: Annotation | AnnotationProperties | AnnotationJSON): Annotation;
resolveDecoration(decoration: RangeType | RangeTypeProperties | RangeTypeJSON): Decoration;
resolvePath(path: Path, index?: number): Immutable.List<number>;
resolvePoint(point: Point | PointProperties | PointJSON): Point;
resolveRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Range;
resolveSelection(selection: Selection | SelectionProperties | SelectionJSON | Range): Selection;
setNode(path: Path, properties: NodeProperties): Node;
setMark(
path: Path,
properties: MarkProperties,
newProperties: MarkProperties,
): Node;
siblings(path: Path, options?: IterableOptions): Iterable<[Node, Immutable.List<number>]>;
splitNode(path: Path, position: number, properties: NodeProperties): Node;
texts(options: IterableOptions): Iterable<[Text, Immutable.List<number>]>;
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
validate(editor: Editor): Error | void;
/**
* Deprecated.
*/
getBlocksAtRange(range: RangeProperties | RangeJSON | Range): Immutable.List<Block>;
getBlocksAtRangeAsArray(range: RangeProperties | RangeJSON | Range): Block[];
getInlinesAtRange(range: RangeProperties | RangeJSON | Range): Immutable.List<Inline>;
getInlinesAtRangeAsArray(range: RangeProperties | RangeJSON | Range): Inline[];
getNextTextAndPath(path: Path): Text | null;
getNextDeepMatchingNodeAndPath(
path: Immutable.List<number>,
iterator?: () => boolean,
): null | [Node, Immutable.List<number>];
getPreviousTextAndPath(path: Path): Text | null;
findFirstDescendantAndPath(
iterator: (
node: Node,
path: Immutable.List<number>,
nodes: Immutable.List<Node>,
) => boolean,
pathToThisNode: Immutable.List<number>,
): [Node, Immutable.List<number>] | null;
getPreviousMatchingNodeAndPath(
path: Immutable.List<number>,
iterator?: (node: Node) => boolean,
): [Node, Immutable.List<number>] | null;
getPreviousDeepMatchingNodeAndPath(
path: Immutable.List<number>,
iterator?: (node: Node) => boolean,
): [Node, Immutable.List<number>] | null;
findLastDescendantAndPath(
iterator: (
node: Node,
path: Immutable.List<number>,
nodes: Immutable.List<Node>,
) => boolean,
pathToThisNode: Immutable.List<number>,
): [Node, Immutable.List<number>] | null;
findDescendantAndPath(
iterator: (
node: Node,
path: Immutable.List<number>,
nodes: Immutable.List<Node>,
) => boolean,
path?: Immutable.List<number>,
findLast?: boolean,
): [Node, Immutable.List<number>] | null;
forEachDescendantWithPath(
iterator: (
node: Node,
path: Immutable.List<number>,
nodes: Immutable.List<Node>,
) => boolean,
path?: Immutable.List<number>,
findLast?: boolean,
): boolean;
getNextMatchingNodeAndPath(
path: Immutable.List<number>,
iterator?: (node: Node) => boolean,
): [Node, Immutable.List<number>] | null;
getSelectionIndexes(range: RangeType, isSelected?: boolean): { start: number; end: number } | boolean | null;
getTextsBetweenPositionsAsArray(startPath: Path, endPath: Path): Array<Node | null>;
getOrderedMarksBetweenPositions(
startPath: Path,
startOffset: number,
endPath: Path,
endOffset: number,
): Immutable.OrderedSet<Mark>;
getTextsBetweenPathPositionsAsArray(
startPath: Immutable.List<number>,
endPath: Immutable.List<number>,
): Array<Node | null>;
getFurthestAncestor(path: Path): Node | null;
getLeafBlocksAtRangeAsArray(range: Range | RangeProperties | RangeJSON): Block[];
getLeafBlocksBetweenPathPositionsAsArray(
startPath: Immutable.List<number>,
endPath: Immutable.List<number>,
): Block[];
getBlocksAsArray(): Block[];
getBlocksByTypeAsArray(type: string): Block[];
getFurthestOnlyChildAncestor(path: Path): Node | null;
getInlinesAsArray(): Inline[];
getInlinesByTypeAsArray(type: string): Inline[];
getLeafInlinesAtRangeAsArray(range: Range | RangeProperties | RangeJSON): Inline[];
getOrderedMarks(): Immutable.OrderedSet<Mark>;
getOrderedMarksAtRange(range: RangeProperties | RangeJSON | Range): Immutable.OrderedSet<Mark>;
getOrderedMarksByType(type: string): Immutable.OrderedSet<Mark>;
getOrderedMarksByTypeAsArray(type: string): Mark[];
getMarksAsArray(): Mark[];
getRootInlinesAtRangeAsArray(range: RangeProperties | RangeJSON | Range): Inline[];
getTextsAsArray(): Text[];
getTextsAtRangeAsArray(range: RangeProperties | RangeJSON | Range): Text[];
getMarksAtPosition(path: Path, offset: number): Immutable.OrderedSet<Mark>;
getNodesAtRange(range: RangeProperties | RangeJSON | Range): boolean;
isNodeInRange(path: Path, range: RangeProperties | RangeJSON | Range): boolean;
/**
* Assertion variants.
*/
assertChild(path: Path): Node;
assertDepth(path: Path, startAt?: number): number;
assertDescendant(path: Path): Node;
assertNode(path: Path): Node;
assertParent(path: Path): Node;
assertPath(key: Path): Immutable.List<number>;
}
export interface MarkProperties {
object?: "mark" | undefined;
type: string;
data?: Data | { [key: string]: any } | undefined;
}
export interface MarkJSON {
object?: "mark" | undefined;
type: string;
data?: { [key: string]: any } | undefined;
}
export class Mark extends Immutable.Record({}) {
object: "mark";
type: string;
data: Data;
static create(properties: MarkProperties | MarkJSON | Mark | string): Mark;
static createSet(
element?:
| Array<MarkProperties | MarkJSON | Mark | string>
| Immutable.Set<MarkProperties | MarkJSON | Mark | string>,
): Immutable.Set<Mark>;
static createProperties(attrs: Partial<MarkProperties | MarkJSON | Mark | string>): MarkProperties;
static fromJSON(properties: MarkProperties | MarkJSON | Mark): Mark;
static fromJS(properties: MarkProperties | MarkJSON | Mark): Mark;
static isMark(maybeMark: any): maybeMark is Mark;
static isMarkSet(maybeMarkSet: any): maybeMarkSet is Immutable.Set<Mark>;
toJSON(): MarkJSON;
toJS(): MarkJSON;
}
export interface SelectionProperties {
object?: "selection" | undefined;
anchor?: Point | undefined;
focus?: Point | undefined;
isFocused?: boolean | undefined;
marks?: Immutable.Set<Mark> | Mark[] | undefined;
}
export interface SelectionJSON {
object?: "selection" | undefined;
anchor?: PointJSON | undefined;
focus?: PointJSON | undefined;
isFocused?: boolean | undefined;
marks?: MarkJSON[] | undefined;
}
export class Selection extends BaseRange {
object: "selection";
anchor: Point;
focus: Point;
isFocused: boolean;
marks: Immutable.Set<Mark>;
readonly isBlurred: boolean;
static create(
properties:
| RangeTypeProperties
| RangeTypeJSON
| RangeType,
): Selection;
static createProperties(
attrs:
| RangeTypeProperties
| RangeTypeJSON
| RangeType
| string,
): SelectionProperties;
static fromJSON(
properties:
| RangeTypeProperties
| RangeTypeJSON,
): Selection;
static fromJS(
properties:
| RangeTypeProperties
| RangeTypeJSON,
): Selection;
toJSON(): SelectionJSON;
toJS(): SelectionJSON;
isSelection(maybeSelection: any): maybeSelection is Selection;
setIsFocused(value: boolean): Selection;
setMarks(marks: Immutable.Set<Mark>): Selection;
setProperties(
properties:
| RangeTypeProperties
| RangeTypeJSON
| RangeType
| string,
): Selection;
}
export interface RangeProperties {
object?: "range" | undefined;
anchor?: Point | undefined;
focus?: Point | undefined;
}
export interface RangeJSON {
object?: "range" | undefined;
anchor?: PointJSON | undefined;
focus?: PointJSON | undefined;
}
export class Range extends BaseRange {
object: "range";
anchor: Point;
focus: Point;
static create(properties: RangeTypeProperties | RangeTypeJSON | RangeType): Range;
static createList(
elements?:
| Array<RangeTypeProperties | RangeTypeJSON | RangeType>
| Immutable.List<RangeTypeProperties | RangeTypeJSON | RangeType>,
): Immutable.List<Range>;
static createProperties(
attrs: RangeTypeProperties | RangeTypeJSON | RangeType,
): RangeProperties;
static fromJSON(properties: RangeTypeJSON): Range;
static fromJS(properties: RangeTypeJSON): Range;
static isRange(maybeRange: any): maybeRange is RangeType;
toJSON(options?: { preserveKeys?: boolean | undefined }): RangeJSON;
toJS(options?: { preserveKeys?: boolean | undefined }): RangeJSON;
}
export interface DecorationProperties {
object?: "decoration" | undefined;
anchor?: Point | undefined;
focus?: Point | undefined;
type?: string | undefined;
data?: Data | { [key: string]: any } | undefined;
}
export interface DecorationJSON {
object?: "decoration" | undefined;
anchor?: PointJSON | undefined;
focus?: PointJSON | undefined;
type?: string | undefined;
data?: { [key: string]: any } | undefined;
}
export class Decoration extends BaseRange {
object: "decoration";
anchor: Point;
focus: Point;
type: string;
data: Data;
static create(
properties:
| RangeTypeProperties
| RangeTypeJSON
| RangeType,
): Decoration;
static createList(
elements?:
| Array<RangeTypeProperties | RangeTypeJSON | RangeType>
| Immutable.List<RangeTypeProperties | RangeTypeJSON | RangeType>,
): Immutable.List<Decoration>;
static createProperties(
attrs: RangeTypeProperties | RangeTypeJSON | RangeType,
): DecorationProperties;
static fromJSON(properties: DecorationJSON & { mark?: MarkJSON | undefined }): Decoration;
static fromJSON(properties: DecorationJSON & { mark?: MarkJSON | undefined }): Decoration;
static isDecoration(maybeDecoration: any): maybeDecoration is Decoration;
setProperties(properties: RangeTypeProperties | RangeTypeJSON | RangeType): Decoration;
toJSON(): DecorationJSON;
toJS(): DecorationJSON;
}
export interface AnnotationProperties {
object?: "annotation" | undefined;
key: string;
type: string;
data?: Data | { [key: string]: any } | undefined;
anchor?: Point | undefined;
focus?: Point | undefined;
}
export interface AnnotationJSON {
object?: "annotation" | undefined;
key: string;
type: string;
data?: { [key: string]: any } | undefined;
anchor?: PointJSON | undefined;
focus?: PointJSON | undefined;
}
export class Annotation extends BaseRange {
object: "annotation";
key: string;
type: string;
data: Data;
anchor: Point;
focus: Point;
static create(properties: Annotation | AnnotationProperties | AnnotationJSON): Annotation;
static createMap(
elements?:
| { [key: string]: Annotation | AnnotationProperties | AnnotationJSON }
| Immutable.Map<string, Annotation>,
): Immutable.Map<string, Annotation>;
static createProperties(
attrs: AnnotationProperties | AnnotationJSON | Annotation,
): AnnotationProperties;
static fromJSON(properties: AnnotationProperties | AnnotationJSON): Annotation;
static fromJS(properties: AnnotationProperties | AnnotationJSON): Annotation;
static isAnnotation(maybeAnnotation: any): maybeAnnotation is Annotation;
toJSON(): AnnotationJSON;
toJS(): AnnotationJSON;
setProperties(properties: AnnotationProperties | AnnotationJSON | Annotation): Annotation;
}
export type RangeTypeProperties =
| RangeProperties
| SelectionProperties
| DecorationProperties
| AnnotationProperties;
export type RangeTypeJSON = RangeJSON | SelectionJSON | DecorationJSON | AnnotationJSON;
export type RangeType = Range | Selection | Decoration | Annotation;
declare class BaseRange extends Immutable.Record({}) {
readonly isCollapsed: boolean;
readonly isExpanded: boolean;
readonly isBackward: boolean;
readonly isForward: boolean;
readonly isUnset: boolean;
readonly isSet: boolean;
readonly start: Point;
readonly end: Point;
flip(): RangeType;
moveForward(n?: number): RangeType;
moveBackward(n?: number): RangeType;
moveAnchorBackward(n?: number): RangeType;
moveAnchorForward(n?: number): RangeType;
moveAnchorTo(path: string | number | Immutable.List<number>, offset?: number): RangeType;
moveAnchorToStartOfNode(node: Node): RangeType;
moveAnchorToEndOfNode(node: Node): RangeType;
moveEndBackward(n?: number): RangeType;
moveEndForward(n?: number): RangeType;
moveEndTo(path: string | number | Immutable.List<number>, offset?: number): RangeType;
moveEndToStartOfNode(node: Node): RangeType;
moveEndToEndOfNode(node: Node): RangeType;
moveFocusBackward(n?: number): RangeType;
moveFocusForward(n?: number): RangeType;
moveFocusTo(path: string | number | Immutable.List<number>, offset?: number): RangeType;
moveFocusToStartOfNode(node: Node): RangeType;
moveFocusToEndOfNode(node: Node): RangeType;
moveStartBackward(n?: number): RangeType;
moveStartForward(n?: number): RangeType;
moveStartTo(path: string | number | Immutable.List<number>, offset?: number): RangeType;
moveStartToStartOfNode(node: Node): RangeType;
moveStartToEndOfNode(node: Node): RangeType;
moveToAnchor(): RangeType;
moveToEnd(): RangeType;
moveToEndOfNode(node: Node): RangeType;
moveToFocus(): RangeType;
moveToRangeOfNode(start: Node, end?: Node): RangeType;
moveToStart(): RangeType;
moveToStartOfNode(node: Node): RangeType;
normalize(node: Node): RangeType;
setAnchor(anchor: Point): RangeType;
setEnd(point: Point): RangeType;
setFocus(focus: Point): RangeType;
setIsAtomic(value: boolean): RangeType;
setIsFocused(value: boolean): RangeType;
setMarks(marks: Immutable.Set<Mark>): RangeType;
setPoints(values: Point[]): RangeType;
updatePoints(updater: (point: Point) => Point): RangeType;
setStart(point: Point): RangeType;
setProperties(
properties: RangeTypeProperties | RangeTypeJSON | RangeType,
): RangeType;
toJSON(): RangeTypeJSON;
toJS(): RangeTypeJSON;
toRange(): RangeType;
unset(): RangeType;
}
export interface PointProperties {
object?: "point" | undefined;
key?: string | undefined;
offset?: number | undefined;
path?: Immutable.List<number> | undefined;
}
export interface PointJSON {
object?: "point" | undefined;
key?: string | undefined;
offset?: number | undefined;
path?: number[] | undefined;
}
export class Point extends Immutable.Record({}) {
object: "point";
key: string;
offset: number;
path: Immutable.List<number>;
static create(properties: PointProperties | PointJSON | Point): Point;
static createProperties(properties: PointProperties | PointJSON | Point): Point;
static fromJSON(properties: PointJSON | PointProperties): Point;
static fromJS(properties: PointJSON | PointProperties): Point;
static isPoint(maybePoint: any): maybePoint is Point;
readonly isSet: boolean;
readonly isUnset: boolean;
isAfterPoint(point: Point): boolean;
isAfterRange(range: RangeType): boolean;
isAtEndofRange(range: RangeType): boolean;
isAtStartOfRange(range: RangeType): boolean;
isBeforePoint(point: Point): boolean;
isBeforeRange(range: RangeType): boolean;
isInRange(range: RangeType): boolean;
isAtEndOfNode(node: Node): boolean;
isAtStartOfNode(node: Node): boolean;
isInNode(node: Node): boolean;
moveBackward(n?: number): this;
moveForward(n?: number): this;
moveTo(path: string | number | Immutable.List<number>, offset?: number): this;
moveToStartOfNode(node: Node): this;
moveToEndOfNode(node: Node): this;
normalize(node: Node): this;
setKey(key: string): this;
setOffset(offset: number): this;
setPath(path: Immutable.List<number> | number[]): this;
toJSON(options?: { preserveKeys?: boolean | undefined }): PointJSON;
toJS(options?: { preserveKeys?: boolean | undefined }): PointJSON;
unset(): this;
}
export type Operation =
| InsertTextOperation
| RemoveTextOperation
| AddMarkOperation
| RemoveMarkOperation
| SetMarkOperation
| AddAnnotationOperation
| RemoveAnnotationOperation
| SetAnnotationOperation
| InsertNodeOperation
| MergeNodeOperation
| MoveNodeOperation
| RemoveNodeOperation
| SetNodeOperation
| SplitNodeOperation
| SetSelectionOperation
| SetValueOperation;
export interface OperationProperties {
object?: "operation" | undefined;
type: string;
text?: string | undefined;
target?: number | undefined;
properties?:
| NodeProperties
| ValueProperties
| SelectionProperties
| AnnotationProperties
| undefined;
position?: number | undefined;
path?: Immutable.List<number> | undefined;
offset?: number | undefined;
node?: Node | undefined;
newProperties?:
| NodeProperties
| ValueProperties
| SelectionProperties
| MarkProperties
| AnnotationProperties
| undefined;
newPath?: Immutable.List<number> | undefined;
mark?: Mark | undefined;
data?: Data | { [key: string]: any } | undefined;
annotation?: Annotation | undefined;
}
export interface OperationJSON {
object?: "operation" | undefined;
type: string;
text?: string | undefined;
target?: number | undefined;
properties?:
| NodeJSON
| ValueJSON
| SelectionJSON
| AnnotationJSON
| undefined;
position?: number | undefined;
path?: number[] | undefined;
offset?: number | undefined;
node?: Node | undefined;
newProperties?:
| NodeJSON
| ValueJSON
| SelectionJSON
| MarkJSON
| AnnotationJSON
| undefined;
newPath?: number[] | undefined;
mark?: MarkJSON | undefined;
data?: { [key: string]: any } | undefined;
annotation?: AnnotationJSON | undefined;
}
export class BaseOperation extends Immutable.Record({}) {
object: "operation";
type: string;
static create(attrs?: Operation | OperationProperties | OperationJSON): Operation;
static createList():
| Immutable.List<Operation | OperationProperties | OperationJSON>
| Array<Operation | OperationProperties | OperationJSON>;
static fromJSON(object: OperationProperties | OperationJSON): Operation;
static fromJS(object: OperationProperties | OperationJSON): Operation;
static isOperation(maybeOperation: any): maybeOperation is Operation;
static isOperationList(maybeOperationList: any): maybeOperationList is Immutable.List<Operation>;
toJSON(): OperationJSON;
apply(value: Value): Value;
invert(): this;
}
export class InsertTextOperation extends BaseOperation {
type: "insert_text";
path: Immutable.List<number>;
offset: number;
text: string;
data: Data;
}
export class RemoveTextOperation extends BaseOperation {
type: "remove_text";
path: Immutable.List<number>;
offset: number;
text: string;
data: Data;
}
export class AddMarkOperation extends BaseOperation {
type: "add_mark";
path: Immutable.List<number>;
mark: Mark;
data: Data;
}
export class RemoveMarkOperation extends BaseOperation {
type: "remove_mark";
path: Immutable.List<number>;
mark: Mark;
data: Data;
}
export class SetMarkOperation extends BaseOperation {
type: "set_mark";
path: Immutable.List<number>;
properties: MarkProperties;
newProperties: MarkProperties;
data: Data;
}
export class AddAnnotationOperation extends BaseOperation {
type: "add_annotation";
annotation: Annotation;
data: Data;
}
export class RemoveAnnotationOperation extends BaseOperation {
type: "remove_annotation";
annotation: Annotation;
data: Data;
}
export class SetAnnotationOperation extends BaseOperation {
type: "set_annotation";
properties: AnnotationProperties;
newProperties: AnnotationProperties;
data: Data;
}
export class InsertNodeOperation extends BaseOperation {
type: "insert_node";
path: Immutable.List<number>;
node: Node;
data: Data;
}
export class MergeNodeOperation extends BaseOperation {
type: "merge_node";
path: Immutable.List<number>;
position: number;
properties: NodeProperties;
data: Data;
}
export class MoveNodeOperation extends BaseOperation {
type: "move_node";
path: Immutable.List<number>;
newPath: Immutable.List<number>;
data: Data;
}
export class RemoveNodeOperation extends BaseOperation {
type: "remove_node";
path: Immutable.List<number>;
node: Node;
data: Data;
}
export class SetNodeOperation extends BaseOperation {
type: "set_node";
path: Immutable.List<number>;
properties: NodeProperties;
newProperties: NodeProperties;
data: Data;
}
export class SplitNodeOperation extends BaseOperation {
type: "split_node";
path: Immutable.List<number>;
position: number;
target: number;
properties: NodeProperties;
data: Data;
}
export class SetSelectionOperation extends BaseOperation {
type: "set_selection";
properties: SelectionProperties;
newProperties: SelectionProperties;
data: Data;
}
export class SetValueOperation extends BaseOperation {
type: "set_value";
properties: ValueProperties;
newProperties: ValueProperties;
data: Data;
}
export type ErrorCode =
| "child_max_invalid"
| "child_min_invalid"
| "child_object_invalid"
| "child_required"
| "child_type_invalid"
| "child_unknown"
| "first_child_object_invalid"
| "first_child_type_invalid"
| "last_child_object_invalid"
| "last_child_type_invalid"
| "next_sibling_object_invalid"
| "next_sibling_type_invalid"
| "node_data_invalid"
| "node_is_void_invalid"
| "node_mark_invalid"
| "node_object_invalid"
| "node_text_invalid"
| "node_type_invalid"
| "parent_object_invalid"
| "parent_type_invalid"
| "previous_sibling_object_invalid"
| "previous_sibling_type_invalid";
export class SlateError extends Error {
code: ErrorCode;
[key: string]: any;
}
export namespace KeyUtils {
function create(key?: string): string;
function setGenerator(func: () => any): void;
function resetGenerator(): void;
}
export type useMemoization = (enabled: boolean) => void;
export type resetMemoization = () => void;
export namespace PathUtils {
/**
* Compare paths `path` and `target` to see which is before or after.
*/
function compare(
path: Immutable.List<number>,
target: Immutable.List<number>,
): number | null;
/**
* Create a path from `attrs`.
*/
function create(
attrs: Immutable.List<number> | number[],
): Immutable.List<number>;
/**
* Crop paths `a` and `b` to an equal size, defaulting to the shortest.
*/
function crop(
a: Immutable.List<number>,
b: Immutable.List<number>,
size?: number,
): Array<Immutable.List<number>>;
/**
* Decrement a `path` by `n` at `index`, defaulting to the last index.
*/
function decrement(
path: Immutable.List<number>,
n?: number,
index?: number,
): Immutable.List<number>;
/**
* Get all ancestor paths of the given path.
*/
function getAncestors(
path: Immutable.List<number>,
): Immutable.List<number>;
/**
* Increment a `path` by `n` at `index`, defaulting to the last index.
*/
function increment(
path: Immutable.List<number>,
n?: number,
index?: number,
): Immutable.List<number>;
/**
* Is a `path` above another `target` path?
*/
function isAbove(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is a `path` after another `target` path in a document?
*/
function isAfter(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is a `path` before another `target` path in a document?
*/
function isBefore(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is a `path` equal to another `target` path in a document?
*/
function isEqual(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is a `path` older than a `target` path? Meaning that it ends as an older
* sibling of one of the indexes in the target.
*/
function isOlder(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is an `any` object a path?
*/
function isPath(
maybePath: any,
): maybePath is Immutable.List<number> | number[];
/**
* Is a `path` a sibling of a `target` path?
*/
function isSibling(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Is a `path` younger than a `target` path? Meaning that it ends as a younger
* sibling of one of the indexes in the target.
*/
function isYounger(
path: Immutable.List<number>,
target: Immutable.List<number>,
): boolean;
/**
* Lift a `path` to refer to its `n`th ancestor.
*/
function lift(
path: Immutable.List<number>,
n?: number,
): Immutable.List<number>;
/**
* Drop a `path`, returning a relative path from a depth of `n`.
*/
function drop(
path: Immutable.List<number>,
n?: number,
): Immutable.List<number>;
/**
* Get the maximum length of paths `a` and `b`.
*/
function max(
a: Immutable.List<number>,
b: Immutable.List<number>,
): number;
/**
* Get the minimum length of paths `a` and `b`.
*/
function min(
a: Immutable.List<number>,
b: Immutable.List<number>,
): number;
/**
* Get the common ancestor path of path `a` and path `b`.
*/
function relate(
a: Immutable.List<number>,
b: Immutable.List<number>,
): Immutable.List<number>;
/**
* Transform a `path` by an `operation`, adjusting it to stay current.
*/
function transform(
path: Immutable.List<number>,
operation: Operation | OperationJSON | OperationProperties,
): Immutable.List<Immutable.List<number>>;
}
export interface Command {
type: string;
args: any[];
}
export interface Query {
type: string;
args: any[];
}
export type CommandFunc<T extends Controller = Controller> = (editor: T, ...args: any[]) => T;
export type QueryFunc<T extends Controller = Controller> = (editor: T, ...args: any[]) => any;
export interface Plugin<T extends Controller = Controller> {
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
normalizeNode?: ((node: Node, editor: T, next: () => void) => ((editor: T) => void) | void) | undefined;
onChange?