[Slate] Add Editor Definition

Editor is not defined in @types/slate, making it difficult to develop
for slate in Typescript if not using slate-react ( and therefore
@types/slate-react, where the React mounted editor is defined).
This commit is contained in:
Sebastian Greaves
2018-10-24 13:44:38 +01:00
parent 3b01bb29b1
commit c60ad4ab65
2 changed files with 33 additions and 2 deletions
+19 -1
View File
@@ -7,10 +7,10 @@
// Kalley Powell <https://github.com/kalley>
// Francesco Agnoletto <https://github.com/Kornil>
// Irwan Fario Subastian <https://github.com/isubasti>
// Sebastian Greaves <https://github.com/sgreav>
// 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<number>;
}
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 {};
+14 -1
View File
@@ -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", () => { });