svedit 0.9.0 → 0.11.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 +476 -364
- package/dist/AnnotatedTextProperty.svelte +40 -10
- package/dist/AnnotatedTextProperty.svelte.d.ts.map +1 -1
- package/dist/Command.svelte.d.ts +0 -1
- package/dist/Command.svelte.d.ts.map +1 -1
- package/dist/Command.svelte.js +48 -6
- package/dist/CustomProperty.svelte +20 -9
- package/dist/CustomProperty.svelte.d.ts +2 -1
- package/dist/CustomProperty.svelte.d.ts.map +1 -1
- package/dist/Node.svelte +7 -5
- package/dist/Node.svelte.d.ts.map +1 -1
- package/dist/NodeArrayProperty.svelte +59 -48
- package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
- package/dist/NodeCaret.svelte +0 -7
- package/dist/NodeGap.svelte +208 -118
- package/dist/NodeGap.svelte.d.ts +0 -2
- package/dist/NodeGap.svelte.d.ts.map +1 -1
- package/dist/NodeGapMarkers.svelte +251 -84
- package/dist/NodeGapMarkers.svelte.d.ts +2 -0
- package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
- package/dist/NodeSelectionMarkers.svelte +4 -3
- package/dist/NodeSelectionMarkers.svelte.d.ts.map +1 -1
- package/dist/Session.svelte.d.ts +12 -1
- package/dist/Session.svelte.d.ts.map +1 -1
- package/dist/Session.svelte.js +40 -3
- package/dist/Svedit.svelte +496 -221
- package/dist/Svedit.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.d.ts +24 -5
- package/dist/Transaction.svelte.d.ts.map +1 -1
- package/dist/Transaction.svelte.js +103 -61
- package/dist/doc_utils.d.ts +69 -3
- package/dist/doc_utils.d.ts.map +1 -1
- package/dist/doc_utils.js +276 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -1
- package/dist/node_visibility.svelte.d.ts +9 -0
- package/dist/node_visibility.svelte.d.ts.map +1 -0
- package/dist/node_visibility.svelte.js +718 -0
- package/dist/paste_utils.d.ts +46 -0
- package/dist/paste_utils.d.ts.map +1 -0
- package/dist/paste_utils.js +167 -0
- package/dist/styles/svedit-animations.css +8 -0
- package/dist/styles/svedit-colors.css +1 -0
- package/dist/types.d.ts +46 -3
- package/dist/utils.d.ts +52 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +109 -3
- package/package.json +3 -2
- package/src/lib/AnnotatedTextProperty.svelte +40 -10
- package/src/lib/Command.svelte.js +48 -6
- package/src/lib/CustomProperty.svelte +20 -9
- package/src/lib/Node.svelte +7 -5
- package/src/lib/NodeArrayProperty.svelte +59 -48
- package/src/lib/NodeCaret.svelte +0 -7
- package/src/lib/NodeGap.svelte +208 -118
- package/src/lib/NodeGapMarkers.svelte +251 -84
- package/src/lib/NodeSelectionMarkers.svelte +4 -3
- package/src/lib/Session.svelte.js +40 -3
- package/src/lib/Svedit.svelte +496 -221
- package/src/lib/Transaction.svelte.js +103 -61
- package/src/lib/doc_utils.js +276 -10
- package/src/lib/index.js +6 -1
- package/src/lib/node_visibility.svelte.js +718 -0
- package/src/lib/paste_utils.js +167 -0
- package/src/lib/styles/svedit-animations.css +8 -0
- package/src/lib/styles/svedit-colors.css +1 -0
- package/src/lib/types.d.ts +46 -3
- package/src/lib/utils.js +109 -3
- package/dist/node_gap_computation.svelte.d.ts +0 -5
- package/dist/node_gap_computation.svelte.d.ts.map +0 -1
- package/dist/node_gap_computation.svelte.js +0 -621
- package/src/lib/node_gap_computation.svelte.js +0 -621
package/dist/Session.svelte.js
CHANGED
|
@@ -8,7 +8,9 @@ import {
|
|
|
8
8
|
apply_op,
|
|
9
9
|
count_references as doc_count_references,
|
|
10
10
|
validate_document_schema,
|
|
11
|
+
validate_document,
|
|
11
12
|
validate_node,
|
|
13
|
+
get_referencing_node_ids,
|
|
12
14
|
get_active_annotation,
|
|
13
15
|
validate_selection
|
|
14
16
|
} from './doc_utils.js';
|
|
@@ -63,6 +65,7 @@ export default class Session {
|
|
|
63
65
|
selected_node = $derived(this.get_selected_node());
|
|
64
66
|
available_annotation_types = $derived(this.get_available_annotation_types());
|
|
65
67
|
|
|
68
|
+
|
|
66
69
|
/**
|
|
67
70
|
* @param {DocumentSchema} schema - The document schema
|
|
68
71
|
* @param {Document} doc - The document
|
|
@@ -77,6 +80,7 @@ export default class Session {
|
|
|
77
80
|
this.schema = schema;
|
|
78
81
|
this.doc = doc;
|
|
79
82
|
this.config = config;
|
|
83
|
+
validate_document(this.doc, this.schema);
|
|
80
84
|
|
|
81
85
|
// Set selection after doc is initialized so validation can work properly
|
|
82
86
|
this.selection = options.selection ?? null;
|
|
@@ -119,9 +123,41 @@ export default class Session {
|
|
|
119
123
|
return this.doc.document_id;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
/**
|
|
127
|
+
* Validates the parts of a transaction result that can be affected by the transaction.
|
|
128
|
+
*
|
|
129
|
+
* This is intentionally narrower than full document validation. It validates all
|
|
130
|
+
* created/modified nodes, plus nodes that still reference created, modified, or
|
|
131
|
+
* deleted nodes. That catches local node invariants and dangling references left
|
|
132
|
+
* behind by deletes without scanning every node on every apply.
|
|
133
|
+
*
|
|
134
|
+
* @param {Transaction} transaction - The transaction result to validate
|
|
135
|
+
* @throws {Error} Throws if the transaction result is invalid
|
|
136
|
+
*/
|
|
137
|
+
validate_transaction_result(transaction) {
|
|
138
|
+
const doc = transaction.doc;
|
|
139
|
+
/** @type {NodeId[]} */
|
|
140
|
+
const affected_node_ids = [];
|
|
141
|
+
|
|
142
|
+
function add_node_id(node_id) {
|
|
143
|
+
if (!affected_node_ids.includes(node_id)) affected_node_ids.push(node_id);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
for (const node_id of transaction.created_node_ids) add_node_id(node_id);
|
|
147
|
+
for (const node_id of transaction.modified_node_ids) add_node_id(node_id);
|
|
148
|
+
for (const node_id of get_referencing_node_ids(this.schema, doc, transaction.created_node_ids)) {
|
|
149
|
+
add_node_id(node_id);
|
|
150
|
+
}
|
|
151
|
+
for (const node_id of get_referencing_node_ids(this.schema, doc, transaction.modified_node_ids)) {
|
|
152
|
+
add_node_id(node_id);
|
|
153
|
+
}
|
|
154
|
+
for (const node_id of get_referencing_node_ids(this.schema, doc, transaction.deleted_node_ids)) {
|
|
155
|
+
add_node_id(node_id);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
for (const node_id of affected_node_ids) {
|
|
159
|
+
const node = doc.nodes[node_id];
|
|
160
|
+
if (node) validate_node(node, this.schema, doc.nodes);
|
|
125
161
|
}
|
|
126
162
|
}
|
|
127
163
|
|
|
@@ -198,6 +234,7 @@ export default class Session {
|
|
|
198
234
|
* @param {boolean} [options.batch=false] - Whether to allow batching with previous transaction
|
|
199
235
|
*/
|
|
200
236
|
apply(transaction, { batch = false } = {}) {
|
|
237
|
+
this.validate_transaction_result(transaction);
|
|
201
238
|
this.doc = transaction.doc;
|
|
202
239
|
// Make sure selection gets a new reference (is rerendered)
|
|
203
240
|
this.selection = structuredClone(transaction.selection);
|