diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index f1cd8ecc64..6f10f91378 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -7,10 +7,10 @@ // Kalley Powell // Francesco Agnoletto // Irwan Fario Subastian +// Sebastian Greaves // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 import * as Immutable from "immutable"; - export class Data extends Immutable.Record({}) { [key: string]: any; @@ -1527,4 +1527,22 @@ export interface PathUtils { ): Immutable.List; } +export class Editor extends Immutable.Record({}) { + object: "editor"; + onChange: (change: Change) => void; + plugins: any[]; + readOnly: boolean; + value: Value; + + change(customChange: (change: Change, ...args: any[]) => Change): void; + command(name: string, ...args: any[]): void; + event(handler: string, event: any): void; + query(query: string, ...args: any[]): any; + registerCommand(command: string): void; + registerQuery(query: string): void; + run(key: string, ...args: any[]): any; + setReadOnly(readOnly: boolean): Editor; + setValue(value: Value, options?: object): Editor; +} + export {}; diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index 91ef2dadcb..38faf7e207 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -1,4 +1,4 @@ -import { Value, Data, BlockJSON, Document } from "slate"; +import { Value, Data, BlockJSON, Document, Editor, Change } from "slate"; const data = Data.create({ foo: "bar " }); const value = Value.create({ data }); @@ -45,3 +45,16 @@ const doc = Document.fromJSON({ data: {}, nodes: [node] }); + +const editor = new Editor({ value }); +editor.change((change: Change) => { + return change.insertText("test"); +}); + +editor.registerQuery("testQuery"); +editor.registerCommand("testCommand"); +editor.setReadOnly(true).setValue(value); +editor.command("testCommand"); +editor.query("testQuery"); +editor.run("testCommand"); +editor.event("mouseDown", () => { });