svedit 0.1.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/LICENSE +21 -0
- package/README.md +323 -0
- package/dist/AnnotatedStringProperty.svelte +126 -0
- package/dist/AnnotatedStringProperty.svelte.d.ts +7 -0
- package/dist/AnnotatedStringProperty.svelte.d.ts.map +1 -0
- package/dist/CustomProperty.svelte +40 -0
- package/dist/CustomProperty.svelte.d.ts +8 -0
- package/dist/CustomProperty.svelte.d.ts.map +1 -0
- package/dist/Document.svelte.d.ts +191 -0
- package/dist/Document.svelte.d.ts.map +1 -0
- package/dist/Document.svelte.js +681 -0
- package/dist/Node.svelte +41 -0
- package/dist/Node.svelte.d.ts +7 -0
- package/dist/Node.svelte.d.ts.map +1 -0
- package/dist/NodeArrayProperty.svelte +45 -0
- package/dist/NodeArrayProperty.svelte.d.ts +7 -0
- package/dist/NodeArrayProperty.svelte.d.ts.map +1 -0
- package/dist/Svedit.svelte +936 -0
- package/dist/Svedit.svelte.d.ts +12 -0
- package/dist/Svedit.svelte.d.ts.map +1 -0
- package/dist/Transaction.svelte.d.ts +198 -0
- package/dist/Transaction.svelte.d.ts.map +1 -0
- package/dist/Transaction.svelte.js +577 -0
- package/dist/UnknownNode.svelte +12 -0
- package/dist/UnknownNode.svelte.d.ts +12 -0
- package/dist/UnknownNode.svelte.d.ts.map +1 -0
- package/dist/commands.svelte.d.ts +5 -0
- package/dist/commands.svelte.d.ts.map +1 -0
- package/dist/commands.svelte.js +261 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/types.d.ts +264 -0
- package/dist/util.d.ts +4 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +78 -0
- package/package.json +65 -0
- package/src/lib/AnnotatedStringProperty.svelte +126 -0
- package/src/lib/CustomProperty.svelte +40 -0
- package/src/lib/Document.svelte.js +681 -0
- package/src/lib/Node.svelte +41 -0
- package/src/lib/NodeArrayProperty.svelte +45 -0
- package/src/lib/Svedit.svelte +936 -0
- package/src/lib/Transaction.svelte.js +577 -0
- package/src/lib/UnknownNode.svelte +12 -0
- package/src/lib/commands.svelte.js +261 -0
- package/src/lib/index.js +14 -0
- package/src/lib/types.d.ts +264 -0
- package/src/lib/util.js +78 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default Svedit;
|
|
2
|
+
type Svedit = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<SveditProps>): void;
|
|
5
|
+
} & {
|
|
6
|
+
focus_canvas: () => void;
|
|
7
|
+
};
|
|
8
|
+
declare const Svedit: import("svelte").Component<SveditProps, {
|
|
9
|
+
focus_canvas: () => void;
|
|
10
|
+
}, "">;
|
|
11
|
+
import type { SveditProps } from './types.d.ts';
|
|
12
|
+
//# sourceMappingURL=Svedit.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Svedit.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Svedit.svelte.js"],"names":[],"mappings":";;;;;;;AA64BA;;OAAqD;iCAj4BgE,cAAc"}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @import { NodeId, SerializedNode, Selection, DocumentPath } from './types.js'
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Transaction class for managing atomic document operations with undo/redo support.
|
|
6
|
+
*
|
|
7
|
+
* A Transaction provides a way to group multiple document operations (create, delete, set)
|
|
8
|
+
* into a single atomic unit that can be applied or rolled back as one. It maintains
|
|
9
|
+
* both forward operations and their inverse operations for undo functionality.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```js
|
|
13
|
+
* const tr = doc.tr;
|
|
14
|
+
* tr.set(['node_1', 'title'], 'New Title');
|
|
15
|
+
* tr.create({id: 'node_2', type: 'paragraph', content: 'Hello'});
|
|
16
|
+
* doc.apply(tr); // Applies all operations atomically
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export default class Transaction {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new Transaction for the given document.
|
|
22
|
+
*
|
|
23
|
+
* @param {any} doc - The document instance this transaction operates on
|
|
24
|
+
*/
|
|
25
|
+
constructor(doc: any);
|
|
26
|
+
doc: any;
|
|
27
|
+
/** @type {Record<string, any>[]} */
|
|
28
|
+
ops: Record<string, any>[];
|
|
29
|
+
/** @type {Record<string, any>[]} */
|
|
30
|
+
inverse_ops: Record<string, any>[];
|
|
31
|
+
selection_before: any;
|
|
32
|
+
/**
|
|
33
|
+
* Gets a value from the document at the specified path.
|
|
34
|
+
*
|
|
35
|
+
* @param {DocumentPath} path - The path to the value in the document
|
|
36
|
+
* @returns {any} The value at the specified path
|
|
37
|
+
*/
|
|
38
|
+
get(path: DocumentPath): any;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the current selection state of the document.
|
|
41
|
+
*
|
|
42
|
+
* @returns {Selection} The current selection object
|
|
43
|
+
*/
|
|
44
|
+
get selection(): Selection;
|
|
45
|
+
/**
|
|
46
|
+
* Sets a property of a node to a new value.
|
|
47
|
+
*
|
|
48
|
+
* This is the core operation for modifying document properties. It records
|
|
49
|
+
* both the forward operation and its inverse for undo support.
|
|
50
|
+
*
|
|
51
|
+
* @param {DocumentPath} path - Array path to the property (e.g., ["node_1", "title"])
|
|
52
|
+
* @param {any} value - The new value to set
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```js
|
|
56
|
+
* tr.set(["list_1", "list_items"], [1, 2, 3]);
|
|
57
|
+
* tr.set(["page_1", "body", "0", "description"], ["Hello world", []]);
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
set(path: DocumentPath, value: any): void;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a new node in the document.
|
|
63
|
+
*
|
|
64
|
+
* The node must have a valid id and must not already exist in the document.
|
|
65
|
+
* The node is validated against the document schema before creation.
|
|
66
|
+
*
|
|
67
|
+
* @param {any} node - The node object to create (must include id, type, and other properties)
|
|
68
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
69
|
+
* @throws {Error} If the node ID is invalid or if the node already exists
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```js
|
|
73
|
+
* tr.create({
|
|
74
|
+
* id: 'para_123',
|
|
75
|
+
* type: 'paragraph',
|
|
76
|
+
* content: ['Hello world', []]
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
create(node: any): Transaction;
|
|
81
|
+
/**
|
|
82
|
+
* Deletes a node from the document by its ID.
|
|
83
|
+
*
|
|
84
|
+
* The node's current state is captured for undo support before deletion.
|
|
85
|
+
*
|
|
86
|
+
* @param {any} id - The ID of the node to delete
|
|
87
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```js
|
|
91
|
+
* tr.delete('node_123');
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
delete(id: any): Transaction;
|
|
95
|
+
/**
|
|
96
|
+
* Sets the document selection.
|
|
97
|
+
*
|
|
98
|
+
* @param {Selection} selection - The new selection object
|
|
99
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
100
|
+
* @todo Check if selection is valid and throw error if not
|
|
101
|
+
*/
|
|
102
|
+
set_selection(selection: Selection): Transaction;
|
|
103
|
+
/**
|
|
104
|
+
* Adds, updates, or removes text annotations in the current selection.
|
|
105
|
+
*
|
|
106
|
+
* Handles various annotation scenarios including adding new annotations,
|
|
107
|
+
* updating existing ones (especially for links), and removing annotations
|
|
108
|
+
* when conflicting types are applied.
|
|
109
|
+
*
|
|
110
|
+
* @param {any} annotation_type - The type of annotation (e.g., 'link', 'bold', 'italic')
|
|
111
|
+
* @param {any} annotation_data - Additional data for the annotation (e.g., href for links)
|
|
112
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```js
|
|
116
|
+
* // Add a link annotation
|
|
117
|
+
* tr.annotate_text('link', { href: 'https://example.com' });
|
|
118
|
+
*
|
|
119
|
+
* // Add emphasis
|
|
120
|
+
* tr.annotate_text('emphasis', {});
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
annotate_text(annotation_type: any, annotation_data: any): Transaction;
|
|
124
|
+
/**
|
|
125
|
+
* Deletes the currently selected text or nodes.
|
|
126
|
+
*
|
|
127
|
+
* Behavior depends on selection type:
|
|
128
|
+
* - For node selections: Removes selected nodes and cascades deletion of unreferenced nodes
|
|
129
|
+
* - For text selections: Removes selected text and adjusts annotations accordingly
|
|
130
|
+
* - For collapsed selections: Deletes the previous character/node
|
|
131
|
+
*
|
|
132
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
133
|
+
*/
|
|
134
|
+
delete_selection(): Transaction;
|
|
135
|
+
/**
|
|
136
|
+
* Inserts an array of nodes at the current node selection.
|
|
137
|
+
*
|
|
138
|
+
* If there's a current selection, it will be deleted first. New nodes are
|
|
139
|
+
* created if they don't already exist (e.g., for cut+paste scenarios).
|
|
140
|
+
*
|
|
141
|
+
* @param {SerializedNode[]} nodes - Array of node objects to insert
|
|
142
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
143
|
+
*
|
|
144
|
+
* @note Assumes we only insert new nodes, not reference existing ones
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```js
|
|
148
|
+
* tr.insert_nodes([
|
|
149
|
+
* {id: 'para_1', type: 'paragraph', content: ['Hello', []]},
|
|
150
|
+
* {id: 'para_2', type: 'paragraph', content: ['World', []]}
|
|
151
|
+
* ]);
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
insert_nodes(nodes: SerializedNode[]): Transaction;
|
|
155
|
+
/**
|
|
156
|
+
* Inserts text at the current text selection, replacing any selected content.
|
|
157
|
+
*
|
|
158
|
+
* Updates both the text content and adjusts annotation offsets to maintain
|
|
159
|
+
* annotation integrity after the text insertion.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} replaced_text - The text to insert
|
|
162
|
+
* @returns {Transaction} This transaction instance for method chaining
|
|
163
|
+
*
|
|
164
|
+
* @todo Support annotations attached to replaced_text for full copy&paste support
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```js
|
|
168
|
+
* tr.insert_text('Hello, world!');
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
insert_text(replaced_text: string): Transaction;
|
|
172
|
+
/**
|
|
173
|
+
* Recursively deletes nodes that become unreferenced after the initial deletion.
|
|
174
|
+
*
|
|
175
|
+
* This method implements cascade deletion by checking reference counts and
|
|
176
|
+
* removing nodes that are no longer referenced by any other nodes in the document.
|
|
177
|
+
*
|
|
178
|
+
* @param {NodeId[]} removed_node_ids - Array of node IDs that were initially removed
|
|
179
|
+
* @private
|
|
180
|
+
*/
|
|
181
|
+
private _cascade_delete_unreferenced_nodes;
|
|
182
|
+
/**
|
|
183
|
+
* Counts references to a target node, excluding nodes that are marked for deletion.
|
|
184
|
+
*
|
|
185
|
+
* This is used during cascade deletion to determine if a node can be safely
|
|
186
|
+
* deleted without breaking document integrity.
|
|
187
|
+
*
|
|
188
|
+
* @param {NodeId} target_node_id - The node ID to count references for
|
|
189
|
+
* @param {Record<NodeId, boolean>} nodes_to_delete - Nodes already marked for deletion
|
|
190
|
+
* @returns {number} The number of references to the target node
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
193
|
+
private _count_references_excluding_deleted;
|
|
194
|
+
}
|
|
195
|
+
import type { DocumentPath } from './types.js';
|
|
196
|
+
import type { Selection } from './types.js';
|
|
197
|
+
import type { SerializedNode } from './types.js';
|
|
198
|
+
//# sourceMappingURL=Transaction.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Transaction.svelte.js"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;;;;;GAcG;AACH;IACE;;;;OAIG;IACH,iBAFW,GAAG,EAWb;IARC,SAAc;IAEd,oCAAoC;IACpC,KADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACnB;IACb,oCAAoC;IACpC,aADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACX;IAErB,sBAA0C;IAG5C;;;;;OAKG;IACH,UAHW,YAAY,GACV,GAAG,CAIf;IAED;;;;OAIG;IACH,iBAFa,SAAS,CAIrB;IAED;;;;;;;;;;;;;;OAcG;IACH,UATW,YAAY,SACZ,GAAG,QA2Bb;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,aAbW,GAAG,GACD,WAAW,CAyBvB;IAED;;;;;;;;;;;;OAYG;IACH,WARW,GAAG,GACD,WAAW,CAcvB;IAED;;;;;;OAMG;IACH,yBAJW,SAAS,GACP,WAAW,CAOvB;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,+BAbW,GAAG,mBACH,GAAG,GACD,WAAW,CAqFvB;IAED;;;;;;;;;OASG;IACH,oBAFa,WAAW,CA8FvB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,oBAbW,cAAc,EAAE,GACd,WAAW,CAqDvB;IAED;;;;;;;;;;;;;;;OAeG;IACH,2BAVW,MAAM,GACJ,WAAW,CAsEvB;IAED;;;;;;;;OAQG;IACH,2CA+BC;IAED;;;;;;;;;;OAUG;IACH,4CAqBC;CACF;kCA/jBmE,YAAY;+BAAZ,YAAY;oCAAZ,YAAY"}
|