UNPKG

2.66 kBTypeScriptView Raw
1import { ExtendedType, Operation, Path, Point, PointEntry } from '..';
2import { RangeDirection } from '../types/types';
3/**
4 * `Range` objects are a set of points that refer to a specific span of a Slate
5 * document. They can define a span inside a single node or a can span across
6 * multiple nodes.
7 */
8export interface BaseRange {
9 anchor: Point;
10 focus: Point;
11}
12export type Range = ExtendedType<'Range', BaseRange>;
13export interface RangeEdgesOptions {
14 reverse?: boolean;
15}
16export interface RangeTransformOptions {
17 affinity?: RangeDirection | null;
18}
19export interface RangeInterface {
20 /**
21 * Get the start and end points of a range, in the order in which they appear
22 * in the document.
23 */
24 edges: (range: Range, options?: RangeEdgesOptions) => [Point, Point];
25 /**
26 * Get the end point of a range.
27 */
28 end: (range: Range) => Point;
29 /**
30 * Check if a range is exactly equal to another.
31 */
32 equals: (range: Range, another: Range) => boolean;
33 /**
34 * Check if a range includes a path, a point or part of another range.
35 */
36 includes: (range: Range, target: Path | Point | Range) => boolean;
37 /**
38 * Get the intersection of a range with another.
39 */
40 intersection: (range: Range, another: Range) => Range | null;
41 /**
42 * Check if a range is backward, meaning that its anchor point appears in the
43 * document _after_ its focus point.
44 */
45 isBackward: (range: Range) => boolean;
46 /**
47 * Check if a range is collapsed, meaning that both its anchor and focus
48 * points refer to the exact same position in the document.
49 */
50 isCollapsed: (range: Range) => boolean;
51 /**
52 * Check if a range is expanded.
53 *
54 * This is the opposite of [[Range.isCollapsed]] and is provided for legibility.
55 */
56 isExpanded: (range: Range) => boolean;
57 /**
58 * Check if a range is forward.
59 *
60 * This is the opposite of [[Range.isBackward]] and is provided for legibility.
61 */
62 isForward: (range: Range) => boolean;
63 /**
64 * Check if a value implements the [[Range]] interface.
65 */
66 isRange: (value: any) => value is Range;
67 /**
68 * Iterate through all of the point entries in a range.
69 */
70 points: (range: Range) => Generator<PointEntry, void, undefined>;
71 /**
72 * Get the start point of a range.
73 */
74 start: (range: Range) => Point;
75 /**
76 * Transform a range by an operation.
77 */
78 transform: (range: Range, op: Operation, options?: RangeTransformOptions) => Range | null;
79}
80export declare const Range: RangeInterface;
81//# sourceMappingURL=range.d.ts.map
\No newline at end of file