UNPKG

3.81 kBTypeScriptView Raw
1import { ExtendedType, Node, Path, Range } from '..';
2export type BaseInsertNodeOperation = {
3 type: 'insert_node';
4 path: Path;
5 node: Node;
6};
7export type InsertNodeOperation = ExtendedType<'InsertNodeOperation', BaseInsertNodeOperation>;
8export type BaseInsertTextOperation = {
9 type: 'insert_text';
10 path: Path;
11 offset: number;
12 text: string;
13};
14export type InsertTextOperation = ExtendedType<'InsertTextOperation', BaseInsertTextOperation>;
15export type BaseMergeNodeOperation = {
16 type: 'merge_node';
17 path: Path;
18 position: number;
19 properties: Partial<Node>;
20};
21export type MergeNodeOperation = ExtendedType<'MergeNodeOperation', BaseMergeNodeOperation>;
22export type BaseMoveNodeOperation = {
23 type: 'move_node';
24 path: Path;
25 newPath: Path;
26};
27export type MoveNodeOperation = ExtendedType<'MoveNodeOperation', BaseMoveNodeOperation>;
28export type BaseRemoveNodeOperation = {
29 type: 'remove_node';
30 path: Path;
31 node: Node;
32};
33export type RemoveNodeOperation = ExtendedType<'RemoveNodeOperation', BaseRemoveNodeOperation>;
34export type BaseRemoveTextOperation = {
35 type: 'remove_text';
36 path: Path;
37 offset: number;
38 text: string;
39};
40export type RemoveTextOperation = ExtendedType<'RemoveTextOperation', BaseRemoveTextOperation>;
41export type BaseSetNodeOperation = {
42 type: 'set_node';
43 path: Path;
44 properties: Partial<Node>;
45 newProperties: Partial<Node>;
46};
47export type SetNodeOperation = ExtendedType<'SetNodeOperation', BaseSetNodeOperation>;
48export type BaseSetSelectionOperation = {
49 type: 'set_selection';
50 properties: null;
51 newProperties: Range;
52} | {
53 type: 'set_selection';
54 properties: Partial<Range>;
55 newProperties: Partial<Range>;
56} | {
57 type: 'set_selection';
58 properties: Range;
59 newProperties: null;
60};
61export type SetSelectionOperation = ExtendedType<'SetSelectionOperation', BaseSetSelectionOperation>;
62export type BaseSplitNodeOperation = {
63 type: 'split_node';
64 path: Path;
65 position: number;
66 properties: Partial<Node>;
67};
68export type SplitNodeOperation = ExtendedType<'SplitNodeOperation', BaseSplitNodeOperation>;
69export type NodeOperation = InsertNodeOperation | MergeNodeOperation | MoveNodeOperation | RemoveNodeOperation | SetNodeOperation | SplitNodeOperation;
70export type SelectionOperation = SetSelectionOperation;
71export type TextOperation = InsertTextOperation | RemoveTextOperation;
72/**
73 * `Operation` objects define the low-level instructions that Slate editors use
74 * to apply changes to their internal state. Representing all changes as
75 * operations is what allows Slate editors to easily implement history,
76 * collaboration, and other features.
77 */
78export type BaseOperation = NodeOperation | SelectionOperation | TextOperation;
79export type Operation = ExtendedType<'Operation', BaseOperation>;
80export interface OperationInterface {
81 /**
82 * Check if a value is a `NodeOperation` object.
83 */
84 isNodeOperation: (value: any) => value is NodeOperation;
85 /**
86 * Check if a value is an `Operation` object.
87 */
88 isOperation: (value: any) => value is Operation;
89 /**
90 * Check if a value is a list of `Operation` objects.
91 */
92 isOperationList: (value: any) => value is Operation[];
93 /**
94 * Check if a value is a `SelectionOperation` object.
95 */
96 isSelectionOperation: (value: any) => value is SelectionOperation;
97 /**
98 * Check if a value is a `TextOperation` object.
99 */
100 isTextOperation: (value: any) => value is TextOperation;
101 /**
102 * Invert an operation, returning a new operation that will exactly undo the
103 * original when applied.
104 */
105 inverse: (op: Operation) => Operation;
106}
107export declare const Operation: OperationInterface;
108//# sourceMappingURL=operation.d.ts.map
\No newline at end of file