-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
164 lines (135 loc) · 3.8 KB
/
types.ts
File metadata and controls
164 lines (135 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { isDiffObject, incomparable } from './symbols';
export interface ProsemirrorContentNode<Type = string> {
type: Type;
content?: ProsemirrorNode[];
}
export interface ProsemirrorTextNode {
type: 'text';
marks?: [{ name: string }];
text: string;
}
export interface UnresolvedProsemirrorTextNode {
type: 'text';
marks?: [{ name: string }];
text: ComparableEntry<string>[];
}
export type ProsemirrorNode = ProsemirrorContentNode | ProsemirrorTextNode;
export interface ProsemirrorSchema {
nodeFromJSON: (x: ProsemirrorNode) => ProsemirrorLiveNode;
}
export interface ProsemirrorLiveNode {
text?: string;
nodeSize: number;
isBlock: boolean;
forEach: (
fn: (child: ProsemirrorLiveNode, pos: number, index: number) => void
) => void;
}
export interface ProsemirrorDomSerializer {
serializeFragment: (f: {}) => any;
}
export type ProsemirrorDoc = ProsemirrorContentNode<'doc'>;
export interface Addition<T> {
add: T;
[isDiffObject]: true;
}
export interface Removal<T> {
remove: T;
[isDiffObject]: true;
}
export type Replacement<T> = Addition<T> & Removal<T>;
export type Add<T = any> = <A extends T>(obj: A) => Addition<T>;
export type Remove<T = any> = <R extends T>(obj: R) => Removal<T>;
export type Replace<T = any> = <A extends T, R extends T>(
r: R,
a: A
) => Replacement<T>;
export type ComparableEntry<T> =
| T
| ReturnType<Add<T>>
| ReturnType<Remove<T>>
| ReturnType<Replace<T>>;
export interface CompareResult<T> {
result: T;
cost: number;
}
export type CompareFn<Input, Result> = (
oldVersion: Input,
newVersion: Input,
context: CompareContext
) => typeof incomparable | CompareResult<Result>;
export type RecursiveWeightFn<T> = (t: T, weight: WeightFn<any>) => number;
export type WeightFn<T> = (t: T) => number;
export interface Memoizer {
compare: (f: Function) => CompareFn<any, any>;
weight: (f: Function) => RecursiveWeightFn<any>;
getHitRate: () => number;
clearHitRate: () => void;
}
export interface CompareContext {
add: Add;
remove: Remove;
replace: Replace;
compare: CompareFn<any, any>;
weight: WeightFn<any>;
memoizer: Memoizer;
budget?: number;
}
export type Resolvable = ProsemirrorNode | string;
export interface ResolverContext {
resolve: (el: ComparableEntry<Resolvable>) => ResolveResult<Resolvable>;
}
type DocIndex = number;
export interface ResolveAdditions {
text?: AdditionsMap<string>;
content?: AdditionsMap<ProsemirrorNode>;
}
export interface ResolveRemovals {
text?: RemovalsMap<string>;
content?: RemovalsMap<ProsemirrorNode>;
}
export interface ResolveResult<T> {
element: T;
additions: ResolveAdditions;
removals: ResolveRemovals;
}
export interface AdditionsMap<K> {
map: Map<DocIndex, K>;
children: Map<DocIndex, ResolveAdditions>;
}
export interface RemovalsMap<K> {
map: Map<'end' | DocIndex, K[]>;
children: Map<DocIndex, ResolveRemovals>;
}
export interface DecoratorContext {
schema: ProsemirrorSchema;
serializer: ProsemirrorDomSerializer;
offset: number;
decorate: (
node: ProsemirrorLiveNode,
offset: number,
additions: ResolveAdditions,
removals: ResolveRemovals
) => any[];
additions: ResolveAdditions;
removals: ResolveRemovals;
}
export type DecoratorFn = (
k: ProsemirrorLiveNode,
c: DecoratorContext
) => any[];
export interface Registry {
[key: string]: {
diff: {
compare?: CompareFn<ProsemirrorNode, any>;
weight: RecursiveWeightFn<ProsemirrorNode>;
};
render: {
resolve: <T extends Resolvable>(
r: T,
c: ResolverContext
) => ResolveResult<T>;
decorate: DecoratorFn;
};
};
}