From 82f27031043dd2f0333d2673405818c91fc50ef7 Mon Sep 17 00:00:00 2001 From: Irwan Fario Subastian Date: Fri, 24 Aug 2018 14:01:03 +1000 Subject: [PATCH 1/4] update slate definition to 0.40 --- types/slate/index.d.ts | 1912 +++++++++++++++++++++++++----------- types/slate/slate-tests.ts | 54 +- 2 files changed, 1357 insertions(+), 609 deletions(-) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 30c0b5a376..47d3983328 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for slate 0.33 +// Type definitions for slate 0.40 // Project: https://github.com/ianstormtaylor/slate // Definitions by: Andy Kent // Jamie Talbot @@ -6,758 +6,1508 @@ // Brandon Shelton // Kalley Powell // Francesco Agnoletto +// Irwan Fario Subastian // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as Immutable from 'immutable'; +import * as Immutable from "immutable"; -export class Data { - [key: string]: any; - static create(options: Data): Data; - static fromJSON(object: Record): Data; - static fromJS(object: Record): Data; +export class Data extends Immutable.Record({}) { + [key: string]: any; + + static create(properties: object): Data; + static fromJSON(object: object): Data; + static fromJS(object: object): Data; } export interface RulesByNodeType { - [key: string]: Rules; + [key: string]: Rules; } -export interface ObjectsAndTypes { - objects?: string[]; - types?: string[]; +export interface ObjectAndType { + object?: string; + types?: string; } -export type InvalidReason = - | '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' - | 'node_data_invalid' - | 'node_is_void_invalid' - | 'node_mark_invalid' - | 'node_text_invalid' - | 'parent_object_invalid' - | 'parent_type_invalid'; - export interface Rules { - data?: { - [key: string]: (v: any) => boolean; - }; - first?: ObjectsAndTypes; - isVoid?: boolean; - last?: ObjectsAndTypes; - nodes?: Array<{ - objects?: string[]; - types?: string[]; - min?: number; - max?: number; - }>; - normalize?: ( - change: Change, - reason: InvalidReason, - context: Record - ) => void; - parent?: ObjectsAndTypes; - text?: RegExp; + data?: { + [key: string]: (v: any) => boolean; + }; + first?: ObjectAndType | ObjectAndType[]; + isVoid?: boolean; + last?: ObjectAndType | ObjectAndType[]; + nodes?: Array<{ + min?: number; + max?: number; + match?: ObjectAndType | ObjectAndType[]; + }>; + normalize?: (change: Change, error: SlateError) => void; + parent?: ObjectAndType | ObjectAndType[]; + text?: RegExp; } export interface SchemaProperties { - document?: Rules; - blocks?: RulesByNodeType; - inlines?: RulesByNodeType; + document?: Rules; + blocks?: RulesByNodeType; + inlines?: RulesByNodeType; } export class Schema extends Immutable.Record({}) { - document: Rules; - blocks: RulesByNodeType; - inlines: RulesByNodeType; + stack: Stack; + rules: Rules[]; - static create(properties: SchemaProperties | Schema): Schema; - static fromJSON(object: SchemaProperties): Schema; - static fromJS(object: SchemaProperties): Schema; - static isSchema(maybeSchema: any): maybeSchema is Schema; + static create(properties: SchemaProperties | Schema): Schema; + static fromJSON(object: SchemaProperties): Schema; + static fromJS(object: SchemaProperties): Schema; + static isSchema(maybeSchema: any): maybeSchema is Schema; - toJSON(): SchemaProperties; -} + validateNode(node: Node): Error | void; + testNode(node: Node): boolean; + assertNode(node: Node): boolean; + getNodeRules(node: Node): any[]; + isVoid(node: Node): boolean; + isAtomic(mark: Mark): boolean; + normalizeNode(node: Node): () => void; + testRules(object: any, rules: object | any[]): boolean; + validateRules( + object: any, + rule: object | any[], + rules: any[] | null, + options?: object + ): Error | void; -export interface HistoryJSON { - object?: 'history'; - redos?: Immutable.Stack; - undos?: Immutable.Stack; -} - -export class History extends Immutable.Record({ redos: Immutable.Stack(), undos: Immutable.Stack() }) { - object: 'history'; - - static create(properties: HistoryJSON | History): History; - static createOperationsList(operations: Operation[] | Immutable.List): Immutable.List; - static fromJSON(object: HistoryJSON): History; - static fromJS(object: HistoryJSON): History; - static isHistory(maybeHistory: any): maybeHistory is History; - - save(operation: Operation, options: { merge?: boolean, skip?: boolean }): History; - toJSON(): HistoryJSON; + toJSON(): SchemaProperties; + toJS(): SchemaProperties; } export interface ValueProperties { - document?: Document; - selection?: Range; - history?: History; - schema?: Schema; - data?: Record; - decorations?: Immutable.List | null; + document?: Document; + selection?: Range; + history?: History; + schema?: Schema; + data?: Data; + decorations?: Immutable.List | null; } export interface ValueJSON { - document?: DocumentJSON; - selection?: Range; - history?: History; - schema?: Schema; - data?: Record; - decorations?: Immutable.List | null; - object?: 'value'; + document?: DocumentJSON; + selection?: Range; + history?: History; + schema?: Schema; + data?: Data; + decorations?: Immutable.List | null; + object?: "value"; } +export type Path = Immutable.List | string; + export class Value extends Immutable.Record({}) { - document: Document; - selection: Range; - history: History; - schema: Schema; - data: Record; - object: 'value'; - decorations: Immutable.List | null; + document: Document; + selection: Range; + history: History; + schema: Schema; + data: Data; + object: "value"; + decorations: Immutable.List; - readonly anchorText: Text; - readonly focusText: Text; - readonly startText: Text; - readonly endText: Text; + readonly anchorText: Text; + readonly focusText: Text; + readonly startText: Text; + readonly endText: Text; + readonly nextText: Text; + readonly previousText: Text; - readonly anchorBlock: Block; - readonly focusBlock: Block; - readonly startBlock: Block; - readonly endBlock: Block; + readonly anchorBlock: Block; + readonly focusBlock: Block; + readonly startBlock: Block; + readonly endBlock: Block; + readonly nextBlock: Block; + readonly previousBlock: Block; - readonly anchorInline: Inline; - readonly focusInline: Inline; - readonly startInline: Inline; - readonly endInline: Inline; + readonly anchorInline: Inline; + readonly focusInline: Inline; + readonly startInline: Inline; + readonly endInline: Inline; + readonly nextInline: Inline; + readonly previousInline: Inline; - readonly marks: Immutable.Set; - readonly activeMarks: Immutable.Set; - readonly blocks: Immutable.List; - readonly fragment: Document; - readonly inlines: Immutable.List; - readonly text: Immutable.List; - readonly characters: Immutable.List; - readonly hasUndos: boolean; - readonly hasRedos: boolean; + readonly marks: Immutable.Set; + readonly activeMarks: Immutable.Set; + readonly blocks: Immutable.List; + readonly fragment: Document; + readonly inlines: Immutable.List; + readonly texts: Immutable.List; - readonly anchorKey: string; - readonly focusKey: string; - readonly startKey: string; - readonly endKey: string; - readonly anchorOffset: number; - readonly focusOffset: number; - readonly startOffset: number; - readonly endOffset: number; - readonly isBackward: boolean; - readonly isBlurred: boolean; - readonly isCollapsed: boolean; - readonly isExpanded: boolean; - readonly isFocused: boolean; - readonly isForward: boolean; + static create(properties?: ValueProperties | Value): Value; + static createProperties(attrs: ValueProperties | Value): ValueProperties; + static fromJSON(properties: ValueJSON): Value; + static fromJS(properties: ValueJSON): Value; + static isValue(maybeValue: any): maybeValue is Value; - static create(properties?: ValueProperties | Value): Value; - static fromJSON(properties: ValueJSON): Value; - static fromJS(properties: ValueJSON): Value; - static isValue(maybeValue: any): maybeValue is Value; - - change(): Change; - toJSON(): ValueJSON; + change(): Change; + toJSON(): ValueJSON; + addMark(path: Path, offset: number, length: number, mark: Mark): Value; + insertNode(path: Path, node: Node): Value; + insertText( + path: Path, + offset: number, + text: string, + marks: Immutable.Set + ): Value; + isValue(value: Value): boolean; + mergeNode(path: Path): Value; + moveNode(path: Path, newPath: Path, newIndex?: number): Value; + removeMark(path: Path, offset: number, length: number, mark: Mark): Value; + removeNode(path: Path): Value; + removeText(path: Path, offset: number, text: Text): Value; + setNode(path: Path, properties: any): Value; + setMark( + path: Path, + offset: number, + length: number, + mark: Mark, + properties: MarkProperties + ): Value; + setProperties(properties: ValueProperties): Value; + setSelection(properties: RangeProperties): Value; + splitNode(path: Path, position: number, properties: any): Value; + mapRanges(iterator: () => void): Value; + clearAtomicRanges(key: string, from: number, to?: number): Value; } export interface DocumentProperties { - nodes?: Immutable.List | Node[]; - key?: string; - data?: Immutable.Map | Record; + nodes?: Immutable.List | Node[]; + key?: string; + data?: Immutable.Map | { [key: string]: any }; } export interface DocumentJSON { - nodes?: NodeJSON[]; - key?: string; - data?: Record; - object?: 'document'; + nodes?: NodeJSON[]; + key?: string; + data?: { [key: string]: any }; + object?: "document"; } -export class Document> extends BaseNode< - DataMap +export class Document extends BaseNode< + DataMap > { - object: 'document'; - nodes: Immutable.List; + object: "document"; + nodes: Immutable.List; - static create( - properties: DocumentProperties | Document | Immutable.List | Node[] - ): Document; + static create( + properties: + | DocumentProperties + | Document + | Immutable.List + | Node[] + ): Document; + static fromJSON(properties: DocumentJSON | Document): Document; + static fromJS(properties: DocumentJSON | Document): Document; + static isDocument(maybeDocument: any): maybeDocument is Document; - static fromJSON(properties: DocumentJSON | Document): Document; - static fromJS(properties: DocumentJSON | Document): Document; - static isDocument(maybeDocument: any): maybeDocument is Document; - - toJSON(): DocumentJSON; + toJSON(): DocumentJSON; } export interface BlockProperties { - type: string; - key?: string; - nodes?: Immutable.List; - isVoid?: boolean; - data?: Immutable.Map | Record; + type: string; + key?: string; + nodes?: Immutable.List; + data?: Immutable.Map | { [key: string]: any }; } export interface BlockJSON { - type: string; - key?: string; - nodes?: NodeJSON[]; - isVoid?: boolean; - data?: Record; - object: 'block'; + type: string; + key?: string; + nodes?: Array; + data?: { [key: string]: any }; + object: "block"; } export class Block extends BaseNode { - isVoid: boolean; - object: 'block'; - nodes: Immutable.List; + object: "block"; + nodes: Immutable.List; - static create(properties: BlockProperties | Block | string): Block; - static createList( - array: (BlockProperties[] | Block[] | string[]) - ): Immutable.List; - static fromJSON(properties: BlockJSON | Block): Block; - static fromJS(properties: BlockJSON | Block): Block; - static isBlock(maybeBlock: any): maybeBlock is Block; + static create(properties: BlockProperties | Block | string): Block; + static createList( + array?: BlockProperties[] | Block[] | string[] + ): Immutable.List; + static fromJSON(properties: BlockJSON | Block): Block; + static fromJS(properties: BlockJSON | Block): Block; + static isBlock(maybeBlock: any): maybeBlock is Block; + static isBlockList( + maybeBlockList: any + ): maybeBlockList is Immutable.List; - toJSON(): BlockJSON; + toJSON(): BlockJSON; } export interface InlineProperties { - type: string; - key?: string; - nodes?: Immutable.List; - isVoid?: boolean; - data?: Immutable.Map | Record; + type: string; + key?: string; + nodes?: Immutable.List; + data?: Immutable.Map | { [key: string]: any }; } export interface InlineJSON { - type: string; - key?: string; - nodes?: NodeJSON[]; - isVoid?: boolean; - data?: Record; - object: 'inline'; + type: string; + key?: string; + nodes?: NodeJSON[]; + data?: { [key: string]: any }; + object: "inline"; } export class Inline extends BaseNode { - isVoid: boolean; - object: 'inline'; - nodes: Immutable.List; + object: "inline"; + nodes: Immutable.List; - static create(properties: InlineProperties | Inline | string): Inline; - static createList( - array: (InlineProperties[] | Inline[] | string[]) - ): Immutable.List; - static fromJSON(properties: InlineJSON | Inline): Inline; - static fromJS(properties: InlineJSON | Inline): Inline; - static isInline(maybeInline: any): maybeInline is Inline; + static create(properties: InlineProperties | Inline | string): Inline; + static createList( + array?: InlineProperties[] | Inline[] | string[] + ): Immutable.List; + static fromJSON(properties: InlineJSON | Inline): Inline; + static fromJS(properties: InlineJSON | Inline): Inline; + static isInline(maybeInline: any): maybeInline is Inline; + static isInlineList( + maybeInlineList: any + ): maybeInlineList is Immutable.List; - toJSON(): InlineJSON; -} - -export interface Leaf { - object: 'leaf'; - marks?: Mark[]; - text: string; + toJSON(): InlineJSON; } export interface TextProperties { - key?: string; - characters: Immutable.List; + key?: string; + text?: string; + marks?: Mark[]; } export interface TextJSON { - key?: string; - characters?: Character[]; - leaves: Leaf[]; - object: 'text'; + key?: string; + leaves: LeafJSON[]; + object: "text"; +} + +export interface LeafAndOffset { + startOffset: number; + endOffset: number; + index: number; + leaf: Leaf; } export class Text extends Immutable.Record({}) { - object: 'text'; - characters: Immutable.List; - key: string; - text: string; + object: "text"; + key: string; - static create(properties: TextProperties | Text | string): Text; - static fromJSON(properties: TextJSON | Text): Text; - static fromJS(properties: TextJSON | Text): Text; - static isText(maybeText: any): maybeText is Text; + readonly text: string; - toJSON(): TextJSON; + static create(properties: TextProperties | Text | string): Text; + static createList( + elements?: + | Text[] + | TextProperties[] + | Immutable.List + | Immutable.List + ): Immutable.List; + static fromJSON(properties: TextJSON | Text): Text; + static fromJS(properties: TextJSON | Text): Text; + static isText(maybeText: any): maybeText is Text; + + toJSON(): TextJSON; + + getKeysToPathsTable(): object; + getString(): string; + searchLeafAtOffset(offset: number): LeafAndOffset; + addMark(index: number, length: number, mark: Mark): Text; + addMarks(index: number, lenght: number, marks: Immutable.Set): Text; + getLeaves(decorations?: Range[]): Immutable.List; + getActiveMarksBetweenOffset( + startOffset: number, + endOffset: number + ): Immutable.Set; + getActiveMarks(): Immutable.Set; + getFirstText(): Text; + getLastText(): Text; + getText(): string; + getMarksBetweenOffset( + startOffset: number, + endOffset: number + ): Immutable.Set; + getMarks(): Immutable.OrderedSet; + getMarksAsArray(): Mark[]; + getMarksAtIndex(index: number): Mark; + getNode(key: string): Node | null; + getPath(key: string | Path): Path; + hasNode(key: string): boolean; + insertText(offset: number, text: string, marks?: Immutable.Set): Text; + regenerateKey(): Text; + removeMark(index: number, length: Mark, mark: Mark): Text; + removeText(start: number, length: number): Text; + resolvePath(path: Path, index: number): Immutable.List; + updateMark( + index: number, + length: number, + mark: Mark, + properties: MarkProperties + ): Text; + splitText(offset: number): Text[]; + mergeText(text: Text): Text; + normalize(schema: Schema): () => void | null; + validate(schema: Schema): Error | null; + getFirstInvalidNode(schema: Schema): Text | null; + setLeaves(leaves: Immutable.List): Text; +} + +export interface LeafProperties { + marks?: Immutable.Set; + text?: string; +} + +export interface LeafJSON { + marks?: Mark[]; + text?: string; +} + +export class Leaf extends Immutable.Record({}) { + object: "leaf"; + marks: Immutable.Set | null; + text: string; + + static create(properties: LeafProperties): Leaf; + static createLeaves(leaves: Immutable.List): Immutable.List; + static splitLeaves( + leaves: Immutable.List, + offset: number + ): Array>; + static createList( + attrs?: + | Leaf[] + | LeafProperties[] + | Immutable.List + | Immutable.List + ): Immutable.List; + static fromJSON(properties: LeafJSON): Leaf; + static fromJS(properties: LeafJSON): Leaf; + static isLeaf(maybeLeaf: any): maybeLeaf is Leaf; + static isLeafList( + maybeLeafList: any + ): maybeLeafList is Immutable.List; + + updateMark(mark: Mark, newMark: Mark): Leaf; + addMarks(marks: Immutable.Set): Leaf; + addMark(mark: Mark): Leaf; + removeMark(mark: Mark): Leaf; + toJSON(): LeafProperties; } export type Node = Document | Block | Inline | Text; export type NodeJSON = DocumentJSON | BlockJSON | InlineJSON | TextJSON; +export type NodeProperties = + | DocumentProperties + | BlockProperties + | InlineProperties + | TextProperties; // tslint:disable-next-line strict-export-declare-modifiers -declare class BaseNode> extends Immutable.Record( - {} -) { - data: Immutable.Map; - type: string; - key: string; - object: 'document' | 'block' | 'inline' | 'text'; - nodes: Immutable.List; - readonly text: string; +declare class BaseNode< + DataMap = { [key: string]: any } +> extends Immutable.Record({}) { + data: Immutable.Map; + type: string; + key: string; + object: "document" | "block" | "inline" | "text"; + nodes: Immutable.List; - filterDescendants(iterator: (node: Node) => boolean): Immutable.List; - findDescendants(iterator: (node: Node) => boolean): Node | null; - getBlocksAtRange(range: Range): Immutable.List; - getBlocks(): Immutable.List; - getCharactersAtRange(range: Range): Immutable.List; - getChild(key: string | Node): Node | null; - getClosestBlock(key: string | Node): Block | null; - getClosestInline(key: string | Node): Inline | null; - getClosest(key: string | Node, match: (node: Node) => boolean): Node | null; - getDepth(key: string | Node): number; - getDescendant(key: string | Node): Node | null; - getFirstText(): Text | null; - getFragmentAtRange(range: Range): Document; - getFurthest(key: string, iterator: (node: Node) => boolean): Node | null; - getFurthestAncestor(key: string): Node | null; - getFurthestBlock(key: string): Block | null; - getFurthestInline(key: string): Inline | null; - getFurthestOnlyChildAncestor(key: string): Node | null; - getInlinesAtRange(range: Range): Immutable.List; - getLastText(): Text | null; - getMarksAtRange(range: Range): Immutable.Set; - getNextBlock(key: string | Node): Block | null; - getNextSibling(key: string | Node): Node | null; - getNextText(key: string | Node): Text | null; - getParent(key: string | Node): Node | null; - getPreviousBlock(key: string | Node): Block | null; - getPreviousSibling(key: string | Node): Node | null; - getPreviousText(key: string | Node): Text | null; - getTexts(): Immutable.List; - getTextsAsArray(): Text[]; - getTextAtOffset(offset: number): Text | null; - getTextsAtRange(range: Range): Immutable.List; - getTextsAtRangeAsArray(range: Range): Text[]; - hasChild(key: string | Node): boolean; -} + readonly text: string; -export interface CharacterProperties { - marks?: Immutable.Set | Mark[]; - text: string; -} + static isNode(maybeNode: any): maybeNode is Node; + static isNodeList( + maybeNodeList: any + ): maybeNodeList is Immutable.List; + static createProperties( + attrs: NodeProperties | string | Node + ): NodeProperties; + static fromJSON(value: NodeJSON | Node): Node; + static fromJS(value: NodeJSON | Node): Node; -export class Character extends Immutable.Record({}) { - object: 'character'; - marks: Immutable.Set; - text: string; - - static create( - properties: CharacterProperties | Character | string - ): Character; - static createList( - array: (CharacterProperties[] | Character[] | string[]) - ): Immutable.List; - static fromJSON(properties: CharacterProperties | Character): Character; - static fromJS(properties: CharacterProperties | Character): Character; - static isCharacter(maybeCharacter: any): maybeCharacter is Character; - - toJSON(): CharacterProperties; + addMark(path: Path, offset: number, length: number, mark: Mark): Node; + createDecoration(properties: DecorationProperties | Decoration): Decoration; + createPoint(properties: PointProperties | Point): Point; + createRange(properties: RangeProperties | Range): Range; + createSelection(properties: SelectionProperties | Selection): Selection; + filterDescendants(iterator: (node: Node) => boolean): Immutable.List; + findDescendants(iterator: (node: Node) => boolean): Node | null; + getActiveMarksAtRange(range: Range): Immutable.Set; + getAncestors(path: Path): Immutable.List | null; + getBlocksAtRange(range: Range): Immutable.List; + getBlocksAtRangeAsArray(range: Range): Block[]; + getBlocks(): Immutable.List; + getBlocksAsArray(): Block[]; + getBlocksByType(type: string): Immutable.List; + getBlocksByTypeAsArray(type: string): Block[]; + getChild(path: Path): Node | null; + getClosestBlock(path: Path): Block | null; + getClosestInline(path: Path): Inline | null; + getClosestVoid(path: Path, schema: Schema): Node | null; + getClosest(path: Path, iterator: (node: Node) => boolean): Node | null; + getCommonAncestor(a: Path, b: Path): Node; + getDecorations(stack: Stack): Immutable.List; + getDepth(path: Path, startAt?: number): number; + getDescendant(path: Path): Node | null; + getFirstInvalidNode(schema: Schema): Node | null; + getFirstText(): Text | null; + getFragmentAtRange(range: Range): Document; + getFurthest(path: Path, iterator: (node: Node) => boolean): Node | null; + getFurthestAncestor(path: Path): Node | null; + getFurthestBlock(path: Path): Block | null; + getFurthestInline(path: Path): Inline | null; + getFurthestOnlyChildAncestor(path: Path): Node | null; + getInlines(): Immutable.List; + getInlinesAsArray(): Inline[]; + getInlinesAtRange(range: Range): Immutable.List; + getInlinesAtRangeAsArray(range: Range): Inline[]; + getInlinesByType(type: string): Immutable.List; + getInlinesByTypeAsArray(type: string): Inline[]; + getInsertMarksAtRange(range: Range): Immutable.Set; + getKeysToPathsTable(): object; + getLastText(): Text | null; + getMarks(): Immutable.Set; + getMarksAsArray(): Mark[]; + getMarksAtPosition(key: string, offset: number): Immutable.Set; + getMarksAtRange(range: Range): Immutable.Set; + getMarksByType(type: string): Immutable.Set; + getMarksByTypeAsArray(type: string): Mark[]; + getNextBlock(key: string | Node): Block | null; + getNextNode(path: Path): Node | null; + getNextSibling(path: Path): Node | null; + getNextText(path: Path): Text | null; + getNode(path: Path): Node | null; + getOffset(key: string): number; + getOffsetAtRange(range: Range): number; + getOrderedMarks(): Immutable.OrderedSet; + getOrderedMarksAtRange(range: Range): Immutable.OrderedSet; + getOrderedMarksBetweenPositions( + startKey: string, + startOffset: number, + endKey: string, + endOffset: number + ): Immutable.OrderedSet; + getOrderedMarksByType(type: string): Immutable.OrderedSet; + getParent(path: Path): Node | null; + getPath(key: string | Path): Path; + getPreviousBlock(key: string | Node): Block | null; + getPreviousNode(path: Path): Node | null; + getPreviousSibling(path: Path): Node | null; + getPreviousText(path: Path): Text | null; + getSelectionIndexes( + range: Range, + isSelected?: boolean + ): { start: number; end: number } | null; + getText(): string; + getTextAtOffset(offset: number): Text | null; + getTextDirection(): string | null; + getTexts(): Immutable.List; + getTextsAsArray(): Text[]; + getTextsAtRange(range: Range): Immutable.List; + getTextsAtRangeAsArray(range: Range): Text[]; + getTextsBetweenPositionsAsArray(startKey: string, endKey: string): Text[]; + hasBlockChildren(): boolean; + hasChild(path: Path): boolean; + hasInlineChildren(): boolean; + hasDescendant(path: Path): boolean; + hasNode(path: Path): boolean; + hasVoidParent(path: Path, schema: Schema): boolean; + insertNode(path: Path, node: Node): Node; + insertText( + path: Path, + offset: number, + text: string, + marks: Immutable.Set + ): Node; + isLeafBlock(): boolean; + isLeafInline(): boolean; + mapChildren(iterator: () => void): Node; + mapDescendants(iterator: () => void): Node; + mergeNode(path: Path): Node; + moveNode(path: Path, newPath: Path, newIndex?: number): Node; + normalize(schema: Schema): () => void | void; + refinedNOde(path: Path, key: string): Node | null; + refindPath(path: Path, key: string): Immutable.List | null; + regenerateKey(): Node; + removeMark(path: Path, offset: number, length: number, mark: Mark): Node; + removeNode(path: Path): Node; + removeText(path: Path, offset: number, text: string): Node; + replaceNode(path: Path, node: Node): Node; + resolvePath(path: Path, index: number): Immutable.List; + resolvePoint(point: Point): Point; + resolveRange(range: Range): Range; + setNode(path: Path, properties: NodeProperties): Node; + setMark( + path: Path, + offset: number, + length: number, + mark: Mark, + properties: MarkProperties + ): Node; + splitNode(path: Path, position: number, properties: NodeProperties): Node; + validate(schema: Schema): Error | void; } export interface MarkProperties { - type: string; - data?: Immutable.Map | Record; + type: string; + data?: Immutable.Map | { [key: string]: any }; } export interface MarkJSON { - type: string; - data?: Record; + type: string; + data?: { [key: string]: any }; } export class Mark extends Immutable.Record({}) { - object: 'mark'; - type: string; - data: Immutable.Map; + object: "mark"; + type: string; + data: Immutable.Map; - static create(properties: MarkProperties | Mark | string): Mark; - static createSet( - array: (MarkProperties[] | Mark[] | string[]) - ): Immutable.Set; - static fromJSON(properties: MarkJSON | Mark): Mark; - static fromJS(properties: MarkJSON | Mark): Mark; - static isMark(maybeMark: any): maybeMark is Mark; + static create(properties: MarkProperties | Mark | string): Mark; + static createSet( + array: MarkProperties[] | Mark[] | string[] + ): Immutable.Set; + static fromJSON(properties: MarkJSON | Mark): Mark; + static fromJS(properties: MarkJSON | Mark): Mark; + static isMark(maybeMark: any): maybeMark is Mark; - toJSON(): MarkProperties; + toJSON(): MarkProperties; +} + +export interface ChangeOption { + normalize?: boolean; } export class Change extends Immutable.Record({}) { - object: 'change'; - value: Value; - operations: Immutable.List; + object: "change"; + value: Value; + operations: Immutable.List; - call(customChange: (change: Change, ...args: any[]) => Change): Change; - withoutNormalization(customChange: (change: Change) => void): Change; + call(customChange: (change: Change, ...args: any[]) => Change): Change; - applyOperations(operations: Operation[]): Change; - applyOperation(operation: Operation): Change; + applyOperations(operations: Operation[]): Change; + applyOperation(operation: Operation): Change; - // Full Value Change - setValue(properties: Value | ValueProperties): Change; + withoutNormalization(fn: (change: Change) => void): Change; + setOperationFlag(key: string, value: any): Change; + getFlag(key: string, options?: object): any; + unsetOperationFlag(key: string): Change; - // Current Value Changes - deleteBackward(n: number): Change; - deleteForward(n: number): Change; - delete(): Change; - insertBlock(block: Block | BlockProperties | string): Change; - insertFragment(fragment: Document): Change; - insertInline(inline: Inline | InlineProperties): Change; - insertText(text: string): Change; - addMark(mark: Mark | MarkProperties | string): Change; - setBlocks(properties: BlockProperties | string): Change; - setInlines(properties: InlineProperties | string): Change; - splitBlock(depth: number): Change; - splitInline(depth: number): Change; - removeMark(mark: Mark | MarkProperties | string): Change; - toggleMark(mark: Mark | MarkProperties | string): Change; - unwrapBlock(properties: BlockProperties | string): Change; - unwrapInline(properties: InlineProperties | string): Change; - wrapBlock(properties: BlockProperties | string): Change; - wrapInline(properties: InlineProperties | string): Change; - wrapText(prefix: string, suffix?: string): Change; + // Full Value Change + setValue(properties: Value | ValueProperties): Change; - // Selection Changes - blur(): Change; - collapseToAnchor(): Change; - collapseToFocus(): Change; - collapseToStart(): Change; - collapseToEnd(): Change; - collapseToStartOf(node: Node): Change; - collapseToEndOf(node: Node): Change; - collapseToStartOfNextBlock(): Change; - collapseToEndOfNextBlock(): Change; - collapseToStartOfPreviousBlock(): Change; - collapseToEndOfPreviousBlock(): Change; - collapseToStartOfNextText(): Change; - collapseToEndOfNextText(): Change; - collapseToStartOfPreviousText(): Change; - collapseToEndOfPreviousText(): Change; - extend(n: number): Change; - extendToStartOf(node: Node): Change; - extendToEndOf(node: Node): Change; - flip(): Change; - focus(): Change; - move(n: number): Change; - moveStart(n: number): Change; - moveEnd(n: number): Change; - moveOffsetsTo(anchorOffset: number, focusOffset: number): Change; - moveToRangeOf(node: Node): Change; - select(properties: Range | RangeProperties): Change; - selectAll(): Change; - deselect(): Change; + // Current Value Changes + deleteBackward(n: number): Change; + deleteForward(n: number): Change; + delete(): Change; + insertBlock(block: Block | BlockProperties | string): Change; + insertFragment(fragment: Document): Change; + insertInline(inline: Inline | InlineProperties): Change; + insertText(text: string): Change; + addMark(mark: Mark | MarkProperties | string): Change; + setBlocks(properties: BlockProperties | string): Change; + setInlines(properties: InlineProperties | string): Change; + splitBlock(depth: number): Change; + splitInline(depth: number): Change; + removeMark(mark: Mark | MarkProperties | string): Change; + replaceMark( + mark: Mark | MarkProperties | string, + newMark: Mark | MarkProperties | string + ): Change; + toggleMark(mark: Mark | MarkProperties | string): Change; + unwrapBlock(properties: BlockProperties | string): Change; + unwrapInline(properties: InlineProperties | string): Change; + wrapBlock(properties: BlockProperties | string): Change; + wrapInline(properties: InlineProperties | string): Change; + wrapText(prefix: string, suffix?: string): Change; - // Document Changes - deleteBackwardAtRange(range: Range, n: number): Change; - deleteForwardAtRange(range: Range, n: number): Change; - deleteAtRange(range: Range): Change; - insertBlockAtRange( - range: Range, - block: Block | BlockProperties | string - ): Change; - insertFragmentAtRange(range: Range, fragment: Document): Change; - insertInlineAtRange( - range: Range, - inline: Inline | InlineProperties - ): Change; - insertTextAtRange(range: Range, text: string): Change; - addMarkAtRange(range: Range, mark: Mark | MarkProperties | string): Change; - setBlocksAtRange(range: Range, properties: BlockProperties | string): Change; - setInlinesAtRange( - range: Range, - properties: InlineProperties | string - ): Change; - splitBlockAtRange(range: Range, depth: number): Change; - splitInlineAtRange(range: Range, depth: number): Change; - removeMarkAtRange( - range: Range, - mark: Mark | MarkProperties | string - ): Change; - toggleMarkAtRange( - range: Range, - mark: Mark | MarkProperties | string - ): Change; - unwrapBlockAtRange( - range: Range, - properties: BlockProperties | string - ): Change; - unwrapInlineAtRange( - range: Range, - properties: InlineProperties | string - ): Change; - wrapBlockAtRange( - range: Range, - properties: BlockProperties | string - ): Change; - wrapInlineAtRange( - range: Range, - properties: InlineProperties | string - ): Change; - wrapTextAtRange(range: Range, prefix: string, suffix?: string): Change; + // Selection Changes + blur(): Change; - // Node Changes - addMarkByKey( - key: string, - offset: number, - length: number, - mark: Mark - ): Change; - insertNodeByKey(key: string, index: number, node: Node): Change; - insertFragmentByKey(key: string, index: number, fragment: Document): Change; - insertTextByKey( - key: string, - offset: number, - text: string, - marks?: Immutable.Set | Mark[] - ): Change; - moveNodeByKey(key: string, newKey: string, newIndex: number): Change; - removeMarkByKey( - key: string, - offset: number, - length: number, - mark: Mark - ): Change; - removeNodeByKey(key: string): Change; - replaceNodeByKey(key: string, node: Node): Change; - removeTextByKey(key: string, offset: number, length: number): Change; - setMarkByKey( - key: string, - offset: number, - length: number, - mark: Mark, - properties: MarkProperties - ): Change; - setNodeByKey( - key: string, - properties: BlockProperties | InlineProperties | string - ): Change; - splitNodeByKey(key: string, offset: number): Change; - unwrapInlineByKey( - key: string, - properties: InlineProperties | string - ): Change; - unwrapBlockByKey(key: string, properties: BlockProperties | string): Change; - unwrapNodeByKey(key: string): Change; - wrapInlineByKey(key: string, properties: InlineProperties | string): Change; - wrapBlockByKey(key: string, properties: BlockProperties | string): Change; + flip(): Change; + focus(): Change; + move(n: number): Change; - // History Changes - redo(): Change; - undo(): Change; + moveAnchorBackward(n?: number): Change; + moveAnchorForward(n?: number): Change; + moveAnchorTo(path: Path, offset: number): Change; + moveAnchorToEndOfBlock(): Change; + moveAnchorToEndOfInline(): Change; + moveAnchorToEndOfDocument(): Change; + moveAnchorToEndOfNextBlock(): Change; + moveAnchorToEndOfNextInline(): Change; + moveAnchorToEndOfNextText(): Change; + moveAnchorEndOfNode(node: Node): Change; + moveAnchorToEndOfPreviousBlock(): Change; + moveAnchorToEndOfPreviousInline(): Change; + moveAnchorToEndOfPreviousText(): Change; + moveAnchorToEndOfText(): Change; + moveAnchorToStartOfBlock(): Change; + moveAnchorToStartOfDocument(): Change; + moveAnchorToStartOfInline(): Change; + moveAnchorToStartOfNextBlock(): Change; + moveAnchorToStartOfNextInline(): Change; + moveAnchorToStartOfNextText(): Change; + moveAnchorToStartOfNode(node: Node): Change; + moveAnchorToStartOfPreviousBlock(): Change; + moveAnchorToStartOfPreviousInline(): Change; + moveAnchorToStartOfPreviousText(): Change; + moveAnchorToStartOfText(): Change; + + moveBackward(point: Point, n?: number): Change; + moveEndBackward(point: Point, n?: number): Change; + moveEndForward(point: Point, n?: number): Change; + + moveEndTo(path: Path, offset: number): Change; + moveEndToEndOfBlock(): Change; + moveEndToEndOfDocument(): Change; + moveEndToEndOfInline(): Change; + moveEndToEndOfNextBlock(): Change; + moveEndToEndOfNextInline(): Change; + moveEndToEndOfNextText(): Change; + moveEndToEndOfNode(node: Node): Change; + moveEndToEndOfPreviousBlock(): Change; + moveEndToEndOfPreviousInline(): Change; + moveEndToEndOfPreviousText(): Change; + moveEndToEndOfText(): Change; + moveEndToStartOfBlock(): Change; + moveEndToStartOfDocument(): Change; + moveEndToStartOfInline(): Change; + moveEndToStartOfNextBlock(): Change; + moveEndToStartOfNextInline(): Change; + moveEndToStartOfNextText(): Change; + moveEndToStartOfNode(node: Node): Change; + moveEndToStartOfPreviousBlock(): Change; + moveEndToStartOfPreviousInline(): Change; + moveEndToStartOfPreviousText(): Change; + moveEndToStartOfText(): Change; + + moveFocusBackward(n?: number): Change; + moveFocusForward(n?: number): Change; + moveFocusTo(point: Point, n?: number): Change; + moveFocusToEndOfBlock(): Change; + moveFocusToEndOfDocument(): Change; + moveFocusToEndOfInline(): Change; + moveFocusToEndOfNextBlock(): Change; + moveFocusToEndOfNextInline(): Change; + moveFocusToEndOfNextText(): Change; + moveFocusToEndOfNode(node: Node): Change; + moveFocusToEndOfPreviousBlock(): Change; + moveFocusToEndOfPreviousInline(): Change; + moveFocusToEndOfPreviousText(): Change; + moveFocusToEndOfText(): Change; + moveFocusToStartOfBlock(): Change; + moveFocusToStartOfDocument(): Change; + moveFocusToStartOfInline(): Change; + moveFocusToStartOfNextBlock(): Change; + moveFocusToStartOfNextInline(): Change; + moveFocusToStartOfNextText(): Change; + moveFocusToStartOfNode(node: Node): Change; + moveFocusToStartOfPreviousBlock(): Change; + moveFocusToStartOfPreviousInline(): Change; + moveFocusToStartOfPreviousText(): Change; + moveFocusToStartOfText(): Change; + + moveForward(point: Point, n?: number): Change; + + moveStartForward(point: Point, n?: number): Change; + moveStartBackward(point: Point, n?: number): Change; + moveStartTo(point: Point, n?: number): Change; + moveStartToEndOfBlock(): Change; + moveStartToEndOfDocument(): Change; + moveStartToEndOfInline(): Change; + moveStartToEndOfNextBlock(): Change; + moveStartToEndOfNextInline(): Change; + moveStartToEndOfNextText(): Change; + moveStartToEndOfNode(node: Node): Change; + moveStartToEndOfPreviousBlock(): Change; + moveStartToEndOfPreviousInline(): Change; + moveStartToEndOfPreviousText(): Change; + moveStartToEndOfText(): Change; + moveStartToStartOfBlock(): Change; + moveStartToStartOfDocument(): Change; + moveStartToStartOfInline(): Change; + moveStartToStartOfNextBlock(): Change; + moveStartToStartOfNextInline(): Change; + moveStartToStartOfNextText(): Change; + moveStartToStartOfNode(node: Node): Change; + moveStartToStartOfPreviousBlock(): Change; + moveStartToStartOfPreviousInline(): Change; + moveStartToStartOfPreviousText(): Change; + moveStartToStartOfText(): Change; + + moveTo(path: Path, offset: number): Change; + moveToAnchor(): Change; + moveToFocus(): Change; + moveToStart(): Change; + moveToEnd(): Change; + moveToEndOfBlock(): Change; + moveToEndOfDocument(): Change; + moveToEndOfInline(): Change; + moveToEndOfNextBlock(): Change; + moveToEndOfNextInline(): Change; + moveToEndOfNextText(): Change; + moveToEndOfNode(node: Node): Change; + moveToEndOfPreviousBlock(): Change; + moveToEndOfPreviousInline(): Change; + moveToEndOfPreviousText(): Change; + moveToEndOfText(): Change; + moveToStartOfBlock(): Change; + moveToStartOfDocument(): Change; + moveToStartOfInline(): Change; + moveToStartOfNextBlock(): Change; + moveToStartOfNextInline(): Change; + moveToStartOfNextText(): Change; + moveToStartOfNode(node: Node): Change; + moveToStartOfPreviousBlock(): Change; + moveToStartOfPreviousInline(): Change; + moveToStartOfPreviousText(): Change; + moveToStartOfText(): Change; + + moveToRangeOfDocument(): Change; + moveToRangeOfNode(node: Node): Change; + select(properties: Range | RangeProperties, options: ChangeOption): Change; + setAnchor(point: Point): Change; + setEnd(point: Point): Change; + setFocus(point: Point): Change; + setStart(point: Point): Change; + snapshotSelection(): Change; + deselect(): Change; + + // Document Changes + deleteCharBackwardAtRange(range: Range, options?: ChangeOption): Change; + deleteLineBackwardAtRange(range: Range, options?: ChangeOption): Change; + deleteWordBackwardAtRange(range: Range, options?: ChangeOption): Change; + deleteBackwardAtRange(range: Range, options?: ChangeOption): Change; + deleteCharForwardAtRange(range: Range, options?: ChangeOption): Change; + deleteLineForwardAtRange(range: Range, options?: ChangeOption): Change; + deleteWordForwardAtRange(range: Range, options?: ChangeOption): Change; + deleteForwardAtRange(range: Range, options?: ChangeOption): Change; + deleteAtRange(range: Range, options?: ChangeOption): Change; + insertBlockAtRange( + range: Range, + block: Block | BlockProperties | string, + options?: ChangeOption + ): Change; + insertFragmentAtRange( + range: Range, + fragment: Document, + options?: ChangeOption + ): Change; + insertInlineAtRange( + range: Range, + inline: Inline | InlineProperties, + options?: ChangeOption + ): Change; + insertTextAtRange( + range: Range, + text: string, + marks?: Immutable.Set, + options?: ChangeOption + ): Change; + addMarkAtRange( + range: Range, + mark: Mark | MarkProperties | string, + options?: ChangeOption + ): Change; + addMarksAtRange( + range: Range, + marks: Mark[] | MarkProperties[] | string[], + options?: ChangeOption + ): Change; + setBlocksAtRange( + range: Range, + properties: BlockProperties | string, + options?: ChangeOption + ): Change; + setInlinesAtRange( + range: Range, + properties: InlineProperties | string, + options?: ChangeOption + ): Change; + splitBlockAtRange( + range: Range, + depth: number, + height?: number, + options?: ChangeOption + ): Change; + splitInlineAtRange( + range: Range, + depth: number, + height?: number, + options?: ChangeOption + ): Change; + removeMarkAtRange( + range: Range, + mark: Mark | MarkProperties | string, + options?: ChangeOption + ): Change; + toggleMarkAtRange( + range: Range, + mark: Mark | MarkProperties | string, + options?: ChangeOption + ): Change; + unwrapBlockAtRange( + range: Range, + properties: BlockProperties | string, + options?: ChangeOption + ): Change; + unwrapInlineAtRange( + range: Range, + properties: InlineProperties | string, + options?: ChangeOption + ): Change; + wrapBlockAtRange( + range: Range, + properties: BlockProperties | string, + options?: ChangeOption + ): Change; + wrapInlineAtRange( + range: Range, + properties: InlineProperties | string, + options?: ChangeOption + ): Change; + wrapTextAtRange( + range: Range, + prefix: string, + suffix?: string, + options?: ChangeOption + ): Change; + + // Node Changes + addMarkByKey( + key: string, + offset: number, + length: number, + mark: Mark + ): Change; + insertNodeByKey(key: string, index: number, node: Node): Change; + insertFragmentByKey(key: string, index: number, fragment: Document): Change; + insertTextByKey( + key: string, + offset: number, + text: string, + marks?: Immutable.Set | Mark[] + ): Change; + moveNodeByKey(key: string, newKey: string, newIndex: number): Change; + removeMarkByKey( + key: string, + offset: number, + length: number, + mark: Mark + ): Change; + removeNodeByKey(key: string): Change; + replaceNodeByKey(key: string, node: Node): Change; + removeTextByKey(key: string, offset: number, length: number): Change; + setMarkByKey( + key: string, + offset: number, + length: number, + mark: Mark, + properties: MarkProperties + ): Change; + setNodeByKey( + key: string, + properties: BlockProperties | InlineProperties | string + ): Change; + splitNodeByKey(key: string, offset: number): Change; + unwrapInlineByKey( + key: string, + properties: InlineProperties | string + ): Change; + unwrapBlockByKey(key: string, properties: BlockProperties | string): Change; + unwrapNodeByKey(key: string): Change; + wrapInlineByKey(key: string, properties: InlineProperties | string): Change; + wrapBlockByKey(key: string, properties: BlockProperties | string): Change; + + // by path + addMarkByPath( + path: Path, + offset: number, + length: number, + mark: MarkProperties | Mark | string, + options: ChangeOption + ): Change; + insertFragmentByPath( + path: Path, + index: number, + fragment: Document, + options: ChangeOption + ): Change; + insertNodeByPath( + path: Path, + index: number, + node: Node, + options: ChangeOption + ): Change; + insertTextByPath( + path: Path, + offset: number, + text: string, + marks: Immutable.Set | null | undefined, + options: ChangeOption + ): Change; + mergeNodeByPath(path: Path, options: ChangeOption): Change; + moveNodeByPath( + path: Path, + newPath: Path, + newIndex: number, + options: ChangeOption + ): Change; + removeMarkByPath( + path: Path, + offset: number, + length: number, + mark: MarkProperties | Mark | string, + options: ChangeOption + ): Change; + removeAllMarksByPath(path: Path, options: ChangeOption): Change; + removeNodeByPath(path: Path, options: ChangeOption): Change; + removeTextByPath( + path: Path, + offset: number, + length: number, + options: ChangeOption + ): Change; + replaceNodeByPath(path: Path, newNode: Node, options: ChangeOption): Change; + replaceTextByPath( + path: Path, + offset: number, + length: number, + text: string, + marks: Immutable.Set | null | undefined, + options: ChangeOption + ): Change; + setMarksByPath( + path: Path, + offset: number, + length: number, + mark: Mark, + properties: MarkProperties, + options: ChangeOption + ): Change; + setNodeByPath( + path: Path, + properties: NodeProperties, + options: ChangeOption + ): Change; + setTextByPath( + path: Path, + text: string, + marks: Immutable.Set | null | undefined, + options: ChangeOption + ): Change; + splitNodeByPath( + path: Path, + position: number, + options?: ChangeOption + ): Change; + splitDescendantByPath( + path: Path, + textPath: Path, + textOffset: number, + options: ChangeOption + ): Change; + unwrapInlineByPath( + path: Path, + properties: InlineProperties, + options: ChangeOption + ): Change; + unwrapBlockByPath( + path: Path, + properties: BlockProperties, + options: ChangeOption + ): Change; + unwrapNodeByPath(path: Path, options: ChangeOption): Change; + wrapBlockByPath(path: Path, block: Block, options: ChangeOption): Change; + wrapInlineByPath(path: Path, inline: Inline, options: ChangeOption): Change; + wrapNodeByPath(path: Path, node: Node): Change; + + normalize(options: ChangeOption): Change; + normalizeDocument(options: ChangeOption): Change; + normalizeNodeByKey(key: string, options: ChangeOption): Change; + normalizeAncestorsByKey(key: string): Change; + normalizeParentByKey(key: string, options: ChangeOption): Change; + normalizeNodeByPath(path: Path, options: ChangeOption): Change; + normalizeParentByPath(path: Path, options: ChangeOption): Change; + normalizeNodeAndChildren(node: Node, schema: Schema): Change; + normalizeNode(node: Node, schema: Schema): Change; + + // History Changes + redo(): Change; + undo(): Change; +} + +export interface SelectionProperties { + anchor?: Point; + focus?: Point; + isFocused?: boolean; + marks?: Immutable.Set | null; +} + +export interface SelectionJSON { + anchor?: PointJSON; + focus?: PointJSON; + isFocused?: boolean; + isBackward?: boolean | null; + marks?: MarkJSON[] | null; +} + +export class Selection extends BaseRange { + object: "selection"; + anchor: Point; + focus: Point; + isFocused: boolean; + marks: Immutable.Set | null; + + readonly isBlurred: boolean; + + static create( + properties: SelectionProperties | Selection | Range + ): Selection; + static createProperties( + attrs: SelectionProperties | string | Selection | Range + ): SelectionProperties; + static fromJSON(properties: SelectionJSON): Selection; + + toJSON(): SelectionJSON; + + isSelection(maybeSelection: any): maybeSelection is Selection; + setIsFocused(value: boolean): Selection; + setMarks(marks: Immutable.Set): Selection; + setProperties(properties: Selection | SelectionProperties): Selection; } export interface RangeProperties { - anchorKey?: string | null; - anchorOffset?: number; - focusKey?: string | null; - focusOffset?: number; - isFocused?: boolean; - isBackward?: boolean | null; - marks?: Immutable.Set | null; + anchor?: Point; + focus?: Point; } export interface RangeJSON { - anchorKey?: string | null; - anchorOffset?: number; - focusKey?: string | null; - focusOffset?: number; - isFocused?: boolean; - isBackward?: boolean | null; - marks?: MarkJSON[] | null; + anchor?: PointJSON; + focus?: PointJSON; } -export class Range extends Immutable.Record({}) { - object: 'range'; - anchorKey: string | null; - anchorOffset: number; - focusKey: string | null; - focusOffset: number; - isFocused: boolean; - isBackward: boolean | null; - marks: Immutable.Set | null; +export class Range extends BaseRange { + object: "range"; + anchor: Point; - readonly isBlurred: boolean; - readonly isCollapsed: boolean; - readonly isExpanded: boolean; - readonly isForward: boolean; - readonly startKey: string; - readonly startOffset: number; - readonly endKey: string; - readonly endOffset: number; + static create(properties: RangeProperties | Range): Range; + static createList( + elements?: + | Range[] + | RangeProperties[] + | Immutable.List + | Immutable.List + ): Immutable.List; + static createProperties( + attrs: RangeProperties | string | Range + ): RangeProperties; + static fromJSON(properties: RangeJSON): Range; + static fromJS(properties: RangeJSON): Range; + static isRange(maybeRange: any): maybeRange is Range; - static create(properties: RangeProperties | Range): Range; - static fromJSON(properties: RangeJSON): Range; - static fromJS(properties: RangeJSON): Range; - static isRange(maybeRange: any): maybeRange is Range; + toJSON(): RangeJSON; +} - toJSON(): RangeProperties; +export interface DecorationProperties { + anchor?: Point; + focus?: Point; + mark?: Mark | null; +} - hasAnchorAtStartOf(node: Node): boolean; - hasFocusAtStartOf(node: Node): boolean; - hasStartAtStartOf(node: Node): boolean; - hasEndAtStartOf(node: Node): boolean; - hasEdgeAtStartOf(node: Node): boolean; +export interface DecorationJSON { + anchor?: PointJSON; + focus?: PointJSON; + mark?: MarkJSON | null; +} - hasAnchorAtEndOf(node: Node): boolean; - hasFocusAtEndOf(node: Node): boolean; - hasStartAtEndOf(node: Node): boolean; - hasEndAtEndOf(node: Node): boolean; - hasEdgeAtEndOf(node: Node): boolean; +export class Decoration extends BaseRange { + object: "decoration"; + anchor: Point; + focus: Point; + mark: Mark | null; + static create(properties: DecorationProperties | Range): Decoration; + static createList( + elements?: + | Decoration[] + | DecorationProperties[] + | Immutable.List + | Immutable.List + ): Immutable.List; + static createProperties( + attrs: DecorationProperties | string | Decoration + ): DecorationProperties; + static fromJSON(properties: DecorationJSON): Decoration; + static fromJS(properties: DecorationJSON): Decoration; + static isDecoration(maybeDecoration: any): maybeDecoration is Decoration; - hasAnchorBetween(node: Node, start: number, end: number): boolean; - hasFocusBetween(node: Node, start: number, end: number): boolean; - hasStartBetween(node: Node, start: number, end: number): boolean; - hasEndBetween(node: Node, start: number, end: number): boolean; - hasEdgeBetween(node: Node, start: number, end: number): boolean; + toJSON(): DecorationJSON; - hasAnchorIn(node: Node): boolean; - hasFocusIn(node: Node): boolean; - hasStartIn(node: Node): boolean; - hasEndIn(node: Node): boolean; - hasEdgeIn(node: Node): boolean; + setProperties(properties: Decoration | DecorationProperties): Decoration; +} - isAtStartOf(node: Node): boolean; - isAtEndOf(node: Node): boolean; +export type RangeTypeProperties = + | RangeProperties + | SelectionProperties + | DecorationProperties; + +export type RangeTypeJSON = RangeJSON | SelectionJSON | DecorationJSON; +export type RangeType = Range | Selection | Decoration; + +// tslint:disable-next-line strict-export-declare-modifiers +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: Path, offset?: number): RangeType; + moveAnchorToStartOfNode(node: Node): RangeType; + moveAnchorToEndOfNode(node: Node): RangeType; + + moveEndBackward(n?: number): RangeType; + moveEndForward(n?: number): RangeType; + moveEndTo(path: Path, offset?: number): RangeType; + moveEndToStartOfNode(node: Node): RangeType; + moveEndToEndOfNode(node: Node): RangeType; + + moveFocusBackward(n?: number): RangeType; + moveFocusForward(n?: number): RangeType; + moveFocusTo(path: Path, offset?: number): RangeType; + moveFocusToStartOfNode(node: Node): RangeType; + moveFocusToEndOfNode(node: Node): RangeType; + + moveStartBackward(n?: number): RangeType; + moveStartForward(n?: number): RangeType; + moveStartTo(path: Path, 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): RangeType; + setPoints(values: Point[]): RangeType; + updatePoints(updator: () => Point): RangeType; + setStart(point: Point): RangeType; + setProperties( + properties: RangeTypeProperties | string | RangeType + ): RangeType; + + toJSON(): RangeTypeJSON; + toRange(): RangeType; + unset(): RangeType; +} + +export interface PointProperties { + key?: string | null; + offset?: number; + path?: Path | null; +} + +export interface PointJSON { + key?: string | null; + offset?: number; + path?: Path | null; + object: "point"; +} + +export class Point extends Immutable.Record({}) { + object: "point"; + key: string | null; + offset: number; + path: Path | null; + + static create(properties: PointProperties | Point): Point; + static createProperties(properties: PointProperties | Point): Point; + static fromJSON(properties: PointJSON): Point; + static fromJS(properties: PointJSON): Point; + static isPoint(maybePoint: any): maybePoint is Point; + + readonly isSet: boolean; + readonly isUnset: boolean; + + isAtEndOfNode(node: Node): boolean; + isAtStartOfNode(node: Node): boolean; + isInNode(node: Node): boolean; + moveBackward(n?: number): Point; + moveForward(n?: number): Point; + moveTo(path: Path, offset?: number): Point; + moveToStartOfNode(node: Node): Point; + moveToEndOfNode(node: Node): Point; + normalize(node: Node): Point; + setKey(key: string): Point; + setOffset(offset: number): Point; + setPath(path: Path): Point; + toJSON(options: any): object; + unset(): Point; } export type Operation = - | InsertTextOperation - | RemoveTextOperation - | AddMarkOperation - | RemoveMarkOperation - | SetMarkOperation - | InsertNodeOperation - | MergeNodeOperation - | MoveNodeOperation - | RemoveNodeOperation - | SetNodeOperation - | SplitNodeOperation - | SetSelectionOperation - | SetValueOperation; + | InsertTextOperation + | RemoveTextOperation + | AddMarkOperation + | RemoveMarkOperation + | SetMarkOperation + | InsertNodeOperation + | MergeNodeOperation + | MoveNodeOperation + | RemoveNodeOperation + | SetNodeOperation + | SplitNodeOperation + | SetSelectionOperation + | SetValueOperation; export interface InsertTextOperation { - type: 'insert_text'; - path: number[]; - offset: number; - text: string; - marks: Mark[]; + type: "insert_text"; + path: number[]; + offset: number; + text: string; + marks: Mark[]; } export interface RemoveTextOperation { - type: 'remove_text'; - path: number[]; - offset: number; - text: string; + type: "remove_text"; + path: number[]; + offset: number; + text: string; } export interface AddMarkOperation { - type: 'add_mark'; - path: number[]; - offset: number; - length: number; - mark: Mark; + type: "add_mark"; + path: number[]; + offset: number; + length: number; + mark: Mark; } export interface RemoveMarkOperation { - type: 'remove_mark'; - path: number[]; - offset: number; - length: number; - mark: Mark; + type: "remove_mark"; + path: number[]; + offset: number; + length: number; + mark: Mark; } export interface SetMarkOperation { - type: 'set_mark'; - path: number[]; - offset: number; - length: number; - mark: Mark; - properties: MarkProperties; + type: "set_mark"; + path: number[]; + offset: number; + length: number; + mark: Mark; + properties: MarkProperties; } export interface InsertNodeOperation { - type: 'insert_node'; - path: number[]; - node: Node; + type: "insert_node"; + path: number[]; + node: Node; } export interface MergeNodeOperation { - type: 'merge_node'; - path: number[]; - position: number; + type: "merge_node"; + path: number[]; + position: number; } export interface MoveNodeOperation { - type: 'move_node'; - path: number[]; - newPath: number[]; + type: "move_node"; + path: number[]; + newPath: number[]; } export interface RemoveNodeOperation { - type: 'remove_node'; - path: number[]; - node: Node; + type: "remove_node"; + path: number[]; + node: Node; } export interface SetNodeOperation { - type: 'set_node'; - path: number[]; - properties: BlockProperties | InlineProperties | TextProperties; + type: "set_node"; + path: number[]; + properties: BlockProperties | InlineProperties | TextProperties; } export interface SplitNodeOperation { - type: 'split_node'; - path: number[]; - position: number; - target: number; + type: "split_node"; + path: number[]; + position: number; + target: number; } export interface SetSelectionOperation { - type: 'set_selection'; - properties: RangeProperties; - selection: Range; + type: "set_selection"; + properties: RangeProperties; + selection: Range; } export interface SetValueOperation { - type: 'set_value'; - properties: ValueProperties; - value: Value; + type: "set_value"; + properties: ValueProperties; + value: Value; } -export const Operations: { - apply: (value: Value, operation: Operation) => Value; - invert: (operation: Operation) => Operation; -}; +export interface Operations { + apply: (value: Value, operation: Operation) => Value; + invert: (operation: Operation) => Operation; +} + +export interface StackProperties { + plugins?: any[]; +} + +export interface StackJSON { + object: "stack"; + plugins: any[]; +} export class Stack extends Immutable.Record({}) { - plugins: any[]; + object: "stack"; + plugins: any[]; + + static create(attrs: StackProperties): Stack; + static isStack(maybeStack: any): maybeStack is Stack; + + static fromJSON(properties: StackJSON): Stack; + static fromJS(properties: StackJSON): Stack; + toJSON(options: any): object; } -export function setKeyGenerator(func: () => string): null; -export function resetKeyGenerator(): null; +export interface HistoryProperties { + undos?: Operation[]; + redos?: Operation[]; +} + +export interface HistoryJSON { + object: "history"; + undos: any[]; + redos: any[]; +} + +export interface HistoryOptions { + merge?: boolean; + skip?: boolean; +} + +export class History extends Immutable.Record({}) { + redos: Stack; + undos: Stack; + object: "history"; + + static create(attrs: History | HistoryProperties): History; + static createOperationsList( + oeprations?: Immutable.List | Operation[] + ): Immutable.List; + static fromJSON(object: HistoryJSON): History; + static fromJS(object: HistoryJSON): History; + static isHistory(maybeHistory: any): maybeHistory is History; + + save(operation: Operation, options?: HistoryOptions): History; + toJSON(): HistoryJSON; + toJS(): HistoryJSON; +} + +export type ErrorCode = + | "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 interface KeyUtils { + create(key: string): string; + setGenerator(func: () => any): void; + resetGenerator(): void; +} + +export type useMemoization = () => void; +export type resetMemoization = () => void; + +export interface PathUtils { + compare( + path: Immutable.List, + target: Immutable.List + ): number | null; + create(attrs: Immutable.List | string): Immutable.List; + crop( + a: Immutable.List, + b: Immutable.List, + size?: number + ): Array>; + decrement( + path: Immutable.List, + n?: number, + index?: number + ): Immutable.List; + increment( + path: Immutable.List, + n?: number, + index?: number + ): Immutable.List; + isAbove( + path: Immutable.List, + target: Immutable.List + ): boolean; + isAfter( + path: Immutable.List, + target: Immutable.List + ): boolean; + isBefore( + path: Immutable.List, + target: Immutable.List + ): boolean; + lift(path: Immutable.List): Immutable.List; + max(a: Immutable.List, b: Immutable.List): number; + min(a: Immutable.List, b: Immutable.List): number; + relate( + a: Immutable.List, + b: Immutable.List + ): Immutable.List; +} export {}; diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index 25f222b4e1..91ef2dadcb 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -1,39 +1,39 @@ -import { Value, Data, NodeJSON, Document } from "slate"; +import { Value, Data, BlockJSON, Document } from "slate"; -const data = Data.create({ foo: "bar "}); +const data = Data.create({ foo: "bar " }); const value = Value.create({ data }); -const change = value.change() -.focus() -.selectAll() -.delete() -.insertText('A bit of rich text, followed by...') -.moveOffsetsTo(10, 14) -.addMark('bold') -.collapseToEndOfNextBlock() -.insertBlock({ - type: 'image', - isVoid: true, - data: { - src: 'http://placekitten.com/200/300', - alt: 'Kittens', - className: 'img-responsive', - }, -}) -.insertBlock('paragraph'); +const change = value + .change() + .focus() + .moveAnchorToStartOfDocument() + .moveFocusToEndOfDocument() + .delete() + .insertText("A bit of rich text, followed by...") + .moveToStartOfText() + .move(10) + .moveFocusForward(4) + .addMark("bold") + .moveToEndOfNextBlock() + .insertBlock({ + type: "image", + data: { + src: "http://placekitten.com/200/300", + alt: "Kittens", + className: "img-responsive" + } + }) + .insertBlock("paragraph"); -const node: NodeJSON = { +const node: BlockJSON = { object: "block", type: "paragraph", - isVoid: false, - data: {}, nodes: [ { object: "text", leaves: [ { - object: 'leaf', text: "example", - marks: [], + marks: [] } ] } @@ -43,7 +43,5 @@ const node: NodeJSON = { const doc = Document.fromJSON({ object: "document", data: {}, - nodes: [ - node - ], + nodes: [node] }); From 144a8059d8b00ee7d7e7ff4caaea304e21b03b6e Mon Sep 17 00:00:00 2001 From: Irwan Fario Subastian Date: Fri, 24 Aug 2018 14:39:47 +1000 Subject: [PATCH 2/4] update slate-react definition to 0.18 --- types/slate-react/index.d.ts | 194 +++++++++++++++++++++++------------ 1 file changed, 126 insertions(+), 68 deletions(-) diff --git a/types/slate-react/index.d.ts b/types/slate-react/index.d.ts index c79b945a5b..31e7b95cbf 100644 --- a/types/slate-react/index.d.ts +++ b/types/slate-react/index.d.ts @@ -1,108 +1,166 @@ -// Type definitions for slate-react 0.12 +// Type definitions for slate-react 0.18 // Project: https://github.com/ianstormtaylor/slate // Definitions by: Andy Kent // Jamie Talbot // Jan Löbel // Patrick Sachs // Brandon Shelton +// Irwan Fario Subastian // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import { Mark, Node, Block, Change, Schema, Value, Stack } from 'slate'; -import * as Immutable from 'immutable'; -import * as React from 'react'; +import { Mark, Node, Change, Schema, Value, Stack, Document } from "slate"; +import * as Immutable from "immutable"; +import * as React from "react"; // Values prefixed with "data-..." (Used for spellchecking according to docs) export interface RenderAttributes { - [key: string]: any; + [key: string]: any; } export interface RenderMarkProps { - attributes: RenderAttributes; - children: React.ReactNode; - editor: Editor; - mark: Mark; - marks: Immutable.Set; - node: Node; - offset: number; - text: string; + attributes: RenderAttributes; + children: React.ReactNode; + editor: Editor; + mark: Mark; + marks: Immutable.Set; + node: Node; + offset: number; + text: string; } export interface RenderNodeProps { - attributes: RenderAttributes; - children: React.ReactNode; - editor: Editor; - isSelected: boolean; - key: string; - node: Node; - parent: Node; + attributes: RenderAttributes; + children: React.ReactNode; + editor: Editor; + isSelected: boolean; + key: string; + node: Node; + parent: Node; } export interface Plugin { - onBeforeInput?: (event: Event, change: Change, editor: Editor) => Change | void; - onBlur?: (event: Event, change: Change, editor: Editor) => Change | void; - onFocus?: (event: Event, change: Change, editor: Editor) => Change | void; - onClick?: (event: Event, change: Change, editor: Editor) => Change | void; - onCopy?: (event: Event, change: Change, editor: Editor) => Change | void; - onCut?: (event: Event, change: Change, editor: Editor) => Change | void; - onDrop?: (event: Event, change: Change, editor: Editor) => Change | void; - onKeyDown?: (event: Event, change: Change, editor: Editor) => Change | void; - onKeyUp?: (event: Event, change: Change, editor: Editor) => Change | void; - onPaste?: (event: Event, change: Change, editor: Editor) => Change | void; - onSelect?: (event: Event, change: Change, editor: Editor) => Change | void; - onChange?: (change: Change) => any; - renderEditor?: (props: RenderAttributes, editor: Editor) => object | void; - schema?: Schema; - decorateNode?: (node: Node) => Range[] | void; - renderMark?: (props: RenderMarkProps) => any; - renderNode?: (props: RenderNodeProps) => any; - renderPlaceholder?: (props: RenderAttributes) => any; - renderPortal?: (props: RenderAttributes) => any; - validateNode?: (node: Node) => any; + onBeforeInput?: ( + event: Event, + change: Change, + editor: Editor + ) => Change | void; + onBlur?: (event: Event, change: Change, editor?: Editor) => Change | void; + onFocus?: (event: Event, change: Change, editor?: Editor) => Change | void; + onClick?: (event: Event, change: Change, editor?: Editor) => Change | void; + onCopy?: (event: Event, change: Change, editor?: Editor) => Change | void; + onCut?: (event: Event, change: Change, editor?: Editor) => Change | void; + onDragEnd?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDragEnter?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDragExit?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDragLeave?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDragOver?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDragStart?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onDrop?: (event: Event, change: Change, editor?: Editor) => Change | void; + onInput?: (event: Event, change: Change, editor?: Editor) => Change | void; + onKeyDown?: ( + event: Event, + change: Change, + editor?: Editor + ) => Change | void; + onKeyUp?: (event: Event, change: Change, editor?: Editor) => Change | void; + onPaste?: (event: Event, change: Change, editor?: Editor) => Change | void; + onSelect?: (event: Event, change: Change, editor?: Editor) => Change | void; + onChange?: (change: Change, editor?: Editor) => any; + renderEditor?: (props: RenderAttributes, editor?: Editor) => object | void; + schema?: Schema; + decorateNode?: (node: Node) => Range[] | void; + renderMark?: (props: RenderMarkProps) => any; + renderNode?: (props: RenderNodeProps) => any; + renderPlaceholder?: (props: RenderAttributes) => any; + renderPortal?: (props: RenderAttributes) => any; + validateNode?: (node: Node) => any; } export interface BasicEditorProps { - value: Value; - autoCorrect?: boolean; - autoFocus?: boolean; - className?: string; - onChange?: (change: Change) => any; - placeholder?: any; - plugins?: Plugin[]; - readOnly?: boolean; - role?: string; - schema?: Schema; - spellCheck?: boolean; - style?: { [key: string]: string }; - tabIndex?: number; + value: Value; + autoCorrect?: boolean; + autoFocus?: boolean; + className?: string; + onChange?: (change: Change) => any; + placeholder?: any; + plugins?: Plugin[]; + readOnly?: boolean; + role?: string; + schema?: Schema; + spellCheck?: boolean; + style?: React.CSSProperties; + tabIndex?: number; } // tsling:disable interface-over-type-literal export type EditorProps = BasicEditorProps & Plugin; export interface EditorState { - schema: Schema; - value: Value; - stack: Stack; // [TODO] define stack + schema: Schema; + value: Value; + stack: Stack; // [TODO] define stack } export class Editor extends React.Component { - schema: Schema; - value: Value; - stack: Stack; + schema: Schema; + value: Value; + stack: Stack; - // Instance Methods - blur(): void; - change(fn: (change: Change) => any): void; - change(...args: any[]): void; - focus(): void; + readonly plugins: Plugin[]; + + // Instance Methods + blur(): void; + change(fn: (change: Change) => any): void; + change(...args: any[]): void; + focus(): void; } -export type SlateType = 'fragment' | 'html' | 'node' | 'rich' | 'text' | 'files'; +export type SlateType = + | "fragment" + | "html" + | "node" + | "rich" + | "text" + | "files"; -export function findDOMNode(node: Node): Element; -export function findDOMRange(range: Range): Range; +export function cloneFragment( + event: Event, + value: Value, + fragment?: Document, + callback?: () => void +): void; +export function findDOMNode(node: Node, win?: Window): Element; +export function findDOMRange(range: Range, win?: Window): Range; export function findNode(element: Element, value: Value): Node; export function findRange(selection: Selection, value: Value): Range; export function getEventRange(event: Event, value: Value): Range; export function getEventTransfer(event: Event): { type: SlateType; node: Node }; -export function setEventTransfer(event: Event, type: SlateType, data: any): void; +export function setEventTransfer( + event: Event, + type: SlateType, + data: any +): void; From c5a172a5962eea14f35c9a2a0e9408fe6c2db2b6 Mon Sep 17 00:00:00 2001 From: Irwan Fario Subastian Date: Thu, 30 Aug 2018 16:30:31 +1000 Subject: [PATCH 3/4] add missing changes and fix value.selection --- types/slate/index.d.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 47d3983328..f4ff94767e 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -81,7 +81,7 @@ export class Schema extends Immutable.Record({}) { export interface ValueProperties { document?: Document; - selection?: Range; + selection?: Selection; history?: History; schema?: Schema; data?: Data; @@ -921,6 +921,7 @@ export class Change extends Immutable.Record({}) { unwrapNodeByKey(key: string): Change; wrapInlineByKey(key: string, properties: InlineProperties | string): Change; wrapBlockByKey(key: string, properties: BlockProperties | string): Change; + wrapNodeByKey(key: string): Change; // by path addMarkByPath( @@ -950,6 +951,7 @@ export class Change extends Immutable.Record({}) { options: ChangeOption ): Change; mergeNodeByPath(path: Path, options: ChangeOption): Change; + mergeNodeByKey(key: string, options: ChangeOption): Change; moveNodeByPath( path: Path, newPath: Path, @@ -964,6 +966,7 @@ export class Change extends Immutable.Record({}) { options: ChangeOption ): Change; removeAllMarksByPath(path: Path, options: ChangeOption): Change; + removeAllMarksByKey(key: string, options: ChangeOption): Change; removeNodeByPath(path: Path, options: ChangeOption): Change; removeTextByPath( path: Path, @@ -980,6 +983,14 @@ export class Change extends Immutable.Record({}) { marks: Immutable.Set | null | undefined, options: ChangeOption ): Change; + replaceTextByKey( + key: string, + offset: number, + length: number, + text: string, + marks: Immutable.Set | null | undefined, + options: ChangeOption + ): Change; setMarksByPath( path: Path, offset: number, @@ -999,6 +1010,12 @@ export class Change extends Immutable.Record({}) { marks: Immutable.Set | null | undefined, options: ChangeOption ): Change; + setTextByKey( + key: string, + text: string, + marks: Immutable.Set | null | undefined, + options: ChangeOption + ): Change; splitNodeByPath( path: Path, position: number, From f2f60839ad5eec8c949fc70983f6cf6d36a3c05b Mon Sep 17 00:00:00 2001 From: Irwan Fario Subastian Date: Thu, 30 Aug 2018 16:35:06 +1000 Subject: [PATCH 4/4] =?UTF-8?q?another=20fix=20to=20decoration=20and=20sel?= =?UTF-8?q?ection=E2=80=99s=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- types/slate/index.d.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index f4ff94767e..f1cd8ecc64 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -85,16 +85,16 @@ export interface ValueProperties { history?: History; schema?: Schema; data?: Data; - decorations?: Immutable.List | null; + decorations?: Immutable.List | null; } export interface ValueJSON { document?: DocumentJSON; - selection?: Range; + selection?: Selection; history?: History; schema?: Schema; data?: Data; - decorations?: Immutable.List | null; + decorations?: Immutable.List | null; object?: "value"; } @@ -102,12 +102,12 @@ export type Path = Immutable.List | string; export class Value extends Immutable.Record({}) { document: Document; - selection: Range; + selection: Selection; history: History; schema: Schema; data: Data; object: "value"; - decorations: Immutable.List; + decorations: Immutable.List; readonly anchorText: Text; readonly focusText: Text;