svedit 0.5.0 → 0.6.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 (62) hide show
  1. package/README.md +761 -120
  2. package/dist/AnnotatedTextProperty.svelte +122 -75
  3. package/dist/AnnotatedTextProperty.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.d.ts +118 -0
  5. package/dist/Command.svelte.d.ts.map +1 -0
  6. package/dist/Command.svelte.js +314 -0
  7. package/dist/CustomProperty.svelte +31 -42
  8. package/dist/CustomProperty.svelte.d.ts.map +1 -1
  9. package/dist/KeyMapper.svelte.d.ts +36 -0
  10. package/dist/KeyMapper.svelte.d.ts.map +1 -0
  11. package/dist/KeyMapper.svelte.js +141 -0
  12. package/dist/Node.svelte +33 -35
  13. package/dist/Node.svelte.d.ts.map +1 -1
  14. package/dist/NodeArrayProperty.svelte +40 -37
  15. package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
  16. package/dist/{Document.svelte.d.ts → Session.svelte.d.ts} +76 -83
  17. package/dist/Session.svelte.d.ts.map +1 -0
  18. package/dist/Session.svelte.js +594 -0
  19. package/dist/Svedit.svelte +1352 -1512
  20. package/dist/Svedit.svelte.d.ts.map +1 -1
  21. package/dist/Transaction.svelte.d.ts +114 -40
  22. package/dist/Transaction.svelte.d.ts.map +1 -1
  23. package/dist/Transaction.svelte.js +845 -661
  24. package/dist/UnknownNode.svelte +6 -6
  25. package/dist/UnknownNode.svelte.d.ts.map +1 -1
  26. package/dist/doc_utils.d.ts +127 -0
  27. package/dist/doc_utils.d.ts.map +1 -0
  28. package/dist/doc_utils.js +482 -0
  29. package/dist/index.d.ts +7 -3
  30. package/dist/index.js +20 -4
  31. package/dist/{commands.svelte.d.ts → transforms.svelte.d.ts} +1 -2
  32. package/dist/transforms.svelte.d.ts.map +1 -0
  33. package/dist/transforms.svelte.js +155 -0
  34. package/dist/types.d.ts +256 -110
  35. package/dist/{util.d.ts → utils.d.ts} +22 -2
  36. package/dist/utils.d.ts.map +1 -0
  37. package/dist/utils.js +338 -0
  38. package/package.json +20 -18
  39. package/src/lib/AnnotatedTextProperty.svelte +122 -75
  40. package/src/lib/Command.svelte.js +314 -0
  41. package/src/lib/CustomProperty.svelte +31 -42
  42. package/src/lib/KeyMapper.svelte.js +141 -0
  43. package/src/lib/Node.svelte +33 -35
  44. package/src/lib/NodeArrayProperty.svelte +40 -37
  45. package/src/lib/Session.svelte.js +594 -0
  46. package/src/lib/Svedit.svelte +1352 -1512
  47. package/src/lib/Transaction.svelte.js +845 -661
  48. package/src/lib/UnknownNode.svelte +6 -6
  49. package/src/lib/doc_utils.js +482 -0
  50. package/src/lib/index.js +20 -4
  51. package/src/lib/transforms.svelte.js +155 -0
  52. package/src/lib/types.d.ts +256 -110
  53. package/src/lib/utils.js +338 -0
  54. package/dist/Document.svelte.d.ts.map +0 -1
  55. package/dist/Document.svelte.js +0 -833
  56. package/dist/commands.svelte.d.ts.map +0 -1
  57. package/dist/commands.svelte.js +0 -266
  58. package/dist/util.d.ts.map +0 -1
  59. package/dist/util.js +0 -269
  60. package/src/lib/Document.svelte.js +0 -833
  61. package/src/lib/commands.svelte.js +0 -266
  62. package/src/lib/util.js +0 -269
@@ -1,4 +1,4 @@
1
- import type Document from './Document.svelte.js';
1
+ import type Session from './Session.svelte.js';
2
2
  import type Svedit from './Svedit.svelte';
3
3
 
4
4
  // ===== SVELTE TYPE IMPORTS =====
@@ -24,28 +24,28 @@ export type DocumentPath = Array<string | number>;
24
24
  * Text selection within a text property
25
25
  */
26
26
  export type TextSelection = {
27
- type: "text";
28
- path: DocumentPath;
29
- anchor_offset: number;
30
- focus_offset: number;
27
+ type: 'text';
28
+ path: DocumentPath;
29
+ anchor_offset: number;
30
+ focus_offset: number;
31
31
  };
32
32
 
33
33
  /**
34
34
  * Node selection within a node array
35
35
  */
36
36
  export type NodeSelection = {
37
- type: "node";
38
- path: DocumentPath;
39
- anchor_offset: number;
40
- focus_offset: number;
37
+ type: 'node';
38
+ path: DocumentPath;
39
+ anchor_offset: number;
40
+ focus_offset: number;
41
41
  };
42
42
 
43
43
  /**
44
44
  * Property selection within a node
45
45
  */
46
46
  export type PropertySelection = {
47
- type: "property";
48
- path: DocumentPath;
47
+ type: 'property';
48
+ path: DocumentPath;
49
49
  };
50
50
 
51
51
  /**
@@ -53,27 +53,35 @@ export type PropertySelection = {
53
53
  */
54
54
  export type Selection = TextSelection | NodeSelection | PropertySelection;
55
55
 
56
+ /**
57
+ * Represents only the range (no direction and payload) of a NodeSelection or TextSelection
58
+ */
59
+ export type SelectionRange = {
60
+ start_offset: number;
61
+ end_offset: number;
62
+ };
63
+
56
64
  // ===== SCHEMA TYPE DEFINITIONS =====
57
65
 
58
66
  /**
59
67
  * Basic scalar types supported by the schema system.
60
68
  */
61
- export type ScalarType = "string" | "number" | "boolean" | "integer" | "datetime";
69
+ export type ScalarType = 'string' | 'number' | 'boolean' | 'integer' | 'datetime';
62
70
 
63
71
  /**
64
72
  * Array types for collections of scalar values.
65
73
  */
66
- export type ArrayType = "string_array" | "number_array" | "boolean_array" | "integer_array";
74
+ export type ArrayType = 'string_array' | 'number_array' | 'boolean_array' | 'integer_array';
67
75
 
68
76
  /**
69
77
  * Special types for rich content.
70
78
  */
71
- export type RichType = "annotated_text";
79
+ export type RichType = 'annotated_text';
72
80
 
73
81
  /**
74
82
  * Node reference types for linking to other nodes.
75
83
  */
76
- export type ReferenceType = "node" | "node_array";
84
+ export type ReferenceType = 'node' | 'node_array';
77
85
 
78
86
  /**
79
87
  * All primitive types that can be used in property definitions.
@@ -88,71 +96,178 @@ export type PropertyType = PrimitiveType | ReferenceType;
88
96
  /**
89
97
  * Document schema primitive types - all possible property types in document schemas.
90
98
  */
91
- export type DocumentSchemaPrimitive = "string" | "number" | "boolean" | "integer" | "datetime" | "string_array" | "number_array" | "boolean_array" | "integer_array" | "annotated_text" | "node" | "node_array";
99
+ export type DocumentSchemaPrimitive =
100
+ | 'string'
101
+ | 'number'
102
+ | 'boolean'
103
+ | 'integer'
104
+ | 'datetime'
105
+ | 'string_array'
106
+ | 'number_array'
107
+ | 'boolean_array'
108
+ | 'integer_array'
109
+ | 'annotated_text'
110
+ | 'node'
111
+ | 'node_array';
92
112
 
93
113
  /**
94
114
  * Maps document schema types to their JavaScript runtime types.
95
115
  */
96
- export type DocumentSchemaValueToJs<T> =
97
- T extends "string" ? string :
98
- T extends "number" ? number :
99
- T extends "boolean" ? boolean :
100
- T extends "integer" ? number :
101
- T extends "datetime" ? string :
102
- T extends "string_array" ? Array<string> :
103
- T extends "number_array" ? Array<number> :
104
- T extends "boolean_array" ? Array<boolean> :
105
- T extends "integer_array" ? Array<number> :
106
- T extends "annotated_text" ? AnnotatedText :
107
- T extends "node" ? string :
108
- T extends "node_array" ? Array<string> :
109
- never;
116
+ export type DocumentSchemaValueToJs<T> = T extends 'string'
117
+ ? string
118
+ : T extends 'number'
119
+ ? number
120
+ : T extends 'boolean'
121
+ ? boolean
122
+ : T extends 'integer'
123
+ ? number
124
+ : T extends 'datetime'
125
+ ? string
126
+ : T extends 'string_array'
127
+ ? Array<string>
128
+ : T extends 'number_array'
129
+ ? Array<number>
130
+ : T extends 'boolean_array'
131
+ ? Array<boolean>
132
+ : T extends 'integer_array'
133
+ ? Array<number>
134
+ : T extends 'annotated_text'
135
+ ? AnnotatedText
136
+ : T extends 'node'
137
+ ? string
138
+ : T extends 'node_array'
139
+ ? Array<string>
140
+ : never;
110
141
 
111
142
  /**
112
143
  * Converts a document node schema definition to its inferred JS type.
113
144
  * Handles the {type: "..."} wrapper structure used in document schemas.
114
145
  */
115
- export type DocumentNodeToJs<S extends NodeSchema> =
116
- { id: string, type: string } & { [K in keyof S["properties"]]: DocumentSchemaValueToJs<S["properties"][K]["type"]> };
146
+ export type DocumentNodeToJs<S extends NodeSchema> = { id: string; type: string } & {
147
+ [K in keyof S['properties']]: DocumentSchemaValueToJs<S['properties'][K]['type']>;
148
+ };
117
149
 
118
150
  /**
119
151
  * A property that stores an annotated text with required allow_newlines setting.
120
152
  */
121
153
  export type AnnotatedTextProperty = {
122
- type: 'annotated_text';
123
- node_types?: string[];
124
- allow_newlines: boolean;
154
+ type: 'annotated_text';
155
+ node_types?: string[];
156
+ allow_newlines: boolean;
157
+ };
158
+
159
+ /**
160
+ * A property that stores a string value.
161
+ */
162
+ export type StringProperty = {
163
+ type: 'string';
164
+ default?: string;
165
+ };
166
+
167
+ /**
168
+ * A property that stores a number value.
169
+ */
170
+ export type NumberProperty = {
171
+ type: 'number';
172
+ default?: number;
173
+ };
174
+
175
+ /**
176
+ * A property that stores a boolean value.
177
+ */
178
+ export type BooleanProperty = {
179
+ type: 'boolean';
180
+ default?: boolean;
181
+ };
182
+
183
+ /**
184
+ * A property that stores an integer value.
185
+ */
186
+ export type IntegerProperty = {
187
+ type: 'integer';
188
+ default?: number;
189
+ };
190
+
191
+ /**
192
+ * A property that stores a datetime value.
193
+ */
194
+ export type DatetimeProperty = {
195
+ type: 'datetime';
196
+ default?: string;
197
+ };
198
+
199
+ /**
200
+ * A property that stores an array of strings.
201
+ */
202
+ export type StringArrayProperty = {
203
+ type: 'string_array';
204
+ default?: string[];
205
+ };
206
+
207
+ /**
208
+ * A property that stores an array of numbers.
209
+ */
210
+ export type NumberArrayProperty = {
211
+ type: 'number_array';
212
+ default?: number[];
213
+ };
214
+
215
+ /**
216
+ * A property that stores an array of booleans.
217
+ */
218
+ export type BooleanArrayProperty = {
219
+ type: 'boolean_array';
220
+ default?: boolean[];
221
+ };
222
+
223
+ /**
224
+ * A property that stores an array of integers.
225
+ */
226
+ export type IntegerArrayProperty = {
227
+ type: 'integer_array';
228
+ default?: number[];
125
229
  };
126
230
 
127
231
  /**
128
232
  * A property that stores a primitive value (excluding annotated_text).
129
233
  */
130
- export type PrimitiveProperty = {
131
- [K in Exclude<PrimitiveType, 'annotated_text'>]: { type: K }
132
- }[Exclude<PrimitiveType, 'annotated_text'>];
234
+ export type PrimitiveProperty =
235
+ | StringProperty
236
+ | NumberProperty
237
+ | BooleanProperty
238
+ | IntegerProperty
239
+ | DatetimeProperty
240
+ | StringArrayProperty
241
+ | NumberArrayProperty
242
+ | BooleanArrayProperty
243
+ | IntegerArrayProperty;
133
244
 
134
245
  /**
135
246
  * A property that stores a reference to a single node.
136
247
  */
137
248
  export type NodeProperty = {
138
- type: "node";
139
- node_types: string[];
140
- default_node_type?: string;
249
+ type: 'node';
250
+ node_types: string[];
251
+ default_node_type?: string;
141
252
  };
142
253
 
143
254
  /**
144
255
  * A property that stores an array of node references.
145
256
  */
146
257
  export type NodeArrayProperty = {
147
- type: "node_array";
148
- node_types: string[];
149
- default_node_type?: string;
258
+ type: 'node_array';
259
+ node_types: string[];
260
+ default_node_type?: string;
150
261
  };
151
262
 
152
263
  /**
153
264
  * Union type for all possible property definitions.
154
265
  */
155
- export type PropertyDefinition = PrimitiveProperty | AnnotatedTextProperty | NodeProperty | NodeArrayProperty;
266
+ export type PropertyDefinition =
267
+ | PrimitiveProperty
268
+ | AnnotatedTextProperty
269
+ | NodeProperty
270
+ | NodeArrayProperty;
156
271
 
157
272
  /**
158
273
  * Node kind values for different types of content nodes
@@ -163,18 +278,18 @@ export type NodeKind = 'document' | 'block' | 'text' | 'annotation';
163
278
  * Schema for text nodes - must have a content property of type annotated_text
164
279
  */
165
280
  export type TextNodeSchema = {
166
- kind: 'text';
167
- properties: {
168
- content: AnnotatedTextProperty;
169
- } & Record<string, PropertyDefinition>;
281
+ kind: 'text';
282
+ properties: {
283
+ content: AnnotatedTextProperty;
284
+ } & Record<string, PropertyDefinition>;
170
285
  };
171
286
 
172
287
  /**
173
288
  * Schema for non-text nodes
174
289
  */
175
290
  export type NonTextNodeSchema = {
176
- kind: 'document' | 'block' | 'annotation';
177
- properties: Record<string, PropertyDefinition>;
291
+ kind: 'document' | 'block' | 'annotation';
292
+ properties: Record<string, PropertyDefinition>;
178
293
  };
179
294
 
180
295
  /**
@@ -190,120 +305,151 @@ export type NodeSchema = TextNodeSchema | NonTextNodeSchema;
190
305
  export type DocumentSchema = Record<string, NodeSchema>;
191
306
 
192
307
  /**
193
- * A serialized node in the document format.
308
+ * A node in the document.
194
309
  * Must have id and type properties, with other properties defined by the schema.
195
310
  */
196
- export type SerializedNode = {
197
- id: string;
198
- type: string;
199
- [key: string]: any;
311
+ export type DocumentNode = {
312
+ id: string;
313
+ type: string;
314
+ [key: string]: any;
200
315
  };
201
316
 
202
317
  /**
203
- * The document serialization format - an array of serialized nodes.
204
- * Nodes must be ordered so that referenced nodes come before nodes that reference them.
318
+ * The document format - an object with document_id and nodes.
319
+ * The nodes object maps node IDs to their node data.
205
320
  */
206
- export type SerializedDocument = SerializedNode[];
321
+ export type Document = {
322
+ document_id: string;
323
+ nodes: {
324
+ [key: string]: DocumentNode;
325
+ };
326
+ };
207
327
 
208
328
  /**
209
329
  * Props for the AnnotatedTextProperty component
210
330
  */
211
331
  export type AnnotatedTextPropertyProps = {
212
- /** The full path to the property */
213
- path: DocumentPath;
214
- /** The `class` attribute on the content element */
215
- class?: string;
216
- /** A placeholder to be rendered for empty content */
217
- placeholder?: string;
332
+ /** The full path to the property */
333
+ path: DocumentPath;
334
+ /** Optional custom HTML tag */
335
+ tag?: string;
336
+ /** The `class` attribute on the content element */
337
+ class?: string;
338
+ /** A placeholder to be rendered for empty content */
339
+ placeholder?: string;
218
340
  };
219
341
 
220
342
  /**
221
343
  * Props for the CustomProperty component
222
344
  */
223
345
  export type CustomPropertyProps = {
224
- /** The full path to the property */
225
- path: DocumentPath;
226
- /** The `class` attribute on the content element */
227
- class?: string;
228
- /** The content of the custom property (e.g. an image) */
229
- children: Snippet;
346
+ /** The full path to the property */
347
+ path: DocumentPath;
348
+ /** Optional custom HTML tag */
349
+ tag?: string;
350
+ /** The `class` attribute on the content element */
351
+ class?: string;
352
+ /** The content of the custom property (e.g. an image) */
353
+ children: Snippet;
230
354
  };
231
355
 
232
356
  /**
233
357
  * Props for the NodeArray component
234
358
  */
235
359
  export type NodeArrayPropertyProps = {
236
- /** The full path to the property */
237
- path: DocumentPath;
238
- /** The `class` attribute on the container element */
239
- class?: string;
360
+ /** The full path to the property */
361
+ path: DocumentPath;
362
+ /** Optional custom HTML tag */
363
+ tag?: string;
364
+ /** Optional custom HTML tag */
365
+ tag?: string;
366
+ /** The `class` attribute on the container element */
367
+ class?: string;
240
368
  };
241
369
 
242
370
  /**
243
371
  * Props for the Node component
244
372
  */
245
373
  export type NodeProps = {
246
- /** The full path to the node */
247
- path: DocumentPath;
248
- /** The type-specific content of the node */
249
- children: Snippet;
374
+ /** The full path to the node */
375
+ path: DocumentPath;
376
+ /** Optional custom HTML tag */
377
+ tag?: string;
378
+ /** Optional string of CSS classes */
379
+ class?: string;
380
+ /** The type-specific content of the node */
381
+ children: Snippet;
250
382
  };
251
383
 
252
384
  /**
253
385
  * Props for the CustomProperty component
254
386
  */
255
387
  export type CustomPropertyProps = {
256
- /** The full path to the property */
257
- path: DocumentPath;
258
- /** The `class` attribute on the content element */
259
- class?: string;
260
- /** The content of the custom property (e.g. an image) */
261
- children: Snippet;
388
+ /** The full path to the property */
389
+ path: DocumentPath;
390
+ /** The `class` attribute on the content element */
391
+ class?: string;
392
+ /** The content of the custom property (e.g. an image) */
393
+ children: Snippet;
262
394
  };
263
395
 
264
396
  /**
265
397
  * Props for the CustomProperty component
266
398
  */
267
399
  export type SveditProps = {
268
- /** The full path to the property */
269
- doc: Document,
270
- /** Determines wether the document should be editable or read-only. */
271
- editable?: boolean,
272
- /** The path to the root element (e.g. ['page_1']) */
273
- path: DocumentPath,
274
- /** The `class` attribute on the canvas element */
275
- class?: string;
276
- /** The `autocapitalize` attribute on the canvas element */
277
- autocapitalize?: 'on' | 'off';
278
- /** The `spellcheck` attribute on the canvas element */
279
- spellcheck?: 'true' | 'false';
400
+ /** The session instance */
401
+ session: Session;
402
+ /** Determines wether the document should be editable or read-only. */
403
+ editable?: boolean;
404
+ /** The path to the root element (e.g. ['page_1']) */
405
+ path: DocumentPath;
406
+ /** The `class` attribute on the canvas element */
407
+ class?: string;
408
+ /** The `autocapitalize` attribute on the canvas element */
409
+ autocapitalize?: 'on' | 'off';
410
+ /** The `spellcheck` attribute on the canvas element */
411
+ spellcheck?: 'true' | 'false';
280
412
  };
281
413
 
282
414
  /**
283
415
  * Represents an annotation in an annotated string
284
416
  */
285
417
  export type Annotation = {
286
- start_offset: number;
287
- end_offset: number;
288
- node_id: NodeId;
418
+ start_offset: number;
419
+ end_offset: number;
420
+ node_id: NodeId;
289
421
  };
290
422
 
291
423
  /**
292
424
  * Represents an annotated text with text and annotations
293
425
  */
294
426
  export type AnnotatedText = {
295
- text: string;
296
- annotations: Array<Annotation>;
427
+ text: string;
428
+ annotations: Array<Annotation>;
297
429
  };
298
430
 
299
431
  /**
300
- * Represents a fragment of annotated text content
432
+ * Represents a selection highlight fragment for non-annotated text selections
433
+ */
434
+ export type SelectionHighlightFragment = {
435
+ type: 'selection_highlight';
436
+ content: string;
437
+ };
438
+
439
+ /**
440
+ * Represents an annotation fragment in annotated text content
301
441
  */
302
- export type AnnotationFragment = string | {
303
- /** NodeId that has annotation type and details */
304
- node: any;
305
- /** The text content of the annotation */
306
- content: string;
307
- /** Index of the annotation in the original array */
308
- annotation_index: number;
442
+ export type AnnotationFragment = {
443
+ type: 'annotation';
444
+ /** NodeId that has annotation type and details */
445
+ node: any;
446
+ /** The text content of the annotation */
447
+ content: string;
448
+ /** Index of the annotation in the original array */
449
+ annotation_index: number;
309
450
  };
451
+
452
+ /**
453
+ * Represents a fragment of annotated text content
454
+ */
455
+ export type Fragment = string | AnnotationFragment | SelectionHighlightFragment;