UNPKG

4.66 kBTypeScriptView Raw
1import { InsertNodeOperation, MergeNodeOperation, MoveNodeOperation, Operation, RemoveNodeOperation, SplitNodeOperation } from '..';
2import { TextDirection } from '../types/types';
3/**
4 * `Path` arrays are a list of indexes that describe a node's exact position in
5 * a Slate node tree. Although they are usually relative to the root `Editor`
6 * object, they can be relative to any `Node` object.
7 */
8export type Path = number[];
9export interface PathAncestorsOptions {
10 reverse?: boolean;
11}
12export interface PathLevelsOptions {
13 reverse?: boolean;
14}
15export interface PathTransformOptions {
16 affinity?: TextDirection | null;
17}
18export interface PathInterface {
19 /**
20 * Get a list of ancestor paths for a given path.
21 *
22 * The paths are sorted from shallowest to deepest ancestor. However, if the
23 * `reverse: true` option is passed, they are reversed.
24 */
25 ancestors: (path: Path, options?: PathAncestorsOptions) => Path[];
26 /**
27 * Get the common ancestor path of two paths.
28 */
29 common: (path: Path, another: Path) => Path;
30 /**
31 * Compare a path to another, returning an integer indicating whether the path
32 * was before, at, or after the other.
33 *
34 * Note: Two paths of unequal length can still receive a `0` result if one is
35 * directly above or below the other. If you want exact matching, use
36 * [[Path.equals]] instead.
37 */
38 compare: (path: Path, another: Path) => -1 | 0 | 1;
39 /**
40 * Check if a path ends after one of the indexes in another.
41 */
42 endsAfter: (path: Path, another: Path) => boolean;
43 /**
44 * Check if a path ends at one of the indexes in another.
45 */
46 endsAt: (path: Path, another: Path) => boolean;
47 /**
48 * Check if a path ends before one of the indexes in another.
49 */
50 endsBefore: (path: Path, another: Path) => boolean;
51 /**
52 * Check if a path is exactly equal to another.
53 */
54 equals: (path: Path, another: Path) => boolean;
55 /**
56 * Check if the path of previous sibling node exists
57 */
58 hasPrevious: (path: Path) => boolean;
59 /**
60 * Check if a path is after another.
61 */
62 isAfter: (path: Path, another: Path) => boolean;
63 /**
64 * Check if a path is an ancestor of another.
65 */
66 isAncestor: (path: Path, another: Path) => boolean;
67 /**
68 * Check if a path is before another.
69 */
70 isBefore: (path: Path, another: Path) => boolean;
71 /**
72 * Check if a path is a child of another.
73 */
74 isChild: (path: Path, another: Path) => boolean;
75 /**
76 * Check if a path is equal to or an ancestor of another.
77 */
78 isCommon: (path: Path, another: Path) => boolean;
79 /**
80 * Check if a path is a descendant of another.
81 */
82 isDescendant: (path: Path, another: Path) => boolean;
83 /**
84 * Check if a path is the parent of another.
85 */
86 isParent: (path: Path, another: Path) => boolean;
87 /**
88 * Check is a value implements the `Path` interface.
89 */
90 isPath: (value: any) => value is Path;
91 /**
92 * Check if a path is a sibling of another.
93 */
94 isSibling: (path: Path, another: Path) => boolean;
95 /**
96 * Get a list of paths at every level down to a path. Note: this is the same
97 * as `Path.ancestors`, but including the path itself.
98 *
99 * The paths are sorted from shallowest to deepest. However, if the `reverse:
100 * true` option is passed, they are reversed.
101 */
102 levels: (path: Path, options?: PathLevelsOptions) => Path[];
103 /**
104 * Given a path, get the path to the next sibling node.
105 */
106 next: (path: Path) => Path;
107 /**
108 * Returns whether this operation can affect paths or not. Used as an
109 * optimization when updating dirty paths during normalization
110 *
111 * NOTE: This *must* be kept in sync with the implementation of 'transform'
112 * below
113 */
114 operationCanTransformPath: (operation: Operation) => operation is InsertNodeOperation | RemoveNodeOperation | MergeNodeOperation | SplitNodeOperation | MoveNodeOperation;
115 /**
116 * Given a path, return a new path referring to the parent node above it.
117 */
118 parent: (path: Path) => Path;
119 /**
120 * Given a path, get the path to the previous sibling node.
121 */
122 previous: (path: Path) => Path;
123 /**
124 * Get a path relative to an ancestor.
125 */
126 relative: (path: Path, ancestor: Path) => Path;
127 /**
128 * Transform a path by an operation.
129 */
130 transform: (path: Path, operation: Operation, options?: PathTransformOptions) => Path | null;
131}
132export declare const Path: PathInterface;
133//# sourceMappingURL=path.d.ts.map
\No newline at end of file