svedit 0.9.0 → 0.10.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 (68) hide show
  1. package/README.md +113 -4
  2. package/dist/AnnotatedTextProperty.svelte +41 -8
  3. package/dist/AnnotatedTextProperty.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.d.ts +0 -1
  5. package/dist/Command.svelte.d.ts.map +1 -1
  6. package/dist/Command.svelte.js +18 -3
  7. package/dist/CustomProperty.svelte +20 -9
  8. package/dist/CustomProperty.svelte.d.ts +2 -1
  9. package/dist/CustomProperty.svelte.d.ts.map +1 -1
  10. package/dist/Node.svelte +7 -5
  11. package/dist/Node.svelte.d.ts.map +1 -1
  12. package/dist/NodeArrayProperty.svelte +65 -42
  13. package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
  14. package/dist/NodeCaret.svelte +0 -7
  15. package/dist/NodeGap.svelte +179 -81
  16. package/dist/NodeGap.svelte.d.ts +0 -2
  17. package/dist/NodeGap.svelte.d.ts.map +1 -1
  18. package/dist/NodeGapMarkers.svelte +251 -84
  19. package/dist/NodeGapMarkers.svelte.d.ts +2 -0
  20. package/dist/NodeGapMarkers.svelte.d.ts.map +1 -1
  21. package/dist/NodeSelectionMarkers.svelte +4 -3
  22. package/dist/NodeSelectionMarkers.svelte.d.ts.map +1 -1
  23. package/dist/Session.svelte.d.ts +12 -1
  24. package/dist/Session.svelte.d.ts.map +1 -1
  25. package/dist/Session.svelte.js +40 -3
  26. package/dist/Svedit.svelte +336 -165
  27. package/dist/Svedit.svelte.d.ts.map +1 -1
  28. package/dist/Transaction.svelte.d.ts +24 -5
  29. package/dist/Transaction.svelte.d.ts.map +1 -1
  30. package/dist/Transaction.svelte.js +103 -61
  31. package/dist/doc_utils.d.ts +64 -3
  32. package/dist/doc_utils.d.ts.map +1 -1
  33. package/dist/doc_utils.js +276 -10
  34. package/dist/index.d.ts +1 -1
  35. package/dist/index.js +5 -1
  36. package/dist/node_visibility.svelte.d.ts +9 -0
  37. package/dist/node_visibility.svelte.d.ts.map +1 -0
  38. package/dist/node_visibility.svelte.js +718 -0
  39. package/dist/styles/svedit-animations.css +8 -0
  40. package/dist/styles/svedit-colors.css +1 -0
  41. package/dist/types.d.ts +46 -3
  42. package/dist/utils.d.ts +52 -0
  43. package/dist/utils.d.ts.map +1 -1
  44. package/dist/utils.js +109 -3
  45. package/package.json +3 -2
  46. package/src/lib/AnnotatedTextProperty.svelte +41 -8
  47. package/src/lib/Command.svelte.js +18 -3
  48. package/src/lib/CustomProperty.svelte +20 -9
  49. package/src/lib/Node.svelte +7 -5
  50. package/src/lib/NodeArrayProperty.svelte +65 -42
  51. package/src/lib/NodeCaret.svelte +0 -7
  52. package/src/lib/NodeGap.svelte +179 -81
  53. package/src/lib/NodeGapMarkers.svelte +251 -84
  54. package/src/lib/NodeSelectionMarkers.svelte +4 -3
  55. package/src/lib/Session.svelte.js +40 -3
  56. package/src/lib/Svedit.svelte +336 -165
  57. package/src/lib/Transaction.svelte.js +103 -61
  58. package/src/lib/doc_utils.js +276 -10
  59. package/src/lib/index.js +5 -1
  60. package/src/lib/node_visibility.svelte.js +718 -0
  61. package/src/lib/styles/svedit-animations.css +8 -0
  62. package/src/lib/styles/svedit-colors.css +1 -0
  63. package/src/lib/types.d.ts +46 -3
  64. package/src/lib/utils.js +109 -3
  65. package/dist/node_gap_computation.svelte.d.ts +0 -5
  66. package/dist/node_gap_computation.svelte.d.ts.map +0 -1
  67. package/dist/node_gap_computation.svelte.js +0 -621
  68. package/src/lib/node_gap_computation.svelte.js +0 -621
@@ -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
- validate_doc() {
123
- for (const node of Object.values(this.doc.nodes)) {
124
- validate_node(node, this.schema, this.doc.nodes);
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);