svedit 0.5.0 → 0.6.1
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 +129 -76
- 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 +1338 -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 +129 -76
- 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 +1338 -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.js"],"names":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.js"],"names":[],"mappings":";;;;;;;AAwyCA;;eAAqD;iCAhxC1C,cAAc"}
|
|
@@ -7,38 +7,106 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```js
|
|
10
|
-
* const tr =
|
|
10
|
+
* const tr = session.tr;
|
|
11
11
|
* tr.set(['node_1', 'title'], 'New Title');
|
|
12
12
|
* tr.create({id: 'node_2', type: 'paragraph', content: 'Hello'});
|
|
13
|
-
*
|
|
13
|
+
* session.apply(tr); // Applies all operations atomically
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export default class Transaction {
|
|
17
17
|
/**
|
|
18
|
-
* Creates a new Transaction
|
|
18
|
+
* Creates a new Transaction with the given state.
|
|
19
19
|
*
|
|
20
|
-
* @param {
|
|
20
|
+
* @param {DocumentSchema} schema - The document schema
|
|
21
|
+
* @param {Document} doc - The document state {document_id, nodes}
|
|
22
|
+
* @param {Selection | null} selection - The current selection
|
|
23
|
+
* @param {object} config - The document config (including generate_id)
|
|
21
24
|
*/
|
|
22
|
-
constructor(doc:
|
|
23
|
-
|
|
25
|
+
constructor(schema: DocumentSchema, doc: Document, selection: Selection | null, config: object);
|
|
26
|
+
schema: DocumentSchema;
|
|
27
|
+
/** @type {object} */
|
|
28
|
+
doc: object;
|
|
29
|
+
/** @type {Selection} */
|
|
30
|
+
selection: Selection;
|
|
31
|
+
config: any;
|
|
24
32
|
/** @type {Record<string, any>[]} */
|
|
25
33
|
ops: Record<string, any>[];
|
|
26
34
|
/** @type {Record<string, any>[]} */
|
|
27
35
|
inverse_ops: Record<string, any>[];
|
|
28
|
-
selection_before:
|
|
36
|
+
selection_before: Selection;
|
|
29
37
|
/**
|
|
30
38
|
* Gets a value from the document at the specified path.
|
|
31
39
|
*
|
|
32
|
-
* @param {DocumentPath} path - The path to the value in the document
|
|
40
|
+
* @param {DocumentPath|string} path - The path to the value in the document, or a string node ID
|
|
33
41
|
* @returns {any} The value at the specified path
|
|
34
42
|
*/
|
|
35
|
-
get(path: DocumentPath): any;
|
|
43
|
+
get(path: DocumentPath | string): any;
|
|
36
44
|
/**
|
|
37
|
-
* Gets the
|
|
45
|
+
* Gets the type of a property from the schema.
|
|
38
46
|
*
|
|
39
|
-
* @
|
|
47
|
+
* @param {string} type - The node type
|
|
48
|
+
* @param {string} property - The property name
|
|
49
|
+
* @returns {string} The property type
|
|
40
50
|
*/
|
|
41
|
-
|
|
51
|
+
property_type(type: string, property: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* Determines the kind of a node ('block', 'text', or 'annotation').
|
|
54
|
+
*
|
|
55
|
+
* @param {any} node - The node to check
|
|
56
|
+
* @returns {'block'|'text'|'annotation'} The node kind
|
|
57
|
+
*/
|
|
58
|
+
kind(node: any): "block" | "text" | "annotation";
|
|
59
|
+
/**
|
|
60
|
+
* Inspects a path to get metadata about the value at that location.
|
|
61
|
+
*
|
|
62
|
+
* @param {DocumentPath} path - The path to inspect
|
|
63
|
+
* @returns {{kind: 'property'|'node', [key: string]: any}} Metadata about the path
|
|
64
|
+
*/
|
|
65
|
+
inspect(path: DocumentPath): {
|
|
66
|
+
kind: "property" | "node";
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Generates a new unique ID using the config's generate_id function.
|
|
71
|
+
*
|
|
72
|
+
* @returns {string} A new unique ID
|
|
73
|
+
*/
|
|
74
|
+
generate_id(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Validates a node against the document schema.
|
|
77
|
+
*
|
|
78
|
+
* @param {any} node - The node to validate
|
|
79
|
+
* @throws {Error} Throws if the node is invalid
|
|
80
|
+
*/
|
|
81
|
+
validate_node(node: any): void;
|
|
82
|
+
/**
|
|
83
|
+
* Gets all nodes referenced by a given node (recursively).
|
|
84
|
+
*
|
|
85
|
+
* @param {NodeId} node_id - The node ID to get references for
|
|
86
|
+
* @returns {NodeId[]} Array of referenced node IDs
|
|
87
|
+
*/
|
|
88
|
+
get_referenced_nodes(node_id: NodeId): NodeId[];
|
|
89
|
+
/**
|
|
90
|
+
* Gets the available annotation types for the current selection.
|
|
91
|
+
*
|
|
92
|
+
* @returns {string[]} Array of available annotation type names
|
|
93
|
+
*/
|
|
94
|
+
get available_annotation_types(): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Returns the annotation object that is currently "under the cursor".
|
|
97
|
+
* NOTE: Annotations in Svedit are exclusive, so there can only be one active_annotation
|
|
98
|
+
*
|
|
99
|
+
* @param {string} [annotation_type] Optional annotation type to filter by
|
|
100
|
+
* @returns {Annotation|null}
|
|
101
|
+
*/
|
|
102
|
+
active_annotation(annotation_type?: string): Annotation | null;
|
|
103
|
+
/**
|
|
104
|
+
* Applies an operation to the document (internal).
|
|
105
|
+
*
|
|
106
|
+
* @param {Array} op - The operation to apply
|
|
107
|
+
* @private
|
|
108
|
+
*/
|
|
109
|
+
private _apply_op;
|
|
42
110
|
/**
|
|
43
111
|
* Sets a property of a node to a new value.
|
|
44
112
|
*
|
|
@@ -99,6 +167,14 @@ export default class Transaction {
|
|
|
99
167
|
* @throws {Error} Throws if the selection is invalid or out of bounds
|
|
100
168
|
*/
|
|
101
169
|
set_selection(selection: Selection): Transaction;
|
|
170
|
+
/**
|
|
171
|
+
* Validates a selection against the current document state.
|
|
172
|
+
*
|
|
173
|
+
* @param {Selection} selection - The selection to validate
|
|
174
|
+
* @throws {Error} Throws if the selection is invalid
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
private _validate_selection;
|
|
102
178
|
/**
|
|
103
179
|
* Adds, updates, or removes text annotations in the current selection.
|
|
104
180
|
*
|
|
@@ -127,57 +203,52 @@ export default class Transaction {
|
|
|
127
203
|
* - For node selections: Removes selected nodes and cascades deletion of unreferenced nodes
|
|
128
204
|
* - For text selections: Removes selected text and adjusts annotations accordingly
|
|
129
205
|
* - For collapsed selections: Deletes the previous character/node (backward) or next character/node (forward)
|
|
206
|
+
* - Property selections are ignored: Those are best handled handled via commands + keyboard shortcuts.
|
|
130
207
|
*
|
|
131
208
|
* @param {'backward' | 'forward'} [direction] - Direction of deletion for collapsed selections
|
|
132
209
|
* @returns {Transaction} This transaction instance for method chaining
|
|
133
210
|
*/
|
|
134
211
|
delete_selection(direction?: "backward" | "forward"): Transaction;
|
|
135
212
|
/**
|
|
136
|
-
* Inserts
|
|
213
|
+
* Inserts nodes at the current node selection position.
|
|
137
214
|
*
|
|
138
|
-
* If
|
|
215
|
+
* If the selection is expanded (not collapsed), first deletes the selected nodes
|
|
216
|
+
* before inserting the new ones.
|
|
139
217
|
*
|
|
140
218
|
* @param {NodeId[]} node_ids - Array of node IDs to insert
|
|
141
219
|
* @returns {Transaction} This transaction instance for method chaining
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```js
|
|
145
|
-
* tr.insert_nodes_new(['para_1', 'para_2']);
|
|
146
|
-
* ```
|
|
147
220
|
*/
|
|
148
221
|
insert_nodes(node_ids: NodeId[]): Transaction;
|
|
149
222
|
/**
|
|
150
|
-
* Inserts text at the current text selection
|
|
223
|
+
* Inserts text at the current text selection position.
|
|
151
224
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
225
|
+
* Handles annotation adjustments when text is inserted, including:
|
|
226
|
+
* - Expanding annotations that contain the insertion point
|
|
227
|
+
* - Shifting annotations that come after the insertion point
|
|
228
|
+
* - Optionally applying new annotations to the inserted text
|
|
154
229
|
*
|
|
155
230
|
* @param {string} replaced_text - The text to insert
|
|
231
|
+
* @param {Array} [annotations] - Optional annotations to apply to the inserted text
|
|
232
|
+
* @param {object} [nodes] - Optional node definitions for annotation nodes
|
|
156
233
|
* @returns {Transaction} This transaction instance for method chaining
|
|
157
|
-
*
|
|
158
|
-
* @todo Support annotations attached to replaced_text for full copy&paste support
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```js
|
|
162
|
-
* tr.insert_text('Hello, world!');
|
|
163
|
-
* ```
|
|
164
234
|
*/
|
|
165
|
-
insert_text(replaced_text: string, annotations?: any[], nodes?:
|
|
235
|
+
insert_text(replaced_text: string, annotations?: any[], nodes?: object): Transaction;
|
|
166
236
|
/**
|
|
167
|
-
* Recursively deletes nodes that
|
|
237
|
+
* Recursively deletes nodes that are no longer referenced in the document.
|
|
168
238
|
*
|
|
169
|
-
* This
|
|
170
|
-
*
|
|
239
|
+
* This handles the cascade deletion of child nodes when their parent
|
|
240
|
+
* references are removed. Uses reference counting to determine which
|
|
241
|
+
* nodes are safe to delete.
|
|
171
242
|
*
|
|
172
|
-
* @param {NodeId[]}
|
|
243
|
+
* @param {NodeId[]} potentially_orphaned_nodes - Array of node IDs to check
|
|
173
244
|
* @private
|
|
174
245
|
*/
|
|
175
246
|
private _cascade_delete_unreferenced_nodes;
|
|
176
247
|
/**
|
|
177
|
-
* Counts references to a
|
|
248
|
+
* Counts references to a node, excluding nodes that have been marked for deletion.
|
|
178
249
|
*
|
|
179
|
-
* This is used during cascade deletion to
|
|
180
|
-
*
|
|
250
|
+
* This is used during cascade deletion to accurately count remaining references
|
|
251
|
+
* as nodes are being deleted.
|
|
181
252
|
*
|
|
182
253
|
* @param {NodeId} target_node_id - The node ID to count references for
|
|
183
254
|
* @param {Record<NodeId, boolean>} nodes_to_delete - Nodes already marked for deletion
|
|
@@ -186,7 +257,10 @@ export default class Transaction {
|
|
|
186
257
|
*/
|
|
187
258
|
private _count_references_excluding_deleted;
|
|
188
259
|
}
|
|
189
|
-
import type {
|
|
190
|
-
import type { Selection } from './types.js';
|
|
191
|
-
import type {
|
|
260
|
+
import type { DocumentSchema } from './types.d.js';
|
|
261
|
+
import type { Selection } from './types.d.js';
|
|
262
|
+
import type { DocumentPath } from './types.d.js';
|
|
263
|
+
import type { NodeId } from './types.d.js';
|
|
264
|
+
import type { Annotation } from './types.d.js';
|
|
265
|
+
import type { Document } from './types.d.js';
|
|
192
266
|
//# sourceMappingURL=Transaction.svelte.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Transaction.svelte.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Transaction.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Transaction.svelte.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;GAcG;AACH;IACC;;;;;;;OAOG;IACH,oBALW,cAAc,OACd,QAAQ,aACR,SAAS,GAAG,IAAI,UAChB,MAAM,EAgBhB;IAbA,uBAAoB;IACpB,qBAAqB;IACrB,KADW,MAAM,CACH;IACd,wBAAwB;IACxB,WADW,SAAS,CACM;IAC1B,YAAoB;IAEpB,oCAAoC;IACpC,KADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACnB;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