svedit 0.11.1 → 0.12.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 (56) hide show
  1. package/README.md +230 -64
  2. package/dist/Command.svelte.d.ts +21 -4
  3. package/dist/Command.svelte.d.ts.map +1 -1
  4. package/dist/Command.svelte.js +85 -27
  5. package/dist/Node.svelte +29 -1
  6. package/dist/Node.svelte.d.ts.map +1 -1
  7. package/dist/NodeArrayProperty.svelte +119 -12
  8. package/dist/NodeArrayProperty.svelte.d.ts.map +1 -1
  9. package/dist/NodeGap.svelte +48 -6
  10. package/dist/NodeGap.svelte.d.ts.map +1 -1
  11. package/dist/Session.svelte.d.ts +31 -14
  12. package/dist/Session.svelte.d.ts.map +1 -1
  13. package/dist/Session.svelte.js +155 -77
  14. package/dist/Svedit.svelte +110 -89
  15. package/dist/Svedit.svelte.d.ts.map +1 -1
  16. package/dist/{AnnotatedTextProperty.svelte → TextProperty.svelte} +45 -44
  17. package/dist/TextProperty.svelte.d.ts +7 -0
  18. package/dist/TextProperty.svelte.d.ts.map +1 -0
  19. package/dist/Transaction.svelte.d.ts +78 -40
  20. package/dist/Transaction.svelte.d.ts.map +1 -1
  21. package/dist/Transaction.svelte.js +412 -234
  22. package/dist/doc_utils.d.ts +96 -21
  23. package/dist/doc_utils.d.ts.map +1 -1
  24. package/dist/doc_utils.js +440 -168
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -1
  27. package/dist/node_visibility.svelte.d.ts +30 -4
  28. package/dist/node_visibility.svelte.d.ts.map +1 -1
  29. package/dist/node_visibility.svelte.js +327 -363
  30. package/dist/paste_utils.d.ts +3 -2
  31. package/dist/paste_utils.d.ts.map +1 -1
  32. package/dist/paste_utils.js +16 -13
  33. package/dist/transforms.svelte.d.ts.map +1 -1
  34. package/dist/transforms.svelte.js +5 -6
  35. package/dist/types.d.ts +112 -42
  36. package/dist/utils.d.ts +75 -12
  37. package/dist/utils.d.ts.map +1 -1
  38. package/dist/utils.js +292 -78
  39. package/package.json +4 -1
  40. package/src/lib/Command.svelte.js +85 -27
  41. package/src/lib/Node.svelte +29 -1
  42. package/src/lib/NodeArrayProperty.svelte +119 -12
  43. package/src/lib/NodeGap.svelte +48 -6
  44. package/src/lib/Session.svelte.js +155 -77
  45. package/src/lib/Svedit.svelte +110 -89
  46. package/src/lib/{AnnotatedTextProperty.svelte → TextProperty.svelte} +45 -44
  47. package/src/lib/Transaction.svelte.js +412 -234
  48. package/src/lib/doc_utils.js +440 -168
  49. package/src/lib/index.js +1 -1
  50. package/src/lib/node_visibility.svelte.js +327 -363
  51. package/src/lib/paste_utils.js +16 -13
  52. package/src/lib/transforms.svelte.js +5 -6
  53. package/src/lib/types.d.ts +112 -42
  54. package/src/lib/utils.js +292 -78
  55. package/dist/AnnotatedTextProperty.svelte.d.ts +0 -7
  56. package/dist/AnnotatedTextProperty.svelte.d.ts.map +0 -1
@@ -40,6 +40,7 @@ export default class Transaction {
40
40
  modified_node_ids: NodeId[];
41
41
  /** @type {NodeId[]} */
42
42
  deleted_node_ids: NodeId[];
43
+ changed_node_types: boolean;
43
44
  /**
44
45
  * Gets a value from the document at the specified path.
45
46
  *
@@ -56,12 +57,12 @@ export default class Transaction {
56
57
  */
57
58
  property_type(type: string, property: string): string;
58
59
  /**
59
- * Determines the kind of a node ('block', 'text', or 'annotation').
60
+ * Determines the kind of a node ('block', 'text', 'mark', or 'annotation').
60
61
  *
61
62
  * @param {any} node - The node to check
62
- * @returns {'block'|'text'|'annotation'} The node kind
63
+ * @returns {'block'|'text'|'mark'|'annotation'} The node kind
63
64
  */
64
- kind(node: any): "block" | "text" | "annotation";
65
+ kind(node: any): "block" | "text" | "mark" | "annotation";
65
66
  /**
66
67
  * Inspects a path to get metadata about the value at that location.
67
68
  *
@@ -92,6 +93,12 @@ export default class Transaction {
92
93
  * @returns {NodeId[]} Array of referenced node IDs
93
94
  */
94
95
  get_referenced_nodes(node_id: NodeId): NodeId[];
96
+ /**
97
+ * Gets the available mark types for the current selection.
98
+ *
99
+ * @returns {string[]} Array of available mark type names
100
+ */
101
+ get available_mark_types(): string[];
95
102
  /**
96
103
  * Gets the available annotation types for the current selection.
97
104
  *
@@ -99,13 +106,31 @@ export default class Transaction {
99
106
  */
100
107
  get available_annotation_types(): string[];
101
108
  /**
102
- * Returns the annotation object that is currently "under the caret".
103
- * NOTE: Annotations in Svedit are exclusive, so there can only be one active_annotation
109
+ * Returns marks touched by the current selection.
104
110
  *
105
- * @param {string} [annotation_type] Optional annotation type to filter by
106
- * @returns {Annotation|null}
111
+ * @returns {Array<Mark & { index: number, node: any }>}
107
112
  */
108
- active_annotation(annotation_type?: string): Annotation | null;
113
+ get selected_marks(): Array<Mark & {
114
+ index: number;
115
+ node: any;
116
+ }>;
117
+ get active_mark(): Attachment & {
118
+ index: number;
119
+ node: any;
120
+ };
121
+ /**
122
+ * Returns annotations touched by the current selection.
123
+ *
124
+ * @returns {Array<Annotation & { index: number, node: any }>}
125
+ */
126
+ get selected_annotations(): Array<Annotation & {
127
+ index: number;
128
+ node: any;
129
+ }>;
130
+ get active_annotation(): Attachment & {
131
+ index: number;
132
+ node: any;
133
+ };
109
134
  /**
110
135
  * Applies an operation to the document (internal).
111
136
  *
@@ -132,7 +157,7 @@ export default class Transaction {
132
157
  * @example
133
158
  * ```js
134
159
  * tr.set(["list_1", "list_items"], [1, 2, 3]);
135
- * tr.set(["page_1", "body", "0", "description"], {text: "Hello world", annotations: []});
160
+ * tr.set(["page_1", "body", "0", "description"], {content: "Hello world", marks: [], annotations: []});
136
161
  * ```
137
162
  */
138
163
  set(path: DocumentPath, value: any): Transaction;
@@ -164,7 +189,7 @@ export default class Transaction {
164
189
  *
165
190
  * NOTE: This is a force-delete and intentionally does NOT check whether
166
191
  * the node is still referenced from elsewhere — callers (e.g.
167
- * `annotate_text`) sometimes need to remove a node while a stale
192
+ * `toggle_mark`) sometimes need to remove a node while a stale
168
193
  * reference to it still exists in the property they are about to update.
169
194
  * For ref-count-aware cleanup, see how `set` calls
170
195
  * `_cascade_delete_unreferenced_nodes`.
@@ -195,26 +220,45 @@ export default class Transaction {
195
220
  */
196
221
  private _validate_selection;
197
222
  /**
198
- * Adds, updates, or removes text annotations in the current selection.
223
+ * Toggles a mark on the current text or node selection.
199
224
  *
200
- * Handles various annotation scenarios including adding new annotations,
201
- * updating existing ones (especially for links), and removing annotations
202
- * when conflicting types are applied.
225
+ * Marks are mutually exclusive. Whole marks are toggled, removed, or
226
+ * switched; ranges are never truncated or expanded by this command.
203
227
  *
204
- * @param {any} annotation_type - The type of annotation (e.g., 'link', 'bold', 'italic')
205
- * @param {any} annotation_properties - Additional data for the annotation (e.g., href for links)
228
+ * @param {any} mark_type - The type of mark (e.g., 'link', 'strong', 'emphasis')
229
+ * @param {any} mark_properties - Additional data for the mark (e.g., href for links)
206
230
  * @returns {Transaction} This transaction instance for method chaining
207
231
  *
208
232
  * @example
209
233
  * ```js
210
- * // Add a link annotation
211
- * tr.annotate_text('link', { href: 'https://example.com' });
234
+ * // Add a link mark
235
+ * tr.toggle_mark('link', { href: 'https://example.com' });
212
236
  *
213
237
  * // Add emphasis
214
- * tr.annotate_text('emphasis', {});
238
+ * tr.toggle_mark('emphasis', {});
239
+ * ```
240
+ */
241
+ toggle_mark(mark_type: any, mark_properties: any): Transaction;
242
+ /**
243
+ * Toggles an annotation on the current text or node selection.
244
+ *
245
+ * Annotations only compete with touched annotations of the same type:
246
+ * touched same-type annotations are removed, otherwise a new annotation is
247
+ * created. Marks and other annotation types never block a toggle, and
248
+ * same-type annotations may still overlap when created through lower-level
249
+ * APIs.
250
+ *
251
+ * @param {any} annotation_type - The type of annotation (e.g., 'comment', 'marker')
252
+ * @param {any} annotation_properties - Additional data for the annotation
253
+ * @returns {Transaction} This transaction instance for method chaining
254
+ *
255
+ * @example
256
+ * ```js
257
+ * // Add a comment annotation
258
+ * tr.toggle_annotation('comment', { text: 'Please review' });
215
259
  * ```
216
260
  */
217
- annotate_text(annotation_type: any, annotation_properties: any): Transaction;
261
+ toggle_annotation(annotation_type: any, annotation_properties: any): Transaction;
218
262
  /**
219
263
  * Deletes the currently selected text, node, or property.
220
264
  *
@@ -235,23 +279,27 @@ export default class Transaction {
235
279
  * before inserting the new ones.
236
280
  *
237
281
  * @param {NodeId[]} node_ids - Array of node IDs to insert
282
+ * @param {Array<Mark>} [marks] - Selection-relative marks to restore
283
+ * @param {Array<Annotation>} [annotations] - Selection-relative annotations to restore
284
+ * @param {Record<NodeId, any>} [nodes] - Node graph for restored marks and annotations
238
285
  * @returns {Transaction} This transaction instance for method chaining
239
286
  */
240
- insert_nodes(node_ids: NodeId[]): Transaction;
287
+ insert_nodes(node_ids: NodeId[], marks?: Array<Mark>, annotations?: Array<Annotation>, nodes?: Record<NodeId, any>): Transaction;
241
288
  /**
242
289
  * Inserts text at the current text selection position.
243
290
  *
244
- * Handles annotation adjustments when text is inserted, including:
245
- * - Expanding annotations that contain the insertion point
246
- * - Shifting annotations that come after the insertion point
247
- * - Optionally applying new annotations to the inserted text
291
+ * Handles mark and annotation adjustments when text is inserted, including:
292
+ * - Expanding ranges that contain the insertion point
293
+ * - Shifting ranges that come after the insertion point
294
+ * - Optionally applying new marks and annotations to the inserted text
248
295
  *
249
296
  * @param {string} replaced_text - The text to insert
250
- * @param {Array} [annotations] - Optional annotations to apply to the inserted text
251
- * @param {object} [nodes] - Optional node definitions for annotation nodes
297
+ * @param {Array<Mark>} [marks] - Optional marks to apply to the inserted text
298
+ * @param {Array<Annotation>} [annotations] - Optional annotations to apply to the inserted text
299
+ * @param {object} [nodes] - Optional node definitions for mark and annotation nodes
252
300
  * @returns {Transaction} This transaction instance for method chaining
253
301
  */
254
- insert_text(replaced_text: string, annotations?: any[], nodes?: object): Transaction;
302
+ insert_text(replaced_text: string, marks?: Array<Mark>, annotations?: Array<Annotation>, nodes?: object): Transaction;
255
303
  /**
256
304
  * Recursively deletes nodes that are no longer referenced in the document.
257
305
  *
@@ -263,23 +311,13 @@ export default class Transaction {
263
311
  * @private
264
312
  */
265
313
  private _cascade_delete_unreferenced_nodes;
266
- /**
267
- * Counts references to a node, excluding nodes that have been marked for deletion.
268
- *
269
- * This is used during cascade deletion to accurately count remaining references
270
- * as nodes are being deleted.
271
- *
272
- * @param {NodeId} target_node_id - The node ID to count references for
273
- * @param {Record<NodeId, boolean>} nodes_to_delete - Nodes already marked for deletion
274
- * @returns {number} The number of references to the target node
275
- * @private
276
- */
277
- private _count_references_excluding_deleted;
278
314
  }
279
315
  import type { DocumentSchema } from './types.d.js';
280
316
  import type { Selection } from './types.d.js';
281
317
  import type { NodeId } from './types.d.js';
282
318
  import type { DocumentPath } from './types.d.js';
319
+ import type { Mark } from './types.d.js';
320
+ import type { Attachment } from './types.d.js';
283
321
  import type { Annotation } from './types.d.js';
284
322
  import type { Document } from './types.d.js';
285
323
  //# 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":"AA0BA;;;;;;;;;;;;;;GAcG;AACH;IACC;;;;;;;OAOG;IACH,oBALW,cAAc,OACd,QAAQ,aACR,SAAS,GAAG,IAAI,UAChB,MAAM,EAuBhB;IApBA,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;IACb,oCAAoC;IACpC,aADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACX;IAErB,4BAAiC;IAEjC,uBAAuB;IACvB,kBADW,MAAM,EAAE,CACO;IAC1B,uBAAuB;IACvB,mBADW,MAAM,EAAE,CACQ;IAC3B,uBAAuB;IACvB,kBADW,MAAM,EAAE,CACO;IAG3B;;;;;OAKG;IACH,UAHW,YAAY,GAAC,MAAM,GACjB,GAAG,C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;;;;;;;OAUG;IACH,4CAOC;CACD;oCA50ByF,cAAc;+BAAd,cAAc;4BAAd,cAAc;kCAAd,cAAc;gCAAd,cAAc;8BAAd,cAAc"}
1
+ {"version":3,"file":"Transaction.svelte.d.ts","sourceRoot":"","sources":["../src/lib/Transaction.svelte.js"],"names":[],"mappings":"AAoDA;;;;;;;;;;;;;;GAcG;AACH;IACC;;;;;;;OAOG;IACH,oBALW,cAAc,OACd,QAAQ,aACR,SAAS,GAAG,IAAI,UAChB,MAAM,EA+BhB;IA5BA,uBAAoB;IAMpB,qBAAqB;IACrB,KADW,MAAM,CACoB;IACrC,wBAAwB;IACxB,WADW,SAAS,CACM;IAC1B,YAAoB;IAEpB,oCAAoC;IACpC,KADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACnB;IACb,oCAAoC;IACpC,aADW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CACX;IAErB,4BAAiC;IAEjC,uBAAuB;IACvB,kBADW,MAAM,EAAE,CACO;IAC1B,uBAAuB;IACvB,mBADW,MAAM,EAAE,CACQ;IAC3B,uBAAuB;IACvB,kBADW,MAAM,EAAE,CACO;IAG1B,4BAA+B;IAGhC;;;;;OAKG;IACH,UAHW,YAAY,GAAC,MAAM,GACjB,GAAG,CAIf;IAED;;;;;;OAMG;IACH,oBAJW,MAAM,YACN,MAAM,GACJ,MAAM,CAIlB;IAED;;;;;OAKG;IACH,WAHW,GAAG,GACD,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,YAAY,CAI9C;IAED;;;;;OAKG;IACH,cAHW,YAAY,GACV;QAAC,IAAI,EAAE,UAAU,GAAC,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,CAIzD;IAED;;;;OAIG;IACH,eAFa,MAAM,CAUlB;IAED;;;;;OAKG;IACH,oBAHW,GAAG,QAKb;IAED;;;;;OAKG;IACH,8BAHW,MAAM,GACJ,MAAM,EAAE,CAIpB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