svedit 0.11.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -82
- package/dist/Command.svelte.d.ts +54 -29
- package/dist/Command.svelte.d.ts.map +1 -1
- package/dist/Command.svelte.js +286 -283
- package/dist/CustomProperty.svelte +3 -5
- package/dist/CustomProperty.svelte.d.ts +3 -6
- package/dist/CustomProperty.svelte.d.ts.map +1 -1
- package/dist/KeyMapper.svelte.d.ts +19 -6
- package/dist/KeyMapper.svelte.d.ts.map +1 -1
- package/dist/KeyMapper.svelte.js +95 -112
- package/dist/Node.svelte +40 -9
- package/dist/Node.svelte.d.ts +3 -5
- package/dist/Node.svelte.d.ts.map +1 -1
- package/dist/NodeArrayProperty.svelte +142 -18
- package/dist/NodeArrayProperty.svelte.d.ts +3 -5
- package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
- package/dist/NodeCaret.svelte +1 -1
- package/dist/NodeCaret.svelte.d.ts +6 -14
- package/dist/NodeCaret.svelte.d.ts.map +1 -1
- package/dist/NodeGap.svelte +60 -12
- package/dist/NodeGap.svelte.d.ts +7 -14
- package/dist/NodeGap.svelte.d.ts.map +1 -1
- package/dist/NodeGapMarkers.svelte +19 -10
- package/dist/NodeGapMarkers.svelte.d.ts +6 -11
- package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
- package/dist/NodeSelectionMarkers.svelte +20 -6
- package/dist/NodeSelectionMarkers.svelte.d.ts +2 -5
- package/dist/NodeSelectionMarkers.svelte.d.ts.map +1 -1
- package/dist/Session.svelte.d.ts +85 -116
- package/dist/Session.svelte.d.ts.map +1 -1
- package/dist/Session.svelte.js +543 -571
- package/dist/Svedit.svelte +243 -216
- package/dist/Svedit.svelte.d.ts +30 -10
- package/dist/Svedit.svelte.d.ts.map +1 -1
- package/dist/{AnnotatedTextProperty.svelte → TextProperty.svelte} +71 -56
- package/dist/TextProperty.svelte.d.ts +5 -0
- package/dist/TextProperty.svelte.d.ts.map +1 -0
- package/dist/Transaction.svelte.d.ts +101 -126
- package/dist/Transaction.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.js +843 -827
- package/dist/UnknownNode.svelte +4 -3
- package/dist/UnknownNode.svelte.d.ts +5 -9
- package/dist/UnknownNode.svelte.d.ts.map +1 -1
- package/dist/doc_utils.d.ts +109 -122
- package/dist/doc_utils.d.ts.map +1 -1
- package/dist/doc_utils.js +726 -698
- package/dist/index.d.ts +20 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -18
- package/dist/node_visibility.svelte.d.ts +132 -5
- package/dist/node_visibility.svelte.d.ts.map +1 -1
- package/dist/node_visibility.svelte.js +535 -642
- package/dist/paste_utils.d.ts +11 -43
- package/dist/paste_utils.d.ts.map +1 -1
- package/dist/paste_utils.js +111 -149
- package/dist/transforms.svelte.d.ts +9 -7
- package/dist/transforms.svelte.d.ts.map +1 -1
- package/dist/transforms.svelte.js +126 -152
- package/dist/types.d.ts +329 -291
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils.d.ts +79 -95
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +392 -305
- package/package.json +69 -67
- package/src/lib/{Command.svelte.js → Command.svelte.ts} +111 -41
- package/src/lib/CustomProperty.svelte +3 -5
- package/src/lib/{KeyMapper.svelte.js → KeyMapper.svelte.ts} +28 -11
- package/src/lib/Node.svelte +40 -9
- package/src/lib/NodeArrayProperty.svelte +142 -18
- package/src/lib/NodeCaret.svelte +1 -1
- package/src/lib/NodeGap.svelte +60 -12
- package/src/lib/NodeGapMarkers.svelte +19 -10
- package/src/lib/NodeSelectionMarkers.svelte +20 -6
- package/src/lib/Session.svelte.ts +656 -0
- package/src/lib/Svedit.svelte +243 -216
- package/src/lib/{AnnotatedTextProperty.svelte → TextProperty.svelte} +71 -56
- package/src/lib/Transaction.svelte.ts +1020 -0
- package/src/lib/UnknownNode.svelte +4 -3
- package/src/lib/doc_utils.ts +1120 -0
- package/src/lib/{index.js → index.ts} +48 -1
- package/src/lib/node_visibility.svelte.ts +658 -0
- package/src/lib/{paste_utils.js → paste_utils.ts} +51 -59
- package/src/lib/{transforms.svelte.js → transforms.svelte.ts} +44 -27
- package/src/lib/{types.d.ts → types.ts} +250 -103
- package/src/lib/utils.ts +660 -0
- package/dist/AnnotatedTextProperty.svelte.d.ts +0 -7
- package/dist/AnnotatedTextProperty.svelte.d.ts.map +0 -1
- package/src/lib/Session.svelte.js +0 -575
- package/src/lib/Transaction.svelte.js +0 -846
- package/src/lib/doc_utils.js +0 -807
- package/src/lib/node_visibility.svelte.js +0 -718
- package/src/lib/utils.js +0 -465
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import type Session from './Session.svelte.js';
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
// ===== SVELTE TYPE IMPORTS =====
|
|
5
|
-
|
|
2
|
+
import type { VisibilityRegistryApi } from './node_visibility.svelte.js';
|
|
6
3
|
/**
|
|
7
4
|
* Import Svelte's Snippet type for properly typing children in components
|
|
8
5
|
*/
|
|
9
|
-
import type {
|
|
10
|
-
|
|
11
|
-
// ===== SELECTION TYPE DEFINITIONS =====
|
|
12
|
-
|
|
6
|
+
import type { Snippet } from 'svelte';
|
|
13
7
|
/**
|
|
14
8
|
* A unique node identifier.
|
|
15
9
|
*
|
|
@@ -18,469 +12,513 @@ import type { Component, Snippet } from 'svelte';
|
|
|
18
12
|
* dashes, and must not contain `__`.
|
|
19
13
|
*/
|
|
20
14
|
export type NodeId = string;
|
|
21
|
-
|
|
15
|
+
export type DynamicRecord = Record<string, any>;
|
|
16
|
+
export type SessionConfig = DynamicRecord;
|
|
17
|
+
export type CommandRegistry = DynamicRecord;
|
|
18
|
+
export type DocumentOperation = [string, ...any[]];
|
|
22
19
|
/**
|
|
23
20
|
* Array of IDs, property names (strings), or indexes (integers) that identify a node or property in the document.
|
|
24
21
|
* String segments must follow the same path segment rules as NodeId.
|
|
25
22
|
*/
|
|
26
23
|
export type DocumentPath = Array<string | number>;
|
|
27
|
-
|
|
28
24
|
/**
|
|
29
25
|
* Text selection within a text property
|
|
30
26
|
*/
|
|
31
27
|
export type TextSelection = {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
type: 'text';
|
|
29
|
+
path: DocumentPath;
|
|
30
|
+
anchor_offset: number;
|
|
31
|
+
focus_offset: number;
|
|
36
32
|
};
|
|
37
|
-
|
|
38
33
|
/**
|
|
39
34
|
* Node selection within a node array
|
|
40
35
|
*/
|
|
41
36
|
export type NodeSelection = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
37
|
+
type: 'node';
|
|
38
|
+
path: DocumentPath;
|
|
39
|
+
anchor_offset: number;
|
|
40
|
+
focus_offset: number;
|
|
46
41
|
};
|
|
47
|
-
|
|
48
42
|
/**
|
|
49
43
|
* Property selection within a node
|
|
50
44
|
*/
|
|
51
45
|
export type PropertySelection = {
|
|
52
|
-
|
|
53
|
-
|
|
46
|
+
type: 'property';
|
|
47
|
+
path: DocumentPath;
|
|
54
48
|
};
|
|
55
|
-
|
|
56
49
|
/**
|
|
57
50
|
* Union type for all possible selection types
|
|
58
51
|
*/
|
|
59
52
|
export type Selection = TextSelection | NodeSelection | PropertySelection;
|
|
60
|
-
|
|
61
53
|
/**
|
|
62
54
|
* Represents only the range (no direction and payload) of a NodeSelection or TextSelection
|
|
63
55
|
*/
|
|
64
56
|
export type SelectionRange = {
|
|
65
|
-
|
|
66
|
-
|
|
57
|
+
start_offset: number;
|
|
58
|
+
end_offset: number;
|
|
67
59
|
};
|
|
68
|
-
|
|
69
|
-
// ===== SCHEMA TYPE DEFINITIONS =====
|
|
70
|
-
|
|
71
60
|
/**
|
|
72
61
|
* Basic scalar types supported by the schema system.
|
|
73
62
|
*/
|
|
74
63
|
export type ScalarType = 'string' | 'number' | 'boolean' | 'integer' | 'datetime';
|
|
75
|
-
|
|
76
64
|
/**
|
|
77
65
|
* Array types for collections of scalar values.
|
|
78
66
|
*/
|
|
79
67
|
export type ArrayType = 'string_array' | 'number_array' | 'boolean_array' | 'integer_array';
|
|
80
|
-
|
|
81
68
|
/**
|
|
82
69
|
* Special types for rich content.
|
|
83
70
|
*/
|
|
84
|
-
export type RichType = '
|
|
85
|
-
|
|
71
|
+
export type RichType = 'text';
|
|
86
72
|
/**
|
|
87
73
|
* Node reference types for linking to other nodes.
|
|
88
74
|
*/
|
|
89
75
|
export type ReferenceType = 'node' | 'node_array';
|
|
90
|
-
|
|
91
76
|
/**
|
|
92
77
|
* All primitive types that can be used in property definitions.
|
|
93
78
|
*/
|
|
94
79
|
export type PrimitiveType = ScalarType | ArrayType | RichType;
|
|
95
|
-
|
|
96
80
|
/**
|
|
97
81
|
* All possible property types in schemas.
|
|
98
82
|
*/
|
|
99
83
|
export type PropertyType = PrimitiveType | ReferenceType;
|
|
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
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Maps a schema property definition to the runtime value type it stores.
|
|
86
|
+
*/
|
|
87
|
+
export type PropertyValue<P extends PropertyDefinition> = P extends {
|
|
88
|
+
type: 'string';
|
|
89
|
+
values: readonly (infer Value extends string)[];
|
|
90
|
+
} ? Value : P extends {
|
|
91
|
+
type: 'string';
|
|
92
|
+
} ? string : P extends {
|
|
93
|
+
type: 'number';
|
|
94
|
+
} ? number : P extends {
|
|
95
|
+
type: 'integer';
|
|
96
|
+
} ? number : P extends {
|
|
97
|
+
type: 'boolean';
|
|
98
|
+
} ? boolean : P extends {
|
|
99
|
+
type: 'datetime';
|
|
100
|
+
} ? string : P extends {
|
|
101
|
+
type: 'string_array';
|
|
102
|
+
} ? string[] : P extends {
|
|
103
|
+
type: 'number_array';
|
|
104
|
+
} ? number[] : P extends {
|
|
105
|
+
type: 'integer_array';
|
|
106
|
+
} ? number[] : P extends {
|
|
107
|
+
type: 'boolean_array';
|
|
108
|
+
} ? boolean[] : P extends {
|
|
109
|
+
type: 'text';
|
|
110
|
+
} ? Text : P extends {
|
|
111
|
+
type: 'node';
|
|
112
|
+
} ? NodeId : P extends {
|
|
113
|
+
type: 'node_array';
|
|
114
|
+
} ? NodeArray : never;
|
|
115
|
+
/**
|
|
116
|
+
* The runtime shape of a node of a specific type, derived from the schema.
|
|
117
|
+
*
|
|
118
|
+
* Falls back to the untyped DocumentNode when the schema is not a concrete
|
|
119
|
+
* schema literal (e.g. the DocumentSchema default of Session).
|
|
120
|
+
*/
|
|
121
|
+
export type NodeOfType<S extends DocumentSchema, T extends keyof S> = string extends keyof S ? DocumentNode : {
|
|
122
|
+
id: NodeId;
|
|
123
|
+
type: T;
|
|
124
|
+
} & {
|
|
125
|
+
[K in keyof S[T]['properties']]: PropertyValue<S[T]['properties'][K]>;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Discriminated union of all node types in a schema. Narrow with
|
|
129
|
+
* `node.type === '...'` to get exact property types.
|
|
130
|
+
*
|
|
131
|
+
* Falls back to the untyped DocumentNode when the schema is not a concrete
|
|
132
|
+
* schema literal (e.g. the DocumentSchema default of Session).
|
|
133
|
+
*/
|
|
134
|
+
export type AnyNode<S extends DocumentSchema> = string extends keyof S ? DocumentNode : {
|
|
135
|
+
[T in keyof S]: NodeOfType<S, T>;
|
|
136
|
+
}[keyof S];
|
|
137
|
+
/**
|
|
138
|
+
* Convenience map from node type name to its runtime node shape,
|
|
139
|
+
* e.g. `NodeMap<typeof document_schema>['story']`.
|
|
140
|
+
*/
|
|
141
|
+
export type NodeMap<S extends DocumentSchema> = {
|
|
142
|
+
[T in keyof S]: NodeOfType<S, T>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Assert that a node is of the given type. Narrows the static type and
|
|
146
|
+
* checks at runtime — for call sites that know what they expect.
|
|
147
|
+
*/
|
|
148
|
+
/**
|
|
149
|
+
* A property that stores text with optional marks and annotations and required allow_newlines setting.
|
|
150
|
+
*/
|
|
151
|
+
export type TextProperty = {
|
|
152
|
+
type: 'text';
|
|
153
|
+
mark_types?: string[];
|
|
154
|
+
annotation_types?: string[];
|
|
155
|
+
allow_newlines: boolean;
|
|
156
|
+
};
|
|
158
157
|
/**
|
|
159
158
|
* A property that stores a string value.
|
|
160
159
|
*/
|
|
161
160
|
export type StringProperty = {
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
type: 'string';
|
|
162
|
+
default?: string;
|
|
163
|
+
values?: readonly string[];
|
|
164
164
|
};
|
|
165
|
-
|
|
166
165
|
/**
|
|
167
166
|
* A property that stores a number value.
|
|
168
167
|
*/
|
|
169
168
|
export type NumberProperty = {
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
type: 'number';
|
|
170
|
+
default?: number;
|
|
172
171
|
};
|
|
173
|
-
|
|
174
172
|
/**
|
|
175
173
|
* A property that stores a boolean value.
|
|
176
174
|
*/
|
|
177
175
|
export type BooleanProperty = {
|
|
178
|
-
|
|
179
|
-
|
|
176
|
+
type: 'boolean';
|
|
177
|
+
default?: boolean;
|
|
180
178
|
};
|
|
181
|
-
|
|
182
179
|
/**
|
|
183
180
|
* A property that stores an integer value.
|
|
184
181
|
*/
|
|
185
182
|
export type IntegerProperty = {
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
type: 'integer';
|
|
184
|
+
default?: number;
|
|
185
|
+
min?: number;
|
|
186
|
+
max?: number;
|
|
188
187
|
};
|
|
189
|
-
|
|
190
188
|
/**
|
|
191
189
|
* A property that stores a datetime value.
|
|
192
190
|
*/
|
|
193
191
|
export type DatetimeProperty = {
|
|
194
|
-
|
|
195
|
-
|
|
192
|
+
type: 'datetime';
|
|
193
|
+
default?: string;
|
|
196
194
|
};
|
|
197
|
-
|
|
198
195
|
/**
|
|
199
196
|
* A property that stores an array of strings.
|
|
200
197
|
*/
|
|
201
198
|
export type StringArrayProperty = {
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
type: 'string_array';
|
|
200
|
+
default?: string[];
|
|
204
201
|
};
|
|
205
|
-
|
|
206
202
|
/**
|
|
207
203
|
* A property that stores an array of numbers.
|
|
208
204
|
*/
|
|
209
205
|
export type NumberArrayProperty = {
|
|
210
|
-
|
|
211
|
-
|
|
206
|
+
type: 'number_array';
|
|
207
|
+
default?: number[];
|
|
212
208
|
};
|
|
213
|
-
|
|
214
209
|
/**
|
|
215
210
|
* A property that stores an array of booleans.
|
|
216
211
|
*/
|
|
217
212
|
export type BooleanArrayProperty = {
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
type: 'boolean_array';
|
|
214
|
+
default?: boolean[];
|
|
220
215
|
};
|
|
221
|
-
|
|
222
216
|
/**
|
|
223
217
|
* A property that stores an array of integers.
|
|
224
218
|
*/
|
|
225
219
|
export type IntegerArrayProperty = {
|
|
226
|
-
|
|
227
|
-
|
|
220
|
+
type: 'integer_array';
|
|
221
|
+
default?: number[];
|
|
228
222
|
};
|
|
229
|
-
|
|
230
223
|
/**
|
|
231
|
-
* A property that stores a primitive value (excluding
|
|
224
|
+
* A property that stores a primitive value (excluding text).
|
|
232
225
|
*/
|
|
233
|
-
export type PrimitiveProperty =
|
|
234
|
-
| StringProperty
|
|
235
|
-
| NumberProperty
|
|
236
|
-
| BooleanProperty
|
|
237
|
-
| IntegerProperty
|
|
238
|
-
| DatetimeProperty
|
|
239
|
-
| StringArrayProperty
|
|
240
|
-
| NumberArrayProperty
|
|
241
|
-
| BooleanArrayProperty
|
|
242
|
-
| IntegerArrayProperty;
|
|
243
|
-
|
|
226
|
+
export type PrimitiveProperty = StringProperty | NumberProperty | BooleanProperty | IntegerProperty | DatetimeProperty | StringArrayProperty | NumberArrayProperty | BooleanArrayProperty | IntegerArrayProperty;
|
|
244
227
|
/**
|
|
245
228
|
* A property that stores a reference to a single node.
|
|
246
229
|
*/
|
|
247
230
|
export type NodeProperty = {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
231
|
+
type: 'node';
|
|
232
|
+
node_types: string[];
|
|
233
|
+
default_node_type?: string;
|
|
251
234
|
};
|
|
252
|
-
|
|
253
235
|
/**
|
|
254
236
|
* A property that stores an array of node references.
|
|
255
237
|
*/
|
|
256
238
|
export type NodeArrayProperty = {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
239
|
+
type: 'node_array';
|
|
240
|
+
node_types: string[];
|
|
241
|
+
mark_types?: string[];
|
|
242
|
+
annotation_types?: string[];
|
|
243
|
+
default_node_type?: string;
|
|
260
244
|
};
|
|
261
|
-
|
|
262
245
|
/**
|
|
263
246
|
* Union type for all possible property definitions.
|
|
264
247
|
*/
|
|
265
|
-
export type PropertyDefinition =
|
|
266
|
-
| PrimitiveProperty
|
|
267
|
-
| AnnotatedTextProperty
|
|
268
|
-
| NodeProperty
|
|
269
|
-
| NodeArrayProperty;
|
|
270
|
-
|
|
248
|
+
export type PropertyDefinition = PrimitiveProperty | TextProperty | NodeProperty | NodeArrayProperty;
|
|
271
249
|
/**
|
|
272
250
|
* Node kind values for different types of content nodes
|
|
273
251
|
*/
|
|
274
|
-
export type NodeKind = 'document' | 'block' | 'text' | 'annotation';
|
|
275
|
-
|
|
252
|
+
export type NodeKind = 'document' | 'block' | 'text' | 'mark' | 'annotation';
|
|
276
253
|
/**
|
|
277
|
-
* Schema for text nodes - must have a content property of type
|
|
278
|
-
* Use define_document_schema to also check that content is the only
|
|
254
|
+
* Schema for text nodes - must have a content property of type text.
|
|
255
|
+
* Use define_document_schema to also check that content is the only text property.
|
|
279
256
|
*/
|
|
280
257
|
export type TextNodeSchema = {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
: never;
|
|
258
|
+
kind: 'text';
|
|
259
|
+
properties: {
|
|
260
|
+
content: TextProperty;
|
|
261
|
+
} & Record<string, PropertyDefinition>;
|
|
262
|
+
};
|
|
263
|
+
export type TextPropertyNames<Properties> = {
|
|
264
|
+
[PropertyName in keyof Properties]: Properties[PropertyName] extends {
|
|
265
|
+
type: 'text';
|
|
266
|
+
} ? PropertyName : never;
|
|
291
267
|
}[keyof Properties];
|
|
292
|
-
|
|
293
268
|
export type TextNodeSchemaError<Message extends string> = {
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export type
|
|
298
|
-
'Text node schemas must define a "content" property of type annotated_text.'
|
|
299
|
-
>;
|
|
300
|
-
|
|
301
|
-
export type TextNodeExtraAnnotatedTextError<ExtraProperty extends string> = TextNodeSchemaError<
|
|
302
|
-
`Text node schemas must not define annotated_text property "${ExtraProperty}". Use "content" as the only annotated_text property.`
|
|
303
|
-
>;
|
|
304
|
-
|
|
269
|
+
[SchemaError in `Svedit schema error: ${Message}`]: never;
|
|
270
|
+
};
|
|
271
|
+
export type TextNodeMissingContentError = TextNodeSchemaError<'Text node schemas must define a "content" property of type text.'>;
|
|
272
|
+
export type TextNodeExtraTextPropertyError<ExtraProperty extends string> = TextNodeSchemaError<`Text node schemas must not define text property "${ExtraProperty}". Use "content" as the only text property.`>;
|
|
305
273
|
export type ValidateTextNodeSchema<Schema> = Schema extends {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
: Properties extends { content: AnnotatedTextProperty }
|
|
312
|
-
? Exclude<AnnotatedTextPropertyNames<Properties>, 'content'> extends infer ExtraProperties
|
|
313
|
-
? [ExtraProperties] extends [never]
|
|
314
|
-
? Schema
|
|
315
|
-
: TextNodeExtraAnnotatedTextError<Extract<ExtraProperties, string>>
|
|
316
|
-
: never
|
|
317
|
-
: TextNodeMissingContentError
|
|
318
|
-
: Schema;
|
|
319
|
-
|
|
274
|
+
kind: 'text';
|
|
275
|
+
properties: infer Properties;
|
|
276
|
+
} ? string extends keyof Properties ? Schema : Properties extends {
|
|
277
|
+
content: TextProperty;
|
|
278
|
+
} ? Exclude<TextPropertyNames<Properties>, 'content'> extends infer ExtraProperties ? [ExtraProperties] extends [never] ? Schema : TextNodeExtraTextPropertyError<Extract<ExtraProperties, string>> : never : TextNodeMissingContentError : Schema;
|
|
320
279
|
export type ValidateDocumentSchema<Schema extends Record<string, NodeSchema>> = {
|
|
321
|
-
|
|
280
|
+
[NodeType in keyof Schema]: ValidateTextNodeSchema<Schema[NodeType]>;
|
|
322
281
|
};
|
|
323
|
-
|
|
324
282
|
/**
|
|
325
283
|
* Schema for non-text nodes
|
|
326
284
|
*/
|
|
327
285
|
export type NonTextNodeSchema = {
|
|
328
|
-
|
|
329
|
-
|
|
286
|
+
kind: 'document' | 'block' | 'mark' | 'annotation';
|
|
287
|
+
properties: Record<string, PropertyDefinition>;
|
|
330
288
|
};
|
|
331
|
-
|
|
332
289
|
/**
|
|
333
290
|
* A node schema defines the structure of a specific node type.
|
|
334
291
|
* Contains a kind and properties object that maps property names to their definitions.
|
|
335
292
|
*/
|
|
336
293
|
export type NodeSchema = TextNodeSchema | NonTextNodeSchema;
|
|
337
|
-
|
|
338
294
|
/**
|
|
339
295
|
* A document schema defines all node types available in a document.
|
|
340
296
|
* Maps node type names to their schemas.
|
|
341
297
|
*/
|
|
342
298
|
export type DocumentSchema = Record<string, NodeSchema>;
|
|
343
|
-
|
|
344
299
|
/**
|
|
345
300
|
* A node in the document.
|
|
346
301
|
* Must have id and type properties, with other properties defined by the schema.
|
|
347
302
|
*/
|
|
348
303
|
export type DocumentNode = {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
304
|
+
id: string;
|
|
305
|
+
type: string;
|
|
306
|
+
[key: string]: any;
|
|
307
|
+
};
|
|
308
|
+
export type Inspection = {
|
|
309
|
+
kind: 'property' | 'node';
|
|
310
|
+
[key: string]: any;
|
|
352
311
|
};
|
|
353
|
-
|
|
354
312
|
/**
|
|
355
313
|
* The document format - an object with document_id and nodes.
|
|
356
314
|
* The nodes object maps node IDs to their node data.
|
|
357
315
|
*/
|
|
358
316
|
export type Document = {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
317
|
+
document_id: string;
|
|
318
|
+
nodes: {
|
|
319
|
+
[key: string]: DocumentNode;
|
|
320
|
+
};
|
|
363
321
|
};
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
322
|
+
/** Converts a document node to HTML, with access to recursive exporters. */
|
|
323
|
+
export type NodeHtmlExporter<S extends DocumentSchema = DocumentSchema> = (node: DocumentNode, session: Session<S>, html_exporters: Record<string, NodeHtmlExporter<S>>) => string;
|
|
324
|
+
/**
|
|
325
|
+
* Props for the TextProperty component
|
|
326
|
+
*/
|
|
327
|
+
export type TextPropertyProps = {
|
|
328
|
+
/** The full path to the property */
|
|
329
|
+
path: DocumentPath;
|
|
330
|
+
/** Optional custom HTML tag */
|
|
331
|
+
tag?: string;
|
|
332
|
+
/** The `class` attribute on the content element */
|
|
333
|
+
class?: string;
|
|
334
|
+
/** A placeholder to be rendered for empty content */
|
|
335
|
+
placeholder?: string;
|
|
336
|
+
/** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
|
|
337
|
+
[key: string]: unknown;
|
|
379
338
|
};
|
|
380
|
-
|
|
381
339
|
/**
|
|
382
340
|
* Props for the CustomProperty component
|
|
383
341
|
*/
|
|
384
342
|
export type CustomPropertyProps = {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
};
|
|
396
|
-
|
|
343
|
+
/** The full path to the property */
|
|
344
|
+
path: DocumentPath;
|
|
345
|
+
/** Optional custom HTML tag */
|
|
346
|
+
tag?: string;
|
|
347
|
+
/** The `class` attribute on the content element */
|
|
348
|
+
class?: string;
|
|
349
|
+
/** The content of the custom property (e.g. an image) */
|
|
350
|
+
children: Snippet;
|
|
351
|
+
/** Rest props to spread onto the rendered element */
|
|
352
|
+
[key: string]: unknown;
|
|
353
|
+
};
|
|
397
354
|
/**
|
|
398
355
|
* Props for the NodeArray component
|
|
399
356
|
*/
|
|
400
357
|
export type NodeArrayPropertyProps = {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
358
|
+
/** The full path to the property */
|
|
359
|
+
path: DocumentPath;
|
|
360
|
+
/** Optional custom HTML tag */
|
|
361
|
+
tag?: string;
|
|
362
|
+
/** The `class` attribute on the container element */
|
|
363
|
+
class?: string;
|
|
364
|
+
/** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
|
|
365
|
+
[key: string]: unknown;
|
|
409
366
|
};
|
|
410
|
-
|
|
411
367
|
/**
|
|
412
368
|
* Props for the Node component
|
|
413
369
|
*/
|
|
414
370
|
export type NodeProps = {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
371
|
+
/** The full path to the node */
|
|
372
|
+
path: DocumentPath;
|
|
373
|
+
/** The single node-array mark wrapping this node, if any */
|
|
374
|
+
mark?: NodeArrayAttachmentContext | null;
|
|
375
|
+
/** All node-array annotations covering this node */
|
|
376
|
+
annotations?: Array<NodeArrayAttachmentContext>;
|
|
377
|
+
/** Optional custom HTML tag */
|
|
378
|
+
tag?: string;
|
|
379
|
+
/** Optional string of CSS classes */
|
|
380
|
+
class?: string;
|
|
381
|
+
/** The type-specific content of the node */
|
|
382
|
+
children: Snippet;
|
|
383
|
+
/** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
|
|
384
|
+
[key: string]: unknown;
|
|
385
|
+
};
|
|
427
386
|
/**
|
|
428
387
|
* Props for the Svedit component
|
|
429
388
|
*/
|
|
430
|
-
export type SveditProps = {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
389
|
+
export type SveditProps<S extends DocumentSchema = DocumentSchema> = {
|
|
390
|
+
/** The schema-typed session instance */
|
|
391
|
+
session: Session<S>;
|
|
392
|
+
/** Determines wether the document should be editable or read-only. */
|
|
393
|
+
editable?: boolean;
|
|
394
|
+
/** The path to the root element (e.g. ['page_1']) */
|
|
395
|
+
path: DocumentPath;
|
|
396
|
+
/** The `class` attribute on the canvas element */
|
|
397
|
+
class?: string;
|
|
398
|
+
/** The `autocapitalize` attribute on the canvas element */
|
|
399
|
+
autocapitalize?: 'on' | 'off';
|
|
400
|
+
/** The `spellcheck` attribute on the canvas element */
|
|
401
|
+
spellcheck?: 'true' | 'false';
|
|
443
402
|
};
|
|
444
|
-
|
|
445
403
|
/**
|
|
446
|
-
*
|
|
404
|
+
* Context provided by the Svedit component to commands and descendant components.
|
|
447
405
|
*/
|
|
448
|
-
export type
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
406
|
+
export type SveditContext<S extends DocumentSchema = DocumentSchema> = {
|
|
407
|
+
session: Session<S>;
|
|
408
|
+
editable: boolean;
|
|
409
|
+
is_composing: boolean;
|
|
410
|
+
canvas_el: HTMLElement | undefined;
|
|
411
|
+
canvas_focused: boolean;
|
|
412
|
+
focus_canvas: () => void;
|
|
413
|
+
visibility_registry?: VisibilityRegistryApi;
|
|
414
|
+
};
|
|
415
|
+
/** Internal descendant context after Svedit's visibility registry is installed. */
|
|
416
|
+
export type SveditRenderContext<S extends DocumentSchema = DocumentSchema> = SveditContext<S> & {
|
|
417
|
+
visibility_registry: VisibilityRegistryApi;
|
|
452
418
|
};
|
|
453
|
-
|
|
454
419
|
/**
|
|
455
|
-
*
|
|
420
|
+
* A range with an attached payload node, used for both marks and annotations.
|
|
456
421
|
*/
|
|
457
|
-
export type
|
|
458
|
-
|
|
459
|
-
|
|
422
|
+
export type Attachment = {
|
|
423
|
+
start_offset: number;
|
|
424
|
+
end_offset: number;
|
|
425
|
+
node_id: NodeId;
|
|
460
426
|
};
|
|
461
|
-
|
|
462
427
|
/**
|
|
463
|
-
*
|
|
428
|
+
* A content-level range (e.g. strong, emphasis, link, section).
|
|
429
|
+
* Marks are mutually exclusive within a property and render in-place.
|
|
430
|
+
*/
|
|
431
|
+
export type Mark = Attachment;
|
|
432
|
+
/**
|
|
433
|
+
* A metadata/overlay range (e.g. comment, marker).
|
|
434
|
+
* Annotations may overlap and are data-only.
|
|
435
|
+
*/
|
|
436
|
+
export type Annotation = Attachment;
|
|
437
|
+
/**
|
|
438
|
+
* Represents text content with marks and annotations.
|
|
439
|
+
*/
|
|
440
|
+
export type Text = {
|
|
441
|
+
content: string;
|
|
442
|
+
marks: Array<Mark>;
|
|
443
|
+
annotations: Array<Annotation>;
|
|
444
|
+
};
|
|
445
|
+
/**
|
|
446
|
+
* Represents a node array with nodes, marks and annotations.
|
|
447
|
+
*/
|
|
448
|
+
export type NodeArray = {
|
|
449
|
+
nodes: Array<NodeId>;
|
|
450
|
+
marks: Array<Mark>;
|
|
451
|
+
annotations: Array<Annotation>;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* Attachment context passed to a node rendered inside a node array.
|
|
455
|
+
* It is the flattened mark or annotation attachment, enriched with the resolved
|
|
456
|
+
* payload node, its index in the parent attachment array, and this child node's
|
|
457
|
+
* position in the attachment range.
|
|
458
|
+
*/
|
|
459
|
+
export type NodeArrayAttachmentContext = {
|
|
460
|
+
start_offset: number;
|
|
461
|
+
end_offset: number;
|
|
462
|
+
node_id: NodeId;
|
|
463
|
+
index: number;
|
|
464
|
+
node: DocumentNode;
|
|
465
|
+
is_start: boolean;
|
|
466
|
+
is_middle: boolean;
|
|
467
|
+
is_end: boolean;
|
|
468
|
+
};
|
|
469
|
+
/** Internal context shared by a node array and its rendered child nodes. */
|
|
470
|
+
export type NodeArrayRenderContext = {
|
|
471
|
+
length: number;
|
|
472
|
+
mark_for: (node_index: number) => NodeArrayAttachmentContext | null;
|
|
473
|
+
annotations_for: (node_index: number) => NodeArrayAttachmentContext[];
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Represents a selection highlight fragment for unmarked text selections
|
|
464
477
|
*/
|
|
465
478
|
export type SelectionHighlightFragment = {
|
|
466
|
-
|
|
467
|
-
|
|
479
|
+
type: 'selection_highlight';
|
|
480
|
+
content: string;
|
|
481
|
+
};
|
|
482
|
+
/**
|
|
483
|
+
* Represents a mark fragment in text content
|
|
484
|
+
*/
|
|
485
|
+
export type MarkFragment = {
|
|
486
|
+
type: 'mark';
|
|
487
|
+
/** NodeId that has mark type and details */
|
|
488
|
+
node: DocumentNode;
|
|
489
|
+
/** The text content of the mark */
|
|
490
|
+
content: string;
|
|
491
|
+
/** Index of the mark in the original array */
|
|
492
|
+
mark_index: number;
|
|
468
493
|
};
|
|
469
|
-
|
|
470
494
|
/**
|
|
471
|
-
* Represents
|
|
495
|
+
* Represents a fragment of text content
|
|
496
|
+
*/
|
|
497
|
+
export type Fragment = string | MarkFragment | SelectionHighlightFragment;
|
|
498
|
+
/**
|
|
499
|
+
* Represents a node array fragment for plain nodes
|
|
472
500
|
*/
|
|
473
|
-
export type
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
501
|
+
export type NodeArrayPlainFragment = {
|
|
502
|
+
type: 'nodes';
|
|
503
|
+
nodes: Array<NodeId>;
|
|
504
|
+
start_index: number;
|
|
505
|
+
};
|
|
506
|
+
/**
|
|
507
|
+
* Represents a mark fragment in node array content
|
|
508
|
+
*/
|
|
509
|
+
export type NodeArrayMarkFragment = {
|
|
510
|
+
type: 'mark';
|
|
511
|
+
/** NodeId that has mark type and details */
|
|
512
|
+
node: DocumentNode;
|
|
513
|
+
/** The nodes wrapped by the mark */
|
|
514
|
+
nodes: Array<NodeId>;
|
|
515
|
+
/** Start index in the original nodes array */
|
|
516
|
+
start_index: number;
|
|
517
|
+
/** Index of the mark in the original array */
|
|
518
|
+
mark_index: number;
|
|
481
519
|
};
|
|
482
|
-
|
|
483
520
|
/**
|
|
484
|
-
* Represents a fragment of
|
|
521
|
+
* Represents a fragment of node array content
|
|
485
522
|
*/
|
|
486
|
-
export type
|
|
523
|
+
export type NodeArrayFragment = NodeArrayPlainFragment | NodeArrayMarkFragment;
|
|
524
|
+
//# sourceMappingURL=types.d.ts.map
|