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
@@ -1,12 +1,12 @@
1
1
  import type Session from './Session.svelte.js';
2
- import type Svedit from './Svedit.svelte';
2
+ import type { VisibilityRegistryApi } from './node_visibility.svelte.js';
3
3
 
4
4
  // ===== SVELTE TYPE IMPORTS =====
5
5
 
6
6
  /**
7
7
  * Import Svelte's Snippet type for properly typing children in components
8
8
  */
9
- import type { Component, Snippet } from 'svelte';
9
+ import type { Snippet } from 'svelte';
10
10
 
11
11
  // ===== SELECTION TYPE DEFINITIONS =====
12
12
 
@@ -19,6 +19,13 @@ import type { Component, Snippet } from 'svelte';
19
19
  */
20
20
  export type NodeId = string;
21
21
 
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ export type DynamicRecord = Record<string, any>;
24
+ export type SessionConfig = DynamicRecord;
25
+ export type CommandRegistry = DynamicRecord;
26
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ export type DocumentOperation = [string, ...any[]];
28
+
22
29
  /**
23
30
  * Array of IDs, property names (strings), or indexes (integers) that identify a node or property in the document.
24
31
  * String segments must follow the same path segment rules as NodeId.
@@ -81,7 +88,7 @@ export type ArrayType = 'string_array' | 'number_array' | 'boolean_array' | 'int
81
88
  /**
82
89
  * Special types for rich content.
83
90
  */
84
- export type RichType = 'annotated_text';
91
+ export type RichType = 'text';
85
92
 
86
93
  /**
87
94
  * Node reference types for linking to other nodes.
@@ -98,60 +105,89 @@ export type PrimitiveType = ScalarType | ArrayType | RichType;
98
105
  */
99
106
  export type PropertyType = PrimitiveType | ReferenceType;
100
107
 
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[];
108
+ // ===== SCHEMA-DERIVED NODE TYPES =====
109
+
110
+ /**
111
+ * Maps a schema property definition to the runtime value type it stores.
112
+ */
113
+ export type PropertyValue<P extends PropertyDefinition> = P extends {
114
+ type: 'string';
115
+ values: readonly (infer Value extends string)[];
116
+ }
117
+ ? Value
118
+ : P extends { type: 'string' }
119
+ ? string
120
+ : P extends { type: 'number' }
121
+ ? number
122
+ : P extends { type: 'integer' }
123
+ ? number
124
+ : P extends { type: 'boolean' }
125
+ ? boolean
126
+ : P extends { type: 'datetime' }
127
+ ? string
128
+ : P extends { type: 'string_array' }
129
+ ? string[]
130
+ : P extends { type: 'number_array' }
131
+ ? number[]
132
+ : P extends { type: 'integer_array' }
133
+ ? number[]
134
+ : P extends { type: 'boolean_array' }
135
+ ? boolean[]
136
+ : P extends { type: 'text' }
137
+ ? Text
138
+ : P extends { type: 'node' }
139
+ ? NodeId
140
+ : P extends { type: 'node_array' }
141
+ ? NodeArray
142
+ : never;
143
+
144
+ /**
145
+ * The runtime shape of a node of a specific type, derived from the schema.
146
+ *
147
+ * Falls back to the untyped DocumentNode when the schema is not a concrete
148
+ * schema literal (e.g. the DocumentSchema default of Session).
149
+ */
150
+ export type NodeOfType<S extends DocumentSchema, T extends keyof S> = string extends keyof S
151
+ ? DocumentNode
152
+ : {
153
+ id: NodeId;
154
+ type: T;
155
+ } & {
156
+ [K in keyof S[T]['properties']]: PropertyValue<S[T]['properties'][K]>;
157
+ };
158
+
159
+ /**
160
+ * Discriminated union of all node types in a schema. Narrow with
161
+ * `node.type === '...'` to get exact property types.
162
+ *
163
+ * Falls back to the untyped DocumentNode when the schema is not a concrete
164
+ * schema literal (e.g. the DocumentSchema default of Session).
165
+ */
166
+ export type AnyNode<S extends DocumentSchema> = string extends keyof S
167
+ ? DocumentNode
168
+ : {
169
+ [T in keyof S]: NodeOfType<S, T>;
170
+ }[keyof S];
171
+
172
+ /**
173
+ * Convenience map from node type name to its runtime node shape,
174
+ * e.g. `NodeMap<typeof document_schema>['story']`.
175
+ */
176
+ export type NodeMap<S extends DocumentSchema> = {
177
+ [T in keyof S]: NodeOfType<S, T>;
178
+ };
179
+
180
+ /**
181
+ * Assert that a node is of the given type. Narrows the static type and
182
+ * checks at runtime — for call sites that know what they expect.
183
+ */
184
+ /**
185
+ * A property that stores text with optional marks and annotations and required allow_newlines setting.
186
+ */
187
+ export type TextProperty = {
188
+ type: 'text';
189
+ mark_types?: string[];
190
+ annotation_types?: string[];
155
191
  allow_newlines: boolean;
156
192
  };
157
193
 
@@ -161,6 +197,7 @@ export type AnnotatedTextProperty = {
161
197
  export type StringProperty = {
162
198
  type: 'string';
163
199
  default?: string;
200
+ values?: readonly string[];
164
201
  };
165
202
 
166
203
  /**
@@ -185,6 +222,8 @@ export type BooleanProperty = {
185
222
  export type IntegerProperty = {
186
223
  type: 'integer';
187
224
  default?: number;
225
+ min?: number;
226
+ max?: number;
188
227
  };
189
228
 
190
229
  /**
@@ -228,7 +267,7 @@ export type IntegerArrayProperty = {
228
267
  };
229
268
 
230
269
  /**
231
- * A property that stores a primitive value (excluding annotated_text).
270
+ * A property that stores a primitive value (excluding text).
232
271
  */
233
272
  export type PrimitiveProperty =
234
273
  | StringProperty
@@ -256,6 +295,8 @@ export type NodeProperty = {
256
295
  export type NodeArrayProperty = {
257
296
  type: 'node_array';
258
297
  node_types: string[];
298
+ mark_types?: string[];
299
+ annotation_types?: string[];
259
300
  default_node_type?: string;
260
301
  };
261
302
 
@@ -263,29 +304,26 @@ export type NodeArrayProperty = {
263
304
  * Union type for all possible property definitions.
264
305
  */
265
306
  export type PropertyDefinition =
266
- | PrimitiveProperty
267
- | AnnotatedTextProperty
268
- | NodeProperty
269
- | NodeArrayProperty;
307
+ PrimitiveProperty | TextProperty | NodeProperty | NodeArrayProperty;
270
308
 
271
309
  /**
272
310
  * Node kind values for different types of content nodes
273
311
  */
274
- export type NodeKind = 'document' | 'block' | 'text' | 'annotation';
312
+ export type NodeKind = 'document' | 'block' | 'text' | 'mark' | 'annotation';
275
313
 
276
314
  /**
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.
315
+ * Schema for text nodes - must have a content property of type text.
316
+ * Use define_document_schema to also check that content is the only text property.
279
317
  */
280
318
  export type TextNodeSchema = {
281
319
  kind: 'text';
282
320
  properties: {
283
- content: AnnotatedTextProperty;
321
+ content: TextProperty;
284
322
  } & Record<string, PropertyDefinition>;
285
323
  };
286
324
 
287
- export type AnnotatedTextPropertyNames<Properties> = {
288
- [PropertyName in keyof Properties]: Properties[PropertyName] extends { type: 'annotated_text' }
325
+ export type TextPropertyNames<Properties> = {
326
+ [PropertyName in keyof Properties]: Properties[PropertyName] extends { type: 'text' }
289
327
  ? PropertyName
290
328
  : never;
291
329
  }[keyof Properties];
@@ -294,13 +332,11 @@ export type TextNodeSchemaError<Message extends string> = {
294
332
  [SchemaError in `Svedit schema error: ${Message}`]: never;
295
333
  };
296
334
 
297
- export type TextNodeMissingContentError = TextNodeSchemaError<
298
- 'Text node schemas must define a "content" property of type annotated_text.'
299
- >;
335
+ export type TextNodeMissingContentError =
336
+ TextNodeSchemaError<'Text node schemas must define a "content" property of type text.'>;
300
337
 
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
- >;
338
+ export type TextNodeExtraTextPropertyError<ExtraProperty extends string> =
339
+ TextNodeSchemaError<`Text node schemas must not define text property "${ExtraProperty}". Use "content" as the only text property.`>;
304
340
 
305
341
  export type ValidateTextNodeSchema<Schema> = Schema extends {
306
342
  kind: 'text';
@@ -308,11 +344,11 @@ export type ValidateTextNodeSchema<Schema> = Schema extends {
308
344
  }
309
345
  ? string extends keyof Properties
310
346
  ? Schema
311
- : Properties extends { content: AnnotatedTextProperty }
312
- ? Exclude<AnnotatedTextPropertyNames<Properties>, 'content'> extends infer ExtraProperties
347
+ : Properties extends { content: TextProperty }
348
+ ? Exclude<TextPropertyNames<Properties>, 'content'> extends infer ExtraProperties
313
349
  ? [ExtraProperties] extends [never]
314
350
  ? Schema
315
- : TextNodeExtraAnnotatedTextError<Extract<ExtraProperties, string>>
351
+ : TextNodeExtraTextPropertyError<Extract<ExtraProperties, string>>
316
352
  : never
317
353
  : TextNodeMissingContentError
318
354
  : Schema;
@@ -325,7 +361,7 @@ export type ValidateDocumentSchema<Schema extends Record<string, NodeSchema>> =
325
361
  * Schema for non-text nodes
326
362
  */
327
363
  export type NonTextNodeSchema = {
328
- kind: 'document' | 'block' | 'annotation';
364
+ kind: 'document' | 'block' | 'mark' | 'annotation';
329
365
  properties: Record<string, PropertyDefinition>;
330
366
  };
331
367
 
@@ -348,6 +384,13 @@ export type DocumentSchema = Record<string, NodeSchema>;
348
384
  export type DocumentNode = {
349
385
  id: string;
350
386
  type: string;
387
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
388
+ [key: string]: any;
389
+ };
390
+
391
+ export type Inspection = {
392
+ kind: 'property' | 'node';
393
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
351
394
  [key: string]: any;
352
395
  };
353
396
 
@@ -362,10 +405,17 @@ export type Document = {
362
405
  };
363
406
  };
364
407
 
408
+ /** Converts a document node to HTML, with access to recursive exporters. */
409
+ export type NodeHtmlExporter<S extends DocumentSchema = DocumentSchema> = (
410
+ node: DocumentNode,
411
+ session: Session<S>,
412
+ html_exporters: Record<string, NodeHtmlExporter<S>>
413
+ ) => string;
414
+
365
415
  /**
366
- * Props for the AnnotatedTextProperty component
416
+ * Props for the TextProperty component
367
417
  */
368
- export type AnnotatedTextPropertyProps = {
418
+ export type TextPropertyProps = {
369
419
  /** The full path to the property */
370
420
  path: DocumentPath;
371
421
  /** Optional custom HTML tag */
@@ -375,7 +425,7 @@ export type AnnotatedTextPropertyProps = {
375
425
  /** A placeholder to be rendered for empty content */
376
426
  placeholder?: string;
377
427
  /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
378
- [key: string]: any;
428
+ [key: string]: unknown;
379
429
  };
380
430
 
381
431
  /**
@@ -391,7 +441,7 @@ export type CustomPropertyProps = {
391
441
  /** The content of the custom property (e.g. an image) */
392
442
  children: Snippet;
393
443
  /** Rest props to spread onto the rendered element */
394
- [key: string]: any;
444
+ [key: string]: unknown;
395
445
  };
396
446
 
397
447
  /**
@@ -405,7 +455,7 @@ export type NodeArrayPropertyProps = {
405
455
  /** The `class` attribute on the container element */
406
456
  class?: string;
407
457
  /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
408
- [key: string]: any;
458
+ [key: string]: unknown;
409
459
  };
410
460
 
411
461
  /**
@@ -414,6 +464,10 @@ export type NodeArrayPropertyProps = {
414
464
  export type NodeProps = {
415
465
  /** The full path to the node */
416
466
  path: DocumentPath;
467
+ /** The single node-array mark wrapping this node, if any */
468
+ mark?: NodeArrayAttachmentContext | null;
469
+ /** All node-array annotations covering this node */
470
+ annotations?: Array<NodeArrayAttachmentContext>;
417
471
  /** Optional custom HTML tag */
418
472
  tag?: string;
419
473
  /** Optional string of CSS classes */
@@ -421,15 +475,15 @@ export type NodeProps = {
421
475
  /** The type-specific content of the node */
422
476
  children: Snippet;
423
477
  /** Rest props to spread onto the rendered element (e.g. href, target, etc.) */
424
- [key: string]: any;
478
+ [key: string]: unknown;
425
479
  };
426
480
 
427
481
  /**
428
482
  * Props for the Svedit component
429
483
  */
430
- export type SveditProps = {
431
- /** The session instance */
432
- session: Session;
484
+ export type SveditProps<S extends DocumentSchema = DocumentSchema> = {
485
+ /** The schema-typed session instance */
486
+ session: Session<S>;
433
487
  /** Determines wether the document should be editable or read-only. */
434
488
  editable?: boolean;
435
489
  /** The path to the root element (e.g. ['page_1']) */
@@ -443,24 +497,88 @@ export type SveditProps = {
443
497
  };
444
498
 
445
499
  /**
446
- * Represents an annotation in an annotated string
500
+ * Context provided by the Svedit component to commands and descendant components.
501
+ */
502
+ export type SveditContext<S extends DocumentSchema = DocumentSchema> = {
503
+ session: Session<S>;
504
+ editable: boolean;
505
+ is_composing: boolean;
506
+ canvas_el: HTMLElement | undefined;
507
+ canvas_focused: boolean;
508
+ focus_canvas: () => void;
509
+ visibility_registry?: VisibilityRegistryApi;
510
+ };
511
+
512
+ /** Internal descendant context after Svedit's visibility registry is installed. */
513
+ export type SveditRenderContext<S extends DocumentSchema = DocumentSchema> = SveditContext<S> & {
514
+ visibility_registry: VisibilityRegistryApi;
515
+ };
516
+
517
+ /**
518
+ * A range with an attached payload node, used for both marks and annotations.
447
519
  */
448
- export type Annotation = {
520
+ export type Attachment = {
449
521
  start_offset: number;
450
522
  end_offset: number;
451
523
  node_id: NodeId;
452
524
  };
453
525
 
454
526
  /**
455
- * Represents an annotated text with text and annotations
527
+ * A content-level range (e.g. strong, emphasis, link, section).
528
+ * Marks are mutually exclusive within a property and render in-place.
529
+ */
530
+ export type Mark = Attachment;
531
+
532
+ /**
533
+ * A metadata/overlay range (e.g. comment, marker).
534
+ * Annotations may overlap and are data-only.
456
535
  */
457
- export type AnnotatedText = {
458
- text: string;
536
+ export type Annotation = Attachment;
537
+
538
+ /**
539
+ * Represents text content with marks and annotations.
540
+ */
541
+ export type Text = {
542
+ content: string;
543
+ marks: Array<Mark>;
459
544
  annotations: Array<Annotation>;
460
545
  };
461
546
 
462
547
  /**
463
- * Represents a selection highlight fragment for non-annotated text selections
548
+ * Represents a node array with nodes, marks and annotations.
549
+ */
550
+ export type NodeArray = {
551
+ nodes: Array<NodeId>;
552
+ marks: Array<Mark>;
553
+ annotations: Array<Annotation>;
554
+ };
555
+
556
+ /**
557
+ * Attachment context passed to a node rendered inside a node array.
558
+ * It is the flattened mark or annotation attachment, enriched with the resolved
559
+ * payload node, its index in the parent attachment array, and this child node's
560
+ * position in the attachment range.
561
+ */
562
+ export type NodeArrayAttachmentContext = {
563
+ start_offset: number;
564
+ end_offset: number;
565
+ node_id: NodeId;
566
+ index: number;
567
+ node: DocumentNode;
568
+ is_start: boolean;
569
+ is_middle: boolean;
570
+ is_end: boolean;
571
+ };
572
+
573
+ /** Internal context shared by a node array and its rendered child nodes. */
574
+ export type NodeArrayRenderContext = {
575
+ length: number;
576
+ mark_for: (node_index: number) => NodeArrayAttachmentContext | null;
577
+ annotations_for: (node_index: number) => NodeArrayAttachmentContext[];
578
+ };
579
+
580
+ /**
581
+ * Represents a selection highlight fragment for unmarked text selections
464
582
  */
465
583
  export type SelectionHighlightFragment = {
466
584
  type: 'selection_highlight';
@@ -468,19 +586,48 @@ export type SelectionHighlightFragment = {
468
586
  };
469
587
 
470
588
  /**
471
- * Represents an annotation fragment in annotated text content
589
+ * Represents a mark fragment in text content
472
590
  */
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 */
591
+ export type MarkFragment = {
592
+ type: 'mark';
593
+ /** NodeId that has mark type and details */
594
+ node: DocumentNode;
595
+ /** The text content of the mark */
478
596
  content: string;
479
- /** Index of the annotation in the original array */
480
- annotation_index: number;
597
+ /** Index of the mark in the original array */
598
+ mark_index: number;
599
+ };
600
+
601
+ /**
602
+ * Represents a fragment of text content
603
+ */
604
+ export type Fragment = string | MarkFragment | SelectionHighlightFragment;
605
+
606
+ /**
607
+ * Represents a node array fragment for plain nodes
608
+ */
609
+ export type NodeArrayPlainFragment = {
610
+ type: 'nodes';
611
+ nodes: Array<NodeId>;
612
+ start_index: number;
613
+ };
614
+
615
+ /**
616
+ * Represents a mark fragment in node array content
617
+ */
618
+ export type NodeArrayMarkFragment = {
619
+ type: 'mark';
620
+ /** NodeId that has mark type and details */
621
+ node: DocumentNode;
622
+ /** The nodes wrapped by the mark */
623
+ nodes: Array<NodeId>;
624
+ /** Start index in the original nodes array */
625
+ start_index: number;
626
+ /** Index of the mark in the original array */
627
+ mark_index: number;
481
628
  };
482
629
 
483
630
  /**
484
- * Represents a fragment of annotated text content
631
+ * Represents a fragment of node array content
485
632
  */
486
- export type Fragment = string | AnnotationFragment | SelectionHighlightFragment;
633
+ export type NodeArrayFragment = NodeArrayPlainFragment | NodeArrayMarkFragment;