svedit 0.12.0 → 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 (86) hide show
  1. package/README.md +33 -21
  2. package/dist/Command.svelte.d.ts +38 -30
  3. package/dist/Command.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.js +271 -326
  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 +16 -13
  12. package/dist/Node.svelte.d.ts +3 -5
  13. package/dist/Node.svelte.d.ts.map +1 -1
  14. package/dist/NodeArrayProperty.svelte +39 -22
  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 +12 -6
  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 +81 -129
  30. package/dist/Session.svelte.d.ts.map +1 -1
  31. package/dist/Session.svelte.js +542 -648
  32. package/dist/Svedit.svelte +144 -138
  33. package/dist/Svedit.svelte.d.ts +30 -10
  34. package/dist/Svedit.svelte.d.ts.map +1 -1
  35. package/dist/TextProperty.svelte +32 -18
  36. package/dist/TextProperty.svelte.d.ts +3 -5
  37. package/dist/TextProperty.svelte.d.ts.map +1 -1
  38. package/dist/Transaction.svelte.d.ts +64 -127
  39. package/dist/Transaction.svelte.d.ts.map +1 -1
  40. package/dist/Transaction.svelte.js +839 -1001
  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 +67 -155
  45. package/dist/doc_utils.d.ts.map +1 -1
  46. package/dist/doc_utils.js +619 -863
  47. package/dist/index.d.ts +20 -17
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +1 -17
  50. package/dist/node_visibility.svelte.d.ts +110 -9
  51. package/dist/node_visibility.svelte.d.ts.map +1 -1
  52. package/dist/node_visibility.svelte.js +473 -544
  53. package/dist/paste_utils.d.ts +11 -44
  54. package/dist/paste_utils.d.ts.map +1 -1
  55. package/dist/paste_utils.js +111 -152
  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 +125 -150
  59. package/dist/types.d.ts +277 -309
  60. package/dist/types.d.ts.map +1 -0
  61. package/dist/types.js +1 -0
  62. package/dist/utils.d.ts +40 -119
  63. package/dist/utils.d.ts.map +1 -1
  64. package/dist/utils.js +346 -473
  65. package/package.json +69 -70
  66. package/src/lib/{Command.svelte.js → Command.svelte.ts} +29 -17
  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 +16 -13
  70. package/src/lib/NodeArrayProperty.svelte +39 -22
  71. package/src/lib/NodeCaret.svelte +1 -1
  72. package/src/lib/NodeGap.svelte +12 -6
  73. package/src/lib/NodeGapMarkers.svelte +19 -10
  74. package/src/lib/NodeSelectionMarkers.svelte +20 -6
  75. package/src/lib/{Session.svelte.js → Session.svelte.ts} +130 -127
  76. package/src/lib/Svedit.svelte +144 -138
  77. package/src/lib/TextProperty.svelte +32 -18
  78. package/src/lib/{Transaction.svelte.js → Transaction.svelte.ts} +139 -143
  79. package/src/lib/UnknownNode.svelte +4 -3
  80. package/src/lib/{doc_utils.js → doc_utils.ts} +247 -206
  81. package/src/lib/{index.js → index.ts} +47 -0
  82. package/src/lib/{node_visibility.svelte.js → node_visibility.svelte.ts} +68 -92
  83. package/src/lib/{paste_utils.js → paste_utils.ts} +47 -58
  84. package/src/lib/{transforms.svelte.js → transforms.svelte.ts} +39 -21
  85. package/src/lib/{types.d.ts → types.ts} +143 -66
  86. package/src/lib/{utils.js → utils.ts} +110 -129
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,539 +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
71
  export type RichType = 'text';
85
-
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
- // | '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 '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
-
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
+ */
149
148
  /**
150
149
  * A property that stores text with optional marks and annotations and required allow_newlines setting.
151
150
  */
152
151
  export type TextProperty = {
153
- type: 'text';
154
- mark_types?: string[];
155
- annotation_types?: string[];
156
- allow_newlines: boolean;
152
+ type: 'text';
153
+ mark_types?: string[];
154
+ annotation_types?: string[];
155
+ allow_newlines: boolean;
157
156
  };
158
-
159
157
  /**
160
158
  * A property that stores a string value.
161
159
  */
162
160
  export type StringProperty = {
163
- type: 'string';
164
- default?: string;
161
+ type: 'string';
162
+ default?: string;
163
+ values?: readonly string[];
165
164
  };
166
-
167
165
  /**
168
166
  * A property that stores a number value.
169
167
  */
170
168
  export type NumberProperty = {
171
- type: 'number';
172
- default?: number;
169
+ type: 'number';
170
+ default?: number;
173
171
  };
174
-
175
172
  /**
176
173
  * A property that stores a boolean value.
177
174
  */
178
175
  export type BooleanProperty = {
179
- type: 'boolean';
180
- default?: boolean;
176
+ type: 'boolean';
177
+ default?: boolean;
181
178
  };
182
-
183
179
  /**
184
180
  * A property that stores an integer value.
185
181
  */
186
182
  export type IntegerProperty = {
187
- type: 'integer';
188
- default?: number;
183
+ type: 'integer';
184
+ default?: number;
185
+ min?: number;
186
+ max?: number;
189
187
  };
190
-
191
188
  /**
192
189
  * A property that stores a datetime value.
193
190
  */
194
191
  export type DatetimeProperty = {
195
- type: 'datetime';
196
- default?: string;
192
+ type: 'datetime';
193
+ default?: string;
197
194
  };
198
-
199
195
  /**
200
196
  * A property that stores an array of strings.
201
197
  */
202
198
  export type StringArrayProperty = {
203
- type: 'string_array';
204
- default?: string[];
199
+ type: 'string_array';
200
+ default?: string[];
205
201
  };
206
-
207
202
  /**
208
203
  * A property that stores an array of numbers.
209
204
  */
210
205
  export type NumberArrayProperty = {
211
- type: 'number_array';
212
- default?: number[];
206
+ type: 'number_array';
207
+ default?: number[];
213
208
  };
214
-
215
209
  /**
216
210
  * A property that stores an array of booleans.
217
211
  */
218
212
  export type BooleanArrayProperty = {
219
- type: 'boolean_array';
220
- default?: boolean[];
213
+ type: 'boolean_array';
214
+ default?: boolean[];
221
215
  };
222
-
223
216
  /**
224
217
  * A property that stores an array of integers.
225
218
  */
226
219
  export type IntegerArrayProperty = {
227
- type: 'integer_array';
228
- default?: number[];
220
+ type: 'integer_array';
221
+ default?: number[];
229
222
  };
230
-
231
223
  /**
232
224
  * A property that stores a primitive value (excluding text).
233
225
  */
234
- export type PrimitiveProperty =
235
- | StringProperty
236
- | NumberProperty
237
- | BooleanProperty
238
- | IntegerProperty
239
- | DatetimeProperty
240
- | StringArrayProperty
241
- | NumberArrayProperty
242
- | BooleanArrayProperty
243
- | IntegerArrayProperty;
244
-
226
+ export type PrimitiveProperty = StringProperty | NumberProperty | BooleanProperty | IntegerProperty | DatetimeProperty | StringArrayProperty | NumberArrayProperty | BooleanArrayProperty | IntegerArrayProperty;
245
227
  /**
246
228
  * A property that stores a reference to a single node.
247
229
  */
248
230
  export type NodeProperty = {
249
- type: 'node';
250
- node_types: string[];
251
- default_node_type?: string;
231
+ type: 'node';
232
+ node_types: string[];
233
+ default_node_type?: string;
252
234
  };
253
-
254
235
  /**
255
236
  * A property that stores an array of node references.
256
237
  */
257
238
  export type NodeArrayProperty = {
258
- type: 'node_array';
259
- node_types: string[];
260
- mark_types?: string[];
261
- annotation_types?: string[];
262
- 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;
263
244
  };
264
-
265
245
  /**
266
246
  * Union type for all possible property definitions.
267
247
  */
268
- export type PropertyDefinition =
269
- PrimitiveProperty | TextProperty | NodeProperty | 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
252
  export type NodeKind = 'document' | 'block' | 'text' | 'mark' | 'annotation';
275
-
276
253
  /**
277
254
  * Schema for text nodes - must have a content property of type text.
278
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: TextProperty;
284
- } & Record<string, PropertyDefinition>;
258
+ kind: 'text';
259
+ properties: {
260
+ content: TextProperty;
261
+ } & Record<string, PropertyDefinition>;
285
262
  };
286
-
287
263
  export type TextPropertyNames<Properties> = {
288
- [PropertyName in keyof Properties]: Properties[PropertyName] extends { type: 'text' }
289
- ? PropertyName
290
- : never;
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 =
298
- TextNodeSchemaError<'Text node schemas must define a "content" property of type text.'>;
299
-
300
- export type TextNodeExtraTextPropertyError<ExtraProperty extends string> =
301
- TextNodeSchemaError<`Text node schemas must not define text property "${ExtraProperty}". Use "content" as the only text property.`>;
302
-
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.`>;
303
273
  export type ValidateTextNodeSchema<Schema> = Schema extends {
304
- kind: 'text';
305
- properties: infer Properties;
306
- }
307
- ? string extends keyof Properties
308
- ? Schema
309
- : Properties extends { content: TextProperty }
310
- ? Exclude<TextPropertyNames<Properties>, 'content'> extends infer ExtraProperties
311
- ? [ExtraProperties] extends [never]
312
- ? Schema
313
- : TextNodeExtraTextPropertyError<Extract<ExtraProperties, string>>
314
- : never
315
- : TextNodeMissingContentError
316
- : Schema;
317
-
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;
318
279
  export type ValidateDocumentSchema<Schema extends Record<string, NodeSchema>> = {
319
- [NodeType in keyof Schema]: ValidateTextNodeSchema<Schema[NodeType]>;
280
+ [NodeType in keyof Schema]: ValidateTextNodeSchema<Schema[NodeType]>;
320
281
  };
321
-
322
282
  /**
323
283
  * Schema for non-text nodes
324
284
  */
325
285
  export type NonTextNodeSchema = {
326
- kind: 'document' | 'block' | 'mark' | 'annotation';
327
- properties: Record<string, PropertyDefinition>;
286
+ kind: 'document' | 'block' | 'mark' | 'annotation';
287
+ properties: Record<string, PropertyDefinition>;
328
288
  };
329
-
330
289
  /**
331
290
  * A node schema defines the structure of a specific node type.
332
291
  * Contains a kind and properties object that maps property names to their definitions.
333
292
  */
334
293
  export type NodeSchema = TextNodeSchema | NonTextNodeSchema;
335
-
336
294
  /**
337
295
  * A document schema defines all node types available in a document.
338
296
  * Maps node type names to their schemas.
339
297
  */
340
298
  export type DocumentSchema = Record<string, NodeSchema>;
341
-
342
299
  /**
343
300
  * A node in the document.
344
301
  * Must have id and type properties, with other properties defined by the schema.
345
302
  */
346
303
  export type DocumentNode = {
347
- id: string;
348
- type: string;
349
- [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;
350
311
  };
351
-
352
312
  /**
353
313
  * The document format - an object with document_id and nodes.
354
314
  * The nodes object maps node IDs to their node data.
355
315
  */
356
316
  export type Document = {
357
- document_id: string;
358
- nodes: {
359
- [key: string]: DocumentNode;
360
- };
317
+ document_id: string;
318
+ nodes: {
319
+ [key: string]: DocumentNode;
320
+ };
361
321
  };
362
-
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;
363
324
  /**
364
325
  * Props for the TextProperty component
365
326
  */
366
327
  export type TextPropertyProps = {
367
- /** The full path to the property */
368
- path: DocumentPath;
369
- /** Optional custom HTML tag */
370
- tag?: string;
371
- /** The `class` attribute on the content element */
372
- class?: string;
373
- /** A placeholder to be rendered for empty content */
374
- placeholder?: string;
375
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
376
- [key: string]: any;
377
- };
378
-
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;
338
+ };
379
339
  /**
380
340
  * Props for the CustomProperty component
381
341
  */
382
342
  export type CustomPropertyProps = {
383
- /** The full path to the property */
384
- path: DocumentPath;
385
- /** Optional custom HTML tag */
386
- tag?: string;
387
- /** The `class` attribute on the content element */
388
- class?: string;
389
- /** The content of the custom property (e.g. an image) */
390
- children: Snippet;
391
- /** Rest props to spread onto the rendered element */
392
- [key: string]: any;
393
- };
394
-
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
+ };
395
354
  /**
396
355
  * Props for the NodeArray component
397
356
  */
398
357
  export type NodeArrayPropertyProps = {
399
- /** The full path to the property */
400
- path: DocumentPath;
401
- /** Optional custom HTML tag */
402
- tag?: string;
403
- /** The `class` attribute on the container element */
404
- class?: string;
405
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
406
- [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;
407
366
  };
408
-
409
367
  /**
410
368
  * Props for the Node component
411
369
  */
412
370
  export type NodeProps = {
413
- /** The full path to the node */
414
- path: DocumentPath;
415
- /** The single node-array mark wrapping this node, if any */
416
- mark?: NodeArrayAttachmentContext | null;
417
- /** All node-array annotations covering this node */
418
- annotations?: Array<NodeArrayAttachmentContext>;
419
- /** Optional custom HTML tag */
420
- tag?: string;
421
- /** Optional string of CSS classes */
422
- class?: string;
423
- /** The type-specific content of the node */
424
- children: Snippet;
425
- /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
426
- [key: string]: any;
427
- };
428
-
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
+ };
429
386
  /**
430
387
  * Props for the Svedit component
431
388
  */
432
- export type SveditProps = {
433
- /** The session instance */
434
- session: Session;
435
- /** Determines wether the document should be editable or read-only. */
436
- editable?: boolean;
437
- /** The path to the root element (e.g. ['page_1']) */
438
- path: DocumentPath;
439
- /** The `class` attribute on the canvas element */
440
- class?: string;
441
- /** The `autocapitalize` attribute on the canvas element */
442
- autocapitalize?: 'on' | 'off';
443
- /** The `spellcheck` attribute on the canvas element */
444
- spellcheck?: 'true' | 'false';
445
- };
446
-
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';
402
+ };
403
+ /**
404
+ * Context provided by the Svedit component to commands and descendant components.
405
+ */
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;
418
+ };
447
419
  /**
448
420
  * A range with an attached payload node, used for both marks and annotations.
449
421
  */
450
422
  export type Attachment = {
451
- start_offset: number;
452
- end_offset: number;
453
- node_id: NodeId;
423
+ start_offset: number;
424
+ end_offset: number;
425
+ node_id: NodeId;
454
426
  };
455
-
456
427
  /**
457
428
  * A content-level range (e.g. strong, emphasis, link, section).
458
429
  * Marks are mutually exclusive within a property and render in-place.
459
430
  */
460
431
  export type Mark = Attachment;
461
-
462
432
  /**
463
433
  * A metadata/overlay range (e.g. comment, marker).
464
434
  * Annotations may overlap and are data-only.
465
435
  */
466
436
  export type Annotation = Attachment;
467
-
468
437
  /**
469
438
  * Represents text content with marks and annotations.
470
439
  */
471
- export type AnnotatedText = {
472
- content: string;
473
- marks: Array<Mark>;
474
- annotations: Array<Annotation>;
440
+ export type Text = {
441
+ content: string;
442
+ marks: Array<Mark>;
443
+ annotations: Array<Annotation>;
475
444
  };
476
-
477
445
  /**
478
- * Represents an annotated node array with nodes, marks and annotations
446
+ * Represents a node array with nodes, marks and annotations.
479
447
  */
480
- export type AnnotatedNodeArray = {
481
- nodes: Array<NodeId>;
482
- marks: Array<Mark>;
483
- annotations: Array<Annotation>;
448
+ export type NodeArray = {
449
+ nodes: Array<NodeId>;
450
+ marks: Array<Mark>;
451
+ annotations: Array<Annotation>;
484
452
  };
485
-
486
453
  /**
487
- * Attachment context passed to a node rendered inside an annotated node array.
454
+ * Attachment context passed to a node rendered inside a node array.
488
455
  * It is the flattened mark or annotation attachment, enriched with the resolved
489
456
  * payload node, its index in the parent attachment array, and this child node's
490
457
  * position in the attachment range.
491
458
  */
492
459
  export type NodeArrayAttachmentContext = {
493
- start_offset: number;
494
- end_offset: number;
495
- node_id: NodeId;
496
- index: number;
497
- node: DocumentNode;
498
- is_start: boolean;
499
- is_middle: boolean;
500
- is_end: boolean;
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[];
501
474
  };
502
-
503
475
  /**
504
- * Represents a selection highlight fragment for non-annotated text selections
476
+ * Represents a selection highlight fragment for unmarked text selections
505
477
  */
506
478
  export type SelectionHighlightFragment = {
507
- type: 'selection_highlight';
508
- content: string;
479
+ type: 'selection_highlight';
480
+ content: string;
509
481
  };
510
-
511
482
  /**
512
- * Represents a mark fragment in annotated text content
483
+ * Represents a mark fragment in text content
513
484
  */
514
485
  export type MarkFragment = {
515
- type: 'mark';
516
- /** NodeId that has mark type and details */
517
- node: any;
518
- /** The text content of the mark */
519
- content: string;
520
- /** Index of the mark in the original array */
521
- mark_index: number;
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;
522
493
  };
523
-
524
494
  /**
525
- * Represents a fragment of annotated text content
495
+ * Represents a fragment of text content
526
496
  */
527
497
  export type Fragment = string | MarkFragment | SelectionHighlightFragment;
528
-
529
498
  /**
530
499
  * Represents a node array fragment for plain nodes
531
500
  */
532
501
  export type NodeArrayPlainFragment = {
533
- type: 'nodes';
534
- nodes: Array<NodeId>;
535
- start_index: number;
502
+ type: 'nodes';
503
+ nodes: Array<NodeId>;
504
+ start_index: number;
536
505
  };
537
-
538
506
  /**
539
507
  * Represents a mark fragment in node array content
540
508
  */
541
509
  export type NodeArrayMarkFragment = {
542
- type: 'mark';
543
- /** NodeId that has mark type and details */
544
- node: any;
545
- /** The nodes wrapped by the mark */
546
- nodes: Array<NodeId>;
547
- /** Start index in the original nodes array */
548
- start_index: number;
549
- /** Index of the mark in the original array */
550
- mark_index: number;
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;
551
519
  };
552
-
553
520
  /**
554
- * Represents a fragment of annotated node array content
521
+ * Represents a fragment of node array content
555
522
  */
556
523
  export type NodeArrayFragment = NodeArrayPlainFragment | NodeArrayMarkFragment;
524
+ //# sourceMappingURL=types.d.ts.map