mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
[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:
Vendored
+19
-1
@@ -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 {};
|
||||
|
||||
@@ -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", () => { });
|
||||
|
||||
Reference in New Issue
Block a user