diff --git a/types/slate/index.d.ts b/types/slate/index.d.ts index 7b93e66314..31233b8541 100644 --- a/types/slate/index.d.ts +++ b/types/slate/index.d.ts @@ -13,6 +13,7 @@ // Han Jeon // Kay Delaney // Yuichiro Tsuchiya +// Kamil KamiƄski // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 import * as Immutable from "immutable"; @@ -491,7 +492,7 @@ declare class BaseNode extends Immutable.Record({}) { createSelection(properties: SelectionProperties | SelectionJSON | Selection | Range): Selection; descendants(options?: IterableOptions): Iterable<[Node, Immutable.List]>; filterDescendants(predicate?: (node: Node, path: Immutable.List) => boolean): Immutable.List; - findDescendants(predicate?: (node: Node, path: Immutable.List) => boolean): Node | null; + findDescendant(predicate?: (node: Node, path: Immutable.List) => boolean): Node | null; forEachDescendant(predicate?: (node: Node, path: Immutable.List) => boolean): void; getActiveMarksAtRange(range: RangeTypeProperties | RangeTypeJSON | RangeType): Immutable.Set; getAncestors(path: Path): Immutable.List | null; diff --git a/types/slate/slate-tests.ts b/types/slate/slate-tests.ts index 9f1b483c81..09f15faf67 100644 --- a/types/slate/slate-tests.ts +++ b/types/slate/slate-tests.ts @@ -31,12 +31,12 @@ data['foo']; const value = Value.create({ data }); -const node: BlockJSON = { - object: "block", - type: "paragraph", - nodes: [ - { - object: "text", +const nodeJSON: BlockJSON = { + object: "block", + type: "paragraph", + nodes: [ + { + object: "text", key: "a", text: "example", marks: [{ @@ -44,16 +44,26 @@ const node: BlockJSON = { type: "mark", object: "mark" }] - } - ] + } + ] }; const doc = Document.fromJSON({ - object: "document", - data: {}, - nodes: [node] + object: "document", + data: {}, + nodes: [nodeJSON] }); +const node = new Block(nodeJSON); + +doc.findDescendant(); +doc.findDescendant(node => node.object === 'block' && node.type === 'paragraph'); +doc.findDescendant((node, path) => true); + +node.findDescendant(); +node.findDescendant(node => node.object === 'block'); +node.findDescendant((node, path) => false); + const schema: SchemaProperties = { document: { nodes: [ @@ -168,13 +178,13 @@ editor .flush() .focus() .insertBlock({ - type: "image", - key: "b", - data: { - src: "http://placekitten.com/200/300", - alt: "Kittens", - className: "img-responsive" - } + type: "image", + key: "b", + data: { + src: "http://placekitten.com/200/300", + alt: "Kittens", + className: "img-responsive" + } }) .insertBlockAtRange(range, "text") .insertFragment(doc)