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.
- package/README.md +761 -120
- package/dist/AnnotatedTextProperty.svelte +122 -75
- package/dist/AnnotatedTextProperty.svelte.d.ts.map +1 -1
- package/dist/Command.svelte.d.ts +118 -0
- package/dist/Command.svelte.d.ts.map +1 -0
- package/dist/Command.svelte.js +314 -0
- package/dist/CustomProperty.svelte +31 -42
- package/dist/CustomProperty.svelte.d.ts.map +1 -1
- package/dist/KeyMapper.svelte.d.ts +36 -0
- package/dist/KeyMapper.svelte.d.ts.map +1 -0
- package/dist/KeyMapper.svelte.js +141 -0
- package/dist/Node.svelte +33 -35
- package/dist/Node.svelte.d.ts.map +1 -1
- package/dist/NodeArrayProperty.svelte +40 -37
- package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
- package/dist/{Document.svelte.d.ts → Session.svelte.d.ts} +76 -83
- package/dist/Session.svelte.d.ts.map +1 -0
- package/dist/Session.svelte.js +594 -0
- package/dist/Svedit.svelte +1352 -1512
- package/dist/Svedit.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.d.ts +114 -40
- package/dist/Transaction.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.js +845 -661
- package/dist/UnknownNode.svelte +6 -6
- package/dist/UnknownNode.svelte.d.ts.map +1 -1
- package/dist/doc_utils.d.ts +127 -0
- package/dist/doc_utils.d.ts.map +1 -0
- package/dist/doc_utils.js +482 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +20 -4
- package/dist/{commands.svelte.d.ts → transforms.svelte.d.ts} +1 -2
- package/dist/transforms.svelte.d.ts.map +1 -0
- package/dist/transforms.svelte.js +155 -0
- package/dist/types.d.ts +256 -110
- package/dist/{util.d.ts → utils.d.ts} +22 -2
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +338 -0
- package/package.json +20 -18
- package/src/lib/AnnotatedTextProperty.svelte +122 -75
- package/src/lib/Command.svelte.js +314 -0
- package/src/lib/CustomProperty.svelte +31 -42
- package/src/lib/KeyMapper.svelte.js +141 -0
- package/src/lib/Node.svelte +33 -35
- package/src/lib/NodeArrayProperty.svelte +40 -37
- package/src/lib/Session.svelte.js +594 -0
- package/src/lib/Svedit.svelte +1352 -1512
- package/src/lib/Transaction.svelte.js +845 -661
- package/src/lib/UnknownNode.svelte +6 -6
- package/src/lib/doc_utils.js +482 -0
- package/src/lib/index.js +20 -4
- package/src/lib/transforms.svelte.js +155 -0
- package/src/lib/types.d.ts +256 -110
- package/src/lib/utils.js +338 -0
- package/dist/Document.svelte.d.ts.map +0 -1
- package/dist/Document.svelte.js +0 -833
- package/dist/commands.svelte.d.ts.map +0 -1
- package/dist/commands.svelte.js +0 -266
- package/dist/util.d.ts.map +0 -1
- package/dist/util.js +0 -269
- package/src/lib/Document.svelte.js +0 -833
- package/src/lib/commands.svelte.js +0 -266
- package/src/lib/util.js +0 -269
|
@@ -1,66 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
*
|
|
4
|
-
* DocumentPath,
|
|
5
|
-
* Selection,
|
|
6
|
-
* Annotation,
|
|
7
|
-
* PrimitiveType,
|
|
8
|
-
* NodeProperty,
|
|
9
|
-
* NodeArrayProperty,
|
|
10
|
-
* NodeKind,
|
|
11
|
-
* NodeSchema,
|
|
12
|
-
* DocumentSchema,
|
|
13
|
-
* SerializedDocument
|
|
14
|
-
* } from './types.d.ts';
|
|
2
|
+
* @typedef {Object} SessionOptions
|
|
3
|
+
* @property {Selection} [selection] - Initial selection state
|
|
15
4
|
*/
|
|
16
|
-
|
|
17
|
-
* Identity function — keeps schema at runtime & makes IDE infer types.
|
|
18
|
-
* Similar to your define_schema pattern but for document schemas.
|
|
19
|
-
*
|
|
20
|
-
* @template {Record<string, NodeSchema>} S
|
|
21
|
-
* @param {S} schema - The document schema to validate
|
|
22
|
-
* @returns {S} The same schema, but with type information preserved
|
|
23
|
-
*/
|
|
24
|
-
export function define_document_schema<S extends Record<string, NodeSchema>>(schema: S): S;
|
|
25
|
-
/**
|
|
26
|
-
* Check if a string represents a valid primitive type.
|
|
27
|
-
* @param {string} type - The type string to check
|
|
28
|
-
* @returns {type is PrimitiveType} True if it's a valid primitive type
|
|
29
|
-
*/
|
|
30
|
-
export function is_primitive_type(type: string): type is PrimitiveType;
|
|
31
|
-
/**
|
|
32
|
-
* Get the default node type for a property that references nodes.
|
|
33
|
-
* @param {NodeProperty | NodeArrayProperty} property_definition - The property definition
|
|
34
|
-
* @returns {string | null} The default node type, or null if none specified
|
|
35
|
-
*/
|
|
36
|
-
export function get_default_node_type(property_definition: NodeProperty | NodeArrayProperty): string | null;
|
|
37
|
-
/**
|
|
38
|
-
* Validate a document schema to ensure all referenced node types exist.
|
|
39
|
-
* @param {DocumentSchema} document_schema - The document schema to validate
|
|
40
|
-
* @throws {Error} Throws if the document schema is invalid
|
|
41
|
-
*/
|
|
42
|
-
export function validate_document_schema(document_schema: DocumentSchema): void;
|
|
43
|
-
export default class Document {
|
|
5
|
+
export default class Session {
|
|
44
6
|
/**
|
|
45
7
|
* @param {DocumentSchema} schema - The document schema
|
|
46
|
-
* @param {
|
|
47
|
-
* @param {object}
|
|
8
|
+
* @param {Document} doc - The document
|
|
9
|
+
* @param {object} config - configuration object
|
|
10
|
+
* @param {Object} [options]
|
|
48
11
|
* @param {Selection} [options.selection] - Initial selection state
|
|
49
|
-
* @param {any} [options.config] - Document configuration
|
|
50
12
|
*/
|
|
51
|
-
constructor(schema: DocumentSchema,
|
|
13
|
+
constructor(schema: DocumentSchema, doc: Document, config: object, options?: {
|
|
52
14
|
selection?: Selection;
|
|
53
|
-
config?: any;
|
|
54
15
|
});
|
|
16
|
+
/** @type {DocumentSchema} */
|
|
17
|
+
schema: DocumentSchema;
|
|
18
|
+
/** @type {Document} */
|
|
19
|
+
doc: Document;
|
|
20
|
+
/** @type {any} */
|
|
55
21
|
config: any;
|
|
56
|
-
document_id: any;
|
|
57
|
-
nodes: any;
|
|
58
22
|
history: any[];
|
|
59
23
|
history_index: number;
|
|
24
|
+
last_batch_started: any;
|
|
25
|
+
commands: {};
|
|
26
|
+
keymap: {};
|
|
60
27
|
can_undo: boolean;
|
|
61
28
|
can_redo: boolean;
|
|
62
29
|
selected_node: any;
|
|
63
|
-
layout_node: any;
|
|
64
30
|
available_annotation_types: any;
|
|
65
31
|
/**
|
|
66
32
|
* Sets the selection with validation
|
|
@@ -81,18 +47,26 @@ export default class Document {
|
|
|
81
47
|
* @private
|
|
82
48
|
*/
|
|
83
49
|
private _validate_selection;
|
|
84
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Gets the document_id from the doc
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
get document_id(): string;
|
|
55
|
+
validate_doc(): void;
|
|
85
56
|
generate_id(): any;
|
|
86
|
-
get_available_annotation_types(): any;
|
|
87
|
-
get_selected_node(): any;
|
|
88
|
-
get_layout_node(): any;
|
|
89
|
-
_apply_op(op: any): void;
|
|
90
57
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
58
|
+
* Initialize commands and keymap for this session.
|
|
59
|
+
* Called by Svedit component when it has the necessary context.
|
|
60
|
+
*
|
|
61
|
+
* NOTE: This assumes a single Svedit instance per session.
|
|
62
|
+
* For multiple editors on the same document, this architecture would need
|
|
63
|
+
* to be refactored to support multiple sessions per document.
|
|
64
|
+
*
|
|
65
|
+
* @param {object} context - The svedit context with session, editable, canvas, etc.
|
|
94
66
|
*/
|
|
95
|
-
|
|
67
|
+
initialize_commands(context: object): void;
|
|
68
|
+
get_available_annotation_types(): any;
|
|
69
|
+
get_selected_node(): any;
|
|
96
70
|
/**
|
|
97
71
|
* Creates a new transaction for making atomic changes to the document.
|
|
98
72
|
*
|
|
@@ -101,10 +75,15 @@ export default class Document {
|
|
|
101
75
|
get tr(): Transaction;
|
|
102
76
|
/**
|
|
103
77
|
* Applies a transaction to the document.
|
|
78
|
+
* Auto-batches history entries with debounced behavior (max one entry per 2 seconds) when batch is true.
|
|
104
79
|
*
|
|
105
80
|
* @param {Transaction} transaction - The transaction to apply
|
|
81
|
+
* @param {object} [options] - Optional configuration
|
|
82
|
+
* @param {boolean} [options.batch=false] - Whether to allow batching with previous transaction
|
|
106
83
|
*/
|
|
107
|
-
apply(transaction: Transaction
|
|
84
|
+
apply(transaction: Transaction, { batch }?: {
|
|
85
|
+
batch?: boolean;
|
|
86
|
+
}): this;
|
|
108
87
|
undo(): this;
|
|
109
88
|
redo(): this;
|
|
110
89
|
/**
|
|
@@ -113,19 +92,19 @@ export default class Document {
|
|
|
113
92
|
* @returns {any} Either a node instance object or the value of a property
|
|
114
93
|
* @example
|
|
115
94
|
* // Get a node by ID
|
|
116
|
-
*
|
|
95
|
+
* session.get('list_1') // => { type: 'list', id: 'list_1', ... }
|
|
117
96
|
*
|
|
118
97
|
* @example
|
|
119
98
|
* // Get a node array property
|
|
120
|
-
*
|
|
99
|
+
* session.get(['list_1', 'list_items']) // => [ 'list_item_1', 'list_item_2' ]
|
|
121
100
|
*
|
|
122
101
|
* @example
|
|
123
102
|
* // Get a specific node from an array
|
|
124
|
-
*
|
|
103
|
+
* session.get(['page_1', 'body', 3, 'list_items', 0]) // => { type: 'list_item', id: 'list_item_1', ... }
|
|
125
104
|
*
|
|
126
105
|
* @example
|
|
127
106
|
* // Get an annotated text property
|
|
128
|
-
*
|
|
107
|
+
* session.get(['page_1', 'cover', 'title']) // => {text: 'Hello world', annotations: []}
|
|
129
108
|
*/
|
|
130
109
|
get(path: DocumentPath | string): any;
|
|
131
110
|
/**
|
|
@@ -135,7 +114,7 @@ export default class Document {
|
|
|
135
114
|
* @todo The layout of these should be improved and more explictly typed
|
|
136
115
|
*
|
|
137
116
|
* @example
|
|
138
|
-
*
|
|
117
|
+
* session.inspect(['page_1', 'body']) => {
|
|
139
118
|
* kind: 'property',
|
|
140
119
|
* name: 'body',
|
|
141
120
|
* type: 'node_array',
|
|
@@ -144,7 +123,7 @@ export default class Document {
|
|
|
144
123
|
* }
|
|
145
124
|
*
|
|
146
125
|
* @example
|
|
147
|
-
*
|
|
126
|
+
* session.inspect(['page_1', 'body', 1]) => {
|
|
148
127
|
* kind: 'node',
|
|
149
128
|
* id: 'paragraph_234',
|
|
150
129
|
* type: 'paragraph',
|
|
@@ -183,10 +162,10 @@ export default class Document {
|
|
|
183
162
|
* Returns the annotation object that is currently "under the cursor".
|
|
184
163
|
* NOTE: Annotations in Svedit are exclusive, so there can only be one active_annotation
|
|
185
164
|
*
|
|
186
|
-
* @param {string} annotation_type
|
|
165
|
+
* @param {string} [annotation_type] Optional annotation type to filter by
|
|
187
166
|
* @returns {Annotation|null}
|
|
188
167
|
*/
|
|
189
|
-
active_annotation(annotation_type
|
|
168
|
+
active_annotation(annotation_type?: string): Annotation | null;
|
|
190
169
|
get_selected_annotated_text(): {
|
|
191
170
|
text: string;
|
|
192
171
|
annotations: any;
|
|
@@ -195,18 +174,29 @@ export default class Document {
|
|
|
195
174
|
get_selected_plain_text(): string;
|
|
196
175
|
get_selected_nodes(): any;
|
|
197
176
|
select_parent(): void;
|
|
198
|
-
get_selection_range(): {
|
|
199
|
-
start: number;
|
|
200
|
-
end: number;
|
|
201
|
-
length: number;
|
|
202
|
-
};
|
|
203
|
-
traverse(node_id: any): any[];
|
|
204
177
|
/**
|
|
205
|
-
*
|
|
206
|
-
*
|
|
178
|
+
* Traverses the document and returns a list of nodes in depth-first order.
|
|
179
|
+
*
|
|
180
|
+
* The traversal order is:
|
|
181
|
+
* 1. Leaf nodes first
|
|
182
|
+
* 2. Branch nodes second
|
|
183
|
+
* 3. Root node (entry point) last
|
|
184
|
+
*
|
|
185
|
+
* @param {string} node_id - The ID of the node to start traversing from
|
|
186
|
+
* @returns {Array<DocumentNode>} Array of nodes in depth-first order
|
|
187
|
+
* @note Nodes that are not reachable from the entry point node will not be included
|
|
188
|
+
*/
|
|
189
|
+
traverse(node_id: string): Array<DocumentNode>;
|
|
190
|
+
/**
|
|
191
|
+
* Convert the document to a clean format for persistence.
|
|
192
|
+
*
|
|
193
|
+
* We make a traversal to ensure that orphaned nodes are not included,
|
|
194
|
+
* and that leaf nodes go first, followed by branches and the root node at last.
|
|
195
|
+
*
|
|
196
|
+
* @returns {Document} The document
|
|
207
197
|
*/
|
|
208
|
-
to_json():
|
|
209
|
-
property_type(type: any, property: any):
|
|
198
|
+
to_json(): Document;
|
|
199
|
+
property_type(type: any, property: any): string;
|
|
210
200
|
count_references(node_id: any): number;
|
|
211
201
|
/**
|
|
212
202
|
* @param {NodeId} node_id
|
|
@@ -215,16 +205,19 @@ export default class Document {
|
|
|
215
205
|
get_referenced_nodes(node_id: NodeId): NodeId[];
|
|
216
206
|
#private;
|
|
217
207
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
export type SessionOptions = {
|
|
209
|
+
/**
|
|
210
|
+
* - Initial selection state
|
|
211
|
+
*/
|
|
212
|
+
selection?: Selection;
|
|
213
|
+
};
|
|
222
214
|
import type { DocumentSchema } from './types.d.ts';
|
|
215
|
+
import type { Document } from './types.d.ts';
|
|
223
216
|
import type { Selection } from './types.d.ts';
|
|
224
217
|
import Transaction from './Transaction.svelte.js';
|
|
225
218
|
import type { DocumentPath } from './types.d.ts';
|
|
226
219
|
import type { NodeKind } from './types.d.ts';
|
|
227
220
|
import type { Annotation } from './types.d.ts';
|
|
228
|
-
import type {
|
|
221
|
+
import type { DocumentNode } from './types.d.ts';
|
|
229
222
|
import type { NodeId } from './types.d.ts';
|
|
230
|
-
//# sourceMappingURL=
|
|
223
|
+
//# sourceMappingURL=Session.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Session.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Session.svelte.js"],"names":[],"mappings":"AA6BA;;;GAGG;AAEH;IA8BC;;;;;;OAMG;IACH,oBANW,cAAc,OACd,QAAQ,UACR,MAAM,YAEd;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