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.
Files changed (93) hide show
  1. package/README.md +260 -82
  2. package/dist/Command.svelte.d.ts +54 -29
  3. package/dist/Command.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.js +286 -283
  5. package/dist/CustomProperty.svelte +3 -5
  6. package/dist/CustomProperty.svelte.d.ts +3 -6
  7. package/dist/CustomProperty.svelte.d.ts.map +1 -1
  8. package/dist/KeyMapper.svelte.d.ts +19 -6
  9. package/dist/KeyMapper.svelte.d.ts.map +1 -1
  10. package/dist/KeyMapper.svelte.js +95 -112
  11. package/dist/Node.svelte +40 -9
  12. package/dist/Node.svelte.d.ts +3 -5
  13. package/dist/Node.svelte.d.ts.map +1 -1
  14. package/dist/NodeArrayProperty.svelte +142 -18
  15. package/dist/NodeArrayProperty.svelte.d.ts +3 -5
  16. package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
  17. package/dist/NodeCaret.svelte +1 -1
  18. package/dist/NodeCaret.svelte.d.ts +6 -14
  19. package/dist/NodeCaret.svelte.d.ts.map +1 -1
  20. package/dist/NodeGap.svelte +60 -12
  21. package/dist/NodeGap.svelte.d.ts +7 -14
  22. package/dist/NodeGap.svelte.d.ts.map +1 -1
  23. package/dist/NodeGapMarkers.svelte +19 -10
  24. package/dist/NodeGapMarkers.svelte.d.ts +6 -11
  25. package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
  26. package/dist/NodeSelectionMarkers.svelte +20 -6
  27. package/dist/NodeSelectionMarkers.svelte.d.ts +2 -5
  28. package/dist/NodeSelectionMarkers.svelte.d.ts.map +1 -1
  29. package/dist/Session.svelte.d.ts +85 -116
  30. package/dist/Session.svelte.d.ts.map +1 -1
  31. package/dist/Session.svelte.js +543 -571
  32. package/dist/Svedit.svelte +243 -216
  33. package/dist/Svedit.svelte.d.ts +30 -10
  34. package/dist/Svedit.svelte.d.ts.map +1 -1
  35. package/dist/{AnnotatedTextProperty.svelte → TextProperty.svelte} +71 -56
  36. package/dist/TextProperty.svelte.d.ts +5 -0
  37. package/dist/TextProperty.svelte.d.ts.map +1 -0
  38. package/dist/Transaction.svelte.d.ts +101 -126
  39. package/dist/Transaction.svelte.d.ts.map +1 -1
  40. package/dist/Transaction.svelte.js +843 -827
  41. package/dist/UnknownNode.svelte +4 -3
  42. package/dist/UnknownNode.svelte.d.ts +5 -9
  43. package/dist/UnknownNode.svelte.d.ts.map +1 -1
  44. package/dist/doc_utils.d.ts +109 -122
  45. package/dist/doc_utils.d.ts.map +1 -1
  46. package/dist/doc_utils.js +726 -698
  47. package/dist/index.d.ts +20 -17
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +2 -18
  50. package/dist/node_visibility.svelte.d.ts +132 -5
  51. package/dist/node_visibility.svelte.d.ts.map +1 -1
  52. package/dist/node_visibility.svelte.js +535 -642
  53. package/dist/paste_utils.d.ts +11 -43
  54. package/dist/paste_utils.d.ts.map +1 -1
  55. package/dist/paste_utils.js +111 -149
  56. package/dist/transforms.svelte.d.ts +9 -7
  57. package/dist/transforms.svelte.d.ts.map +1 -1
  58. package/dist/transforms.svelte.js +126 -152
  59. package/dist/types.d.ts +329 -291
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +1 -0
  62. package/dist/utils.d.ts +79 -95
  63. package/dist/utils.d.ts.map +1 -1
  64. package/dist/utils.js +392 -305
  65. package/package.json +69 -67
  66. package/src/lib/{Command.svelte.js → Command.svelte.ts} +111 -41
  67. package/src/lib/CustomProperty.svelte +3 -5
  68. package/src/lib/{KeyMapper.svelte.js → KeyMapper.svelte.ts} +28 -11
  69. package/src/lib/Node.svelte +40 -9
  70. package/src/lib/NodeArrayProperty.svelte +142 -18
  71. package/src/lib/NodeCaret.svelte +1 -1
  72. package/src/lib/NodeGap.svelte +60 -12
  73. package/src/lib/NodeGapMarkers.svelte +19 -10
  74. package/src/lib/NodeSelectionMarkers.svelte +20 -6
  75. package/src/lib/Session.svelte.ts +656 -0
  76. package/src/lib/Svedit.svelte +243 -216
  77. package/src/lib/{AnnotatedTextProperty.svelte → TextProperty.svelte} +71 -56
  78. package/src/lib/Transaction.svelte.ts +1020 -0
  79. package/src/lib/UnknownNode.svelte +4 -3
  80. package/src/lib/doc_utils.ts +1120 -0
  81. package/src/lib/{index.js → index.ts} +48 -1
  82. package/src/lib/node_visibility.svelte.ts +658 -0
  83. package/src/lib/{paste_utils.js → paste_utils.ts} +51 -59
  84. package/src/lib/{transforms.svelte.js → transforms.svelte.ts} +44 -27
  85. package/src/lib/{types.d.ts → types.ts} +250 -103
  86. package/src/lib/utils.ts +660 -0
  87. package/dist/AnnotatedTextProperty.svelte.d.ts +0 -7
  88. package/dist/AnnotatedTextProperty.svelte.d.ts.map +0 -1
  89. package/src/lib/Session.svelte.js +0 -575
  90. package/src/lib/Transaction.svelte.js +0 -846
  91. package/src/lib/doc_utils.js +0 -807
  92. package/src/lib/node_visibility.svelte.js +0 -718
  93. 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 Svedit from './Svedit.svelte';
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 { Component, Snippet } from 'svelte';
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
- type: 'text';
33
- path: DocumentPath;
34
- anchor_offset: number;
35
- focus_offset: number;
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
- type: 'node';
43
- path: DocumentPath;
44
- anchor_offset: number;
45
- focus_offset: number;
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
- type: 'property';
53
- path: DocumentPath;
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
- start_offset: number;
66
- end_offset: number;
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 = 'annotated_text';
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
- // TODO: We may later want more sophisticated type inference, so that typing
102
- // e.g. `session.get('image')` auto-completes the node's properties based on
103
- // the schema definition. The types below are a starting point for that.
104
- //
105
- // export type DocumentSchemaPrimitive =
106
- // | 'string'
107
- // | 'number'
108
- // | 'boolean'
109
- // | 'integer'
110
- // | 'datetime'
111
- // | 'string_array'
112
- // | 'number_array'
113
- // | 'boolean_array'
114
- // | 'integer_array'
115
- // | 'annotated_text'
116
- // | 'node'
117
- // | 'node_array';
118
- //
119
- // export type DocumentSchemaValueToJs<T> = T extends 'string'
120
- // ? string
121
- // : T extends 'number'
122
- // ? number
123
- // : T extends 'boolean'
124
- // ? boolean
125
- // : T extends 'integer'
126
- // ? number
127
- // : T extends 'datetime'
128
- // ? string
129
- // : T extends 'string_array'
130
- // ? Array<string>
131
- // : T extends 'number_array'
132
- // ? Array<number>
133
- // : T extends 'boolean_array'
134
- // ? Array<boolean>
135
- // : T extends 'integer_array'
136
- // ? Array<number>
137
- // : T extends 'annotated_text'
138
- // ? AnnotatedText
139
- // : T extends 'node'
140
- // ? string
141
- // : T extends 'node_array'
142
- // ? Array<string>
143
- // : never;
144
- //
145
- // export type DocumentNodeToJs<S extends NodeSchema> = { id: string; type: string } & {
146
- // [K in keyof S['properties']]: DocumentSchemaValueToJs<S['properties'][K]['type']>;
147
- // };
148
-
149
- /**
150
- * A property that stores an annotated text with required allow_newlines setting.
151
- */
152
- export type AnnotatedTextProperty = {
153
- type: 'annotated_text';
154
- node_types?: string[];
155
- allow_newlines: boolean;
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
- type: 'string';
163
- default?: string;
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
- type: 'number';
171
- default?: number;
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
- type: 'boolean';
179
- default?: boolean;
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
- type: 'integer';
187
- default?: number;
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
- type: 'datetime';
195
- default?: string;
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
- type: 'string_array';
203
- default?: string[];
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
- type: 'number_array';
211
- default?: number[];
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
- type: 'boolean_array';
219
- default?: boolean[];
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
- type: 'integer_array';
227
- default?: number[];
220
+ type: 'integer_array';
221
+ default?: number[];
228
222
  };
229
-
230
223
  /**
231
- * A property that stores a primitive value (excluding annotated_text).
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
- type: 'node';
249
- node_types: string[];
250
- default_node_type?: string;
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
- type: 'node_array';
258
- node_types: string[];
259
- default_node_type?: string;
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 annotated_text.
278
- * Use define_document_schema to also check that content is the only annotated_text property.
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
- kind: 'text';
282
- properties: {
283
- content: AnnotatedTextProperty;
284
- } & Record<string, PropertyDefinition>;
285
- };
286
-
287
- export type AnnotatedTextPropertyNames<Properties> = {
288
- [PropertyName in keyof Properties]: Properties[PropertyName] extends { type: 'annotated_text' }
289
- ? PropertyName
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
- [SchemaError in `Svedit schema error: ${Message}`]: never;
295
- };
296
-
297
- export type TextNodeMissingContentError = TextNodeSchemaError<
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
- kind: 'text';
307
- properties: infer Properties;
308
- }
309
- ? string extends keyof Properties
310
- ? Schema
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
- [NodeType in keyof Schema]: ValidateTextNodeSchema<Schema[NodeType]>;
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
- kind: 'document' | 'block' | 'annotation';
329
- properties: Record<string, PropertyDefinition>;
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
- id: string;
350
- type: string;
351
- [key: string]: any;
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
- document_id: string;
360
- nodes: {
361
- [key: string]: DocumentNode;
362
- };
317
+ document_id: string;
318
+ nodes: {
319
+ [key: string]: DocumentNode;
320
+ };
363
321
  };
364
-
365
- /**
366
- * Props for the AnnotatedTextProperty component
367
- */
368
- export type AnnotatedTextPropertyProps = {
369
- /** The full path to the property */
370
- path: DocumentPath;
371
- /** Optional custom HTML tag */
372
- tag?: string;
373
- /** The `class` attribute on the content element */
374
- class?: string;
375
- /** A placeholder to be rendered for empty content */
376
- placeholder?: string;
377
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
378
- [key: string]: any;
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
- /** The full path to the property */
386
- path: DocumentPath;
387
- /** Optional custom HTML tag */
388
- tag?: string;
389
- /** The `class` attribute on the content element */
390
- class?: string;
391
- /** The content of the custom property (e.g. an image) */
392
- children: Snippet;
393
- /** Rest props to spread onto the rendered element */
394
- [key: string]: any;
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
- /** The full path to the property */
402
- path: DocumentPath;
403
- /** Optional custom HTML tag */
404
- tag?: string;
405
- /** The `class` attribute on the container element */
406
- class?: string;
407
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
408
- [key: string]: any;
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
- /** The full path to the node */
416
- path: DocumentPath;
417
- /** Optional custom HTML tag */
418
- tag?: string;
419
- /** Optional string of CSS classes */
420
- class?: string;
421
- /** The type-specific content of the node */
422
- children: Snippet;
423
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
424
- [key: string]: any;
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
- /** The session instance */
432
- session: Session;
433
- /** Determines wether the document should be editable or read-only. */
434
- editable?: boolean;
435
- /** The path to the root element (e.g. ['page_1']) */
436
- path: DocumentPath;
437
- /** The `class` attribute on the canvas element */
438
- class?: string;
439
- /** The `autocapitalize` attribute on the canvas element */
440
- autocapitalize?: 'on' | 'off';
441
- /** The `spellcheck` attribute on the canvas element */
442
- spellcheck?: 'true' | 'false';
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
- * Represents an annotation in an annotated string
404
+ * Context provided by the Svedit component to commands and descendant components.
447
405
  */
448
- export type Annotation = {
449
- start_offset: number;
450
- end_offset: number;
451
- node_id: NodeId;
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
- * Represents an annotated text with text and annotations
420
+ * A range with an attached payload node, used for both marks and annotations.
456
421
  */
457
- export type AnnotatedText = {
458
- text: string;
459
- annotations: Array<Annotation>;
422
+ export type Attachment = {
423
+ start_offset: number;
424
+ end_offset: number;
425
+ node_id: NodeId;
460
426
  };
461
-
462
427
  /**
463
- * Represents a selection highlight fragment for non-annotated text selections
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
- type: 'selection_highlight';
467
- content: string;
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 an annotation fragment in annotated text content
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 AnnotationFragment = {
474
- type: 'annotation';
475
- /** NodeId that has annotation type and details */
476
- node: any;
477
- /** The text content of the annotation */
478
- content: string;
479
- /** Index of the annotation in the original array */
480
- annotation_index: number;
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 annotated text content
521
+ * Represents a fragment of node array content
485
522
  */
486
- export type Fragment = string | AnnotationFragment | SelectionHighlightFragment;
523
+ export type NodeArrayFragment = NodeArrayPlainFragment | NodeArrayMarkFragment;
524
+ //# sourceMappingURL=types.d.ts.map