1 | import { Editor, Path, Range, Text } from '..';
|
2 | import { Element, ElementEntry } from './element';
|
3 | /**
|
4 | * The `Node` union type represents all of the different types of nodes that
|
5 | * occur in a Slate document tree.
|
6 | */
|
7 | export type BaseNode = Editor | Element | Text;
|
8 | export type Node = Editor | Element | Text;
|
9 | export interface NodeAncestorsOptions {
|
10 | reverse?: boolean;
|
11 | }
|
12 | export interface NodeChildrenOptions {
|
13 | reverse?: boolean;
|
14 | }
|
15 | export interface NodeDescendantsOptions {
|
16 | from?: Path;
|
17 | to?: Path;
|
18 | reverse?: boolean;
|
19 | pass?: (node: NodeEntry) => boolean;
|
20 | }
|
21 | export interface NodeElementsOptions {
|
22 | from?: Path;
|
23 | to?: Path;
|
24 | reverse?: boolean;
|
25 | pass?: (node: NodeEntry) => boolean;
|
26 | }
|
27 | export interface NodeLevelsOptions {
|
28 | reverse?: boolean;
|
29 | }
|
30 | export interface NodeNodesOptions {
|
31 | from?: Path;
|
32 | to?: Path;
|
33 | reverse?: boolean;
|
34 | pass?: (entry: NodeEntry) => boolean;
|
35 | }
|
36 | export interface NodeTextsOptions {
|
37 | from?: Path;
|
38 | to?: Path;
|
39 | reverse?: boolean;
|
40 | pass?: (node: NodeEntry) => boolean;
|
41 | }
|
42 | export interface NodeInterface {
|
43 | /**
|
44 | * Get the node at a specific path, asserting that it's an ancestor node.
|
45 | */
|
46 | ancestor: (root: Node, path: Path) => Ancestor;
|
47 | /**
|
48 | * Return a generator of all the ancestor nodes above a specific path.
|
49 | *
|
50 | * By default the order is top-down, from highest to lowest ancestor in
|
51 | * the tree, but you can pass the `reverse: true` option to go bottom-up.
|
52 | */
|
53 | ancestors: (root: Node, path: Path, options?: NodeAncestorsOptions) => Generator<NodeEntry<Ancestor>, void, undefined>;
|
54 | /**
|
55 | * Get the child of a node at a specific index.
|
56 | */
|
57 | child: (root: Node, index: number) => Descendant;
|
58 | /**
|
59 | * Iterate over the children of a node at a specific path.
|
60 | */
|
61 | children: (root: Node, path: Path, options?: NodeChildrenOptions) => Generator<NodeEntry<Descendant>, void, undefined>;
|
62 | /**
|
63 | * Get an entry for the common ancesetor node of two paths.
|
64 | */
|
65 | common: (root: Node, path: Path, another: Path) => NodeEntry;
|
66 | /**
|
67 | * Get the node at a specific path, asserting that it's a descendant node.
|
68 | */
|
69 | descendant: (root: Node, path: Path) => Descendant;
|
70 | /**
|
71 | * Return a generator of all the descendant node entries inside a root node.
|
72 | */
|
73 | descendants: (root: Node, options?: NodeDescendantsOptions) => Generator<NodeEntry<Descendant>, void, undefined>;
|
74 | /**
|
75 | * Return a generator of all the element nodes inside a root node. Each iteration
|
76 | * will return an `ElementEntry` tuple consisting of `[Element, Path]`. If the
|
77 | * root node is an element it will be included in the iteration as well.
|
78 | */
|
79 | elements: (root: Node, options?: NodeElementsOptions) => Generator<ElementEntry, void, undefined>;
|
80 | /**
|
81 | * Extract props from a Node.
|
82 | */
|
83 | extractProps: (node: Node) => NodeProps;
|
84 | /**
|
85 | * Get the first node entry in a root node from a path.
|
86 | */
|
87 | first: (root: Node, path: Path) => NodeEntry;
|
88 | /**
|
89 | * Get the sliced fragment represented by a range inside a root node.
|
90 | */
|
91 | fragment: (root: Node, range: Range) => Descendant[];
|
92 | /**
|
93 | * Get the descendant node referred to by a specific path. If the path is an
|
94 | * empty array, it refers to the root node itself.
|
95 | */
|
96 | get: (root: Node, path: Path) => Node;
|
97 | /**
|
98 | * Similar to get, but returns undefined if the node does not exist.
|
99 | */
|
100 | getIf: (root: Node, path: Path) => Node | undefined;
|
101 | /**
|
102 | * Check if a descendant node exists at a specific path.
|
103 | */
|
104 | has: (root: Node, path: Path) => boolean;
|
105 | /**
|
106 | * Check if a value implements the `Node` interface.
|
107 | */
|
108 | isNode: (value: any) => value is Node;
|
109 | /**
|
110 | * Check if a value is a list of `Node` objects.
|
111 | */
|
112 | isNodeList: (value: any) => value is Node[];
|
113 | /**
|
114 | * Get the last node entry in a root node from a path.
|
115 | */
|
116 | last: (root: Node, path: Path) => NodeEntry;
|
117 | /**
|
118 | * Get the node at a specific path, ensuring it's a leaf text node.
|
119 | */
|
120 | leaf: (root: Node, path: Path) => Text;
|
121 | /**
|
122 | * Return a generator of the in a branch of the tree, from a specific path.
|
123 | *
|
124 | * By default the order is top-down, from highest to lowest node in the tree,
|
125 | * but you can pass the `reverse: true` option to go bottom-up.
|
126 | */
|
127 | levels: (root: Node, path: Path, options?: NodeLevelsOptions) => Generator<NodeEntry, void, undefined>;
|
128 | /**
|
129 | * Check if a node matches a set of props.
|
130 | */
|
131 | matches: (node: Node, props: Partial<Node>) => boolean;
|
132 | /**
|
133 | * Return a generator of all the node entries of a root node. Each entry is
|
134 | * returned as a `[Node, Path]` tuple, with the path referring to the node's
|
135 | * position inside the root node.
|
136 | */
|
137 | nodes: (root: Node, options?: NodeNodesOptions) => Generator<NodeEntry, void, undefined>;
|
138 | /**
|
139 | * Get the parent of a node at a specific path.
|
140 | */
|
141 | parent: (root: Node, path: Path) => Ancestor;
|
142 | /**
|
143 | * Get the concatenated text string of a node's content.
|
144 | *
|
145 | * Note that this will not include spaces or line breaks between block nodes.
|
146 | * It is not a user-facing string, but a string for performing offset-related
|
147 | * computations for a node.
|
148 | */
|
149 | string: (node: Node) => string;
|
150 | /**
|
151 | * Return a generator of all leaf text nodes in a root node.
|
152 | */
|
153 | texts: (root: Node, options?: NodeTextsOptions) => Generator<NodeEntry<Text>, void, undefined>;
|
154 | }
|
155 | export declare const Node: NodeInterface;
|
156 | /**
|
157 | * The `Descendant` union type represents nodes that are descendants in the
|
158 | * tree. It is returned as a convenience in certain cases to narrow a value
|
159 | * further than the more generic `Node` union.
|
160 | */
|
161 | export type Descendant = Element | Text;
|
162 | /**
|
163 | * The `Ancestor` union type represents nodes that are ancestors in the tree.
|
164 | * It is returned as a convenience in certain cases to narrow a value further
|
165 | * than the more generic `Node` union.
|
166 | */
|
167 | export type Ancestor = Editor | Element;
|
168 | /**
|
169 | * `NodeEntry` objects are returned when iterating over the nodes in a Slate
|
170 | * document tree. They consist of the node and its `Path` relative to the root
|
171 | * node in the document.
|
172 | */
|
173 | export type NodeEntry<T extends Node = Node> = [T, Path];
|
174 | /**
|
175 | * Convenience type for returning the props of a node.
|
176 | */
|
177 | export type NodeProps = Omit<Editor, 'children'> | Omit<Element, 'children'> | Omit<Text, 'text'>;
|
178 | //# sourceMappingURL=node.d.ts.map |
\ | No newline at end of file |