lib0 1.0.0-rc.15 → 1.0.0-rc.17

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 (44) hide show
  1. package/dist/delta/delta.d.ts +274 -23
  2. package/dist/delta/position.d.ts +65 -0
  3. package/dist/delta/rdt/delta.d.ts +17 -8
  4. package/dist/delta/rdt/dom.d.ts +37 -8
  5. package/dist/delta/rdt.d.ts +100 -0
  6. package/dist/delta/transformer/{query.d.ts → attr.d.ts} +21 -17
  7. package/dist/delta/transformer/children.d.ts +21 -16
  8. package/dist/delta/transformer/conform.d.ts +83 -0
  9. package/dist/delta/transformer/core.d.ts +138 -33
  10. package/dist/delta/transformer/id.d.ts +1 -8
  11. package/dist/delta/transformer/inline.d.ts +20 -21
  12. package/dist/delta/transformer/pipe.d.ts +161 -250
  13. package/dist/delta/transformer/project.d.ts +223 -0
  14. package/dist/delta/transformer/rename-attrs.d.ts +75 -0
  15. package/dist/delta/transformer/rename.d.ts +30 -40
  16. package/dist/delta/transformer/value.d.ts +92 -0
  17. package/dist/delta/transformer.d.ts +5 -8
  18. package/dist/environment.d.ts +5 -0
  19. package/package.json +25 -11
  20. package/src/delta/delta.js +1171 -196
  21. package/src/delta/position.js +165 -0
  22. package/src/delta/rdt/delta.js +41 -17
  23. package/src/delta/rdt/dom.js +120 -138
  24. package/src/delta/rdt.js +194 -0
  25. package/src/delta/transformer/attr.js +126 -0
  26. package/src/delta/transformer/children.js +57 -45
  27. package/src/delta/transformer/conform.js +401 -0
  28. package/src/delta/transformer/core.js +188 -39
  29. package/src/delta/transformer/id.js +9 -6
  30. package/src/delta/transformer/inline.js +165 -24
  31. package/src/delta/transformer/pipe.js +181 -147
  32. package/src/delta/transformer/project.js +526 -0
  33. package/src/delta/transformer/rename-attrs.js +152 -0
  34. package/src/delta/transformer/rename.js +58 -73
  35. package/src/delta/transformer/value.js +214 -0
  36. package/src/delta/transformer.js +11 -14
  37. package/src/environment.js +7 -0
  38. package/dist/delta/binding.d.ts +0 -69
  39. package/dist/delta/transformer/filter.d.ts +0 -103
  40. package/dist/delta/transformer/projection.d.ts +0 -33
  41. package/src/delta/binding.js +0 -113
  42. package/src/delta/transformer/filter.js +0 -104
  43. package/src/delta/transformer/projection.js +0 -89
  44. package/src/delta/transformer/query.js +0 -110
@@ -15,19 +15,24 @@ export const $attribution: s.Schema<Attribution>;
15
15
  /**
16
16
  * @typedef {{ [key: string]: any }} FormattingAttributes
17
17
  */
18
+ /**
19
+ * @typedef {{ id: string, key: number|string, assoc: 1|-1, attrs?: object }} MarkJSON
20
+ */
18
21
  /**
19
22
  * @typedef {{
20
23
  * type: 'delta',
21
24
  * name?: string,
22
25
  * attrs?: { [Key in string|number]: DeltaAttrOpJSON },
23
- * children?: Array<DeltaListOpJSON>
26
+ * children?: Array<DeltaListOpJSON>,
27
+ * marks?: Array<MarkJSON>,
28
+ * deleteMarks?: Array<string>
24
29
  * }} DeltaJSON
25
30
  */
26
31
  /**
27
32
  * @typedef {{ type: 'insert', insert: string|Array<any>, format?: { [key: string]: any }, attribution?: Attribution } | { delete: number } | { type: 'retain', retain: number, format?: { [key:string]: any }, attribution?: Attribution } | { type: 'modify', value: object }} DeltaListOpJSON
28
33
  */
29
34
  /**
30
- * @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify', value: DeltaJSON }} DeltaAttrOpJSON
35
+ * @typedef {{ type: 'insert', value: any, prevValue?: any, attribution?: Attribution } | { type: 'delete', prevValue?: any, attribution?: Attribution } | { type: 'modify', value: DeltaJSON, attribution?: Attribution }} DeltaAttrOpJSON
31
36
  */
32
37
  /**
33
38
  * @typedef {TextOp|InsertOp<any>|DeleteOp|RetainOp|ModifyOp<any>} ChildrenOpAny
@@ -57,6 +62,8 @@ export const $deltaMapChangeJson: s.Schema<DeltaAttrOpJSON>;
57
62
  * fingerprint read (and any `diff` / equality check that relies on it) is
58
63
  * wrong. Fields covered: insert, delete, retain, format, attribution,
59
64
  * value, key.
65
+ *
66
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
60
67
  */
61
68
  export class TextOp extends list.ListNode {
62
69
  /**
@@ -102,9 +109,13 @@ export class TextOp extends list.ListNode {
102
109
  */
103
110
  toJSON(): DeltaListOpJSON;
104
111
  /**
112
+ * @param {number} [start]
113
+ * @param {number} [end]
114
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (text
115
+ * holds no nested deltas to freeze).
105
116
  * @return {TextOp}
106
117
  */
107
- clone(start?: number, end?: number): TextOp;
118
+ clone(start?: number, end?: number, _markAsDone?: boolean): TextOp;
108
119
  $type: s.Schema<TextOp>;
109
120
  /**
110
121
  * @param {TextOp} other
@@ -113,6 +124,7 @@ export class TextOp extends list.ListNode {
113
124
  }
114
125
  /**
115
126
  * @template {any} ArrayContent
127
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
116
128
  */
117
129
  export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
118
130
  /**
@@ -167,9 +179,15 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
167
179
  */
168
180
  toJSON(): DeltaListOpJSON;
169
181
  /**
182
+ * @param {number} [start]
183
+ * @param {number} [end]
184
+ * @param {boolean} [markAsDone] freeze the cloned child deltas (the default — a shared clone must be
185
+ * immutable). Pass `false` only when the caller is the SOLE owner of the cloned range (a *move*, e.g.
186
+ * `splitHere` which `_splice`s the range out of the source), so the content can stay mutable and is
187
+ * not re-cloned on the next modify (see {@link modValue}).
170
188
  * @return {InsertOp<ArrayContent>}
171
189
  */
172
- clone(start?: number, end?: number): InsertOp<ArrayContent>;
190
+ clone(start?: number, end?: number, markAsDone?: boolean): InsertOp<ArrayContent>;
173
191
  $type: s.Schema<InsertOp<any>>;
174
192
  /**
175
193
  * @param {InsertOp<ArrayContent>} other
@@ -178,6 +196,7 @@ export class InsertOp<ArrayContent extends unknown> extends list.ListNode {
178
196
  }
179
197
  /**
180
198
  * @template {DeltaConf} [Conf={}]
199
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
181
200
  */
182
201
  export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
183
202
  /**
@@ -209,17 +228,22 @@ export class DeleteOp<Conf extends DeltaConf = {}> extends list.ListNode {
209
228
  */
210
229
  toJSON(): DeltaListOpJSON;
211
230
  /**
212
- * @param {number} start
213
- * @param {number} end
231
+ * @param {number} [start]
232
+ * @param {number} [end]
233
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (a
234
+ * cloned delete carries no prevValue).
214
235
  * @return {DeleteOp}
215
236
  */
216
- clone(start?: number, end?: number): DeleteOp;
237
+ clone(start?: number, end?: number, _markAsDone?: boolean): DeleteOp;
217
238
  $type: s.Schema<DeleteOp<any>>;
218
239
  /**
219
240
  * @param {DeleteOp} other
220
241
  */
221
242
  [equalityTrait.EqualityTraitSymbol](other: DeleteOp): boolean;
222
243
  }
244
+ /**
245
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
246
+ */
223
247
  export class RetainOp extends list.ListNode {
224
248
  /**
225
249
  * @param {number} retain
@@ -263,7 +287,14 @@ export class RetainOp extends list.ListNode {
263
287
  * @return {DeltaListOpJSON}
264
288
  */
265
289
  toJSON(): DeltaListOpJSON;
266
- clone(start?: number, end?: number): RetainOp;
290
+ /**
291
+ * @param {number} [start]
292
+ * @param {number} [end]
293
+ * @param {boolean} [_markAsDone] accepted for a uniform children-op `clone` signature; ignored (retain
294
+ * holds no nested deltas).
295
+ * @return {RetainOp}
296
+ */
297
+ clone(start?: number, end?: number, _markAsDone?: boolean): RetainOp;
267
298
  $type: s.Schema<RetainOp>;
268
299
  /**
269
300
  * @param {RetainOp} other
@@ -274,6 +305,7 @@ export class RetainOp extends list.ListNode {
274
305
  * Delta that can be applied on a YType Embed
275
306
  *
276
307
  * @template {Delta} [DTypes=DeltaAny]
308
+ * @internal not part of the consumer API — a content op; build deltas via {@link create}/{@link DeltaBuilder}.
277
309
  */
278
310
  export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
279
311
  /**
@@ -323,9 +355,13 @@ export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
323
355
  */
324
356
  toJSON(): DeltaListOpJSON;
325
357
  /**
358
+ * @param {number} [_start] ignored (a modify is atomic); accepted for a uniform children-op signature.
359
+ * @param {number} [_end] ignored.
360
+ * @param {boolean} [markAsDone] freeze the cloned value (default); `false` shares it mutable — see
361
+ * {@link InsertOp#clone}. The op itself is still a fresh node; only its `value` is consumed.
326
362
  * @return {ModifyOp<DTypes>}
327
363
  */
328
- clone(): ModifyOp<DTypes>;
364
+ clone(_start?: number, _end?: number, markAsDone?: boolean): ModifyOp<DTypes>;
329
365
  $type: s.Schema<ModifyOp<Delta<any>>>;
330
366
  /**
331
367
  * @param {ModifyOp<any>} other
@@ -335,6 +371,7 @@ export class ModifyOp<DTypes extends Delta = DeltaAny> extends list.ListNode {
335
371
  /**
336
372
  * @template {any} [V=any]
337
373
  * @template {string|number} [K=any]
374
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
338
375
  */
339
376
  export class SetAttrOp<V extends unknown = any, K extends string | number = any> {
340
377
  /**
@@ -379,13 +416,16 @@ export class SetAttrOp<V extends unknown = any, K extends string | number = any>
379
416
  get fingerprint(): string;
380
417
  toJSON(): {
381
418
  type: "insert";
382
- value: DeltaJSON | V;
419
+ value: V | DeltaJSON;
383
420
  } & ({
384
421
  attribution: Attribution;
385
422
  } | {
386
423
  attribution?: undefined;
387
424
  });
388
425
  /**
426
+ * Full (frozen) clone. A `move` apply reuses the source op instead of cloning, so there is no
427
+ * shared-mutable variant — see {@link DeltaBuilder#apply}.
428
+ *
389
429
  * @return {SetAttrOp<V,K>}
390
430
  */
391
431
  clone(): SetAttrOp<V, K>;
@@ -398,6 +438,7 @@ export class SetAttrOp<V extends unknown = any, K extends string | number = any>
398
438
  /**
399
439
  * @template [V=any]
400
440
  * @template {string|number} [K=string|number]
441
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
401
442
  */
402
443
  export class DeleteAttrOp<V = any, K extends string | number = string | number> {
403
444
  /**
@@ -429,6 +470,11 @@ export class DeleteAttrOp<V = any, K extends string | number = string | number>
429
470
  * @return {DeltaAttrOpJSON}
430
471
  */
431
472
  toJSON(): DeltaAttrOpJSON;
473
+ /**
474
+ * Full (frozen) clone; a `move` apply reuses the source op instead — see {@link DeltaBuilder#apply}.
475
+ *
476
+ * @return {DeleteAttrOp<V,K>}
477
+ */
432
478
  clone(): DeleteAttrOp<V, K>;
433
479
  $type: s.Schema<DeleteAttrOp<any, string | number>>;
434
480
  /**
@@ -439,13 +485,15 @@ export class DeleteAttrOp<V = any, K extends string | number = string | number>
439
485
  /**
440
486
  * @template {DeltaAny} [Modifier=DeltaAny]
441
487
  * @template {string|number} [K=string]
488
+ * @internal not part of the consumer API — an attribute op; build deltas via {@link create}/{@link DeltaBuilder}.
442
489
  */
443
490
  export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string | number = string> {
444
491
  /**
445
492
  * @param {K} key
446
493
  * @param {Modifier} delta
494
+ * @param {Attribution?} attribution
447
495
  */
448
- constructor(key: K, delta: Modifier);
496
+ constructor(key: K, delta: Modifier, attribution: Attribution | null);
449
497
  /**
450
498
  * @readonly
451
499
  * @type {K}
@@ -456,6 +504,11 @@ export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string
456
504
  * @type {Modifier}
457
505
  */
458
506
  readonly value: Modifier;
507
+ /**
508
+ * @readonly
509
+ * @type {Attribution?}
510
+ */
511
+ readonly attribution: Attribution | null;
459
512
  /**
460
513
  * @type {string|null}
461
514
  */
@@ -474,6 +527,8 @@ export class ModifyAttrOp<Modifier extends DeltaAny = DeltaAny, K extends string
474
527
  */
475
528
  toJSON(): DeltaAttrOpJSON;
476
529
  /**
530
+ * Full (frozen) clone; a `move` apply reuses the source op instead — see {@link DeltaBuilder#apply}.
531
+ *
477
532
  * @return {ModifyAttrOp<Modifier,K>}
478
533
  */
479
534
  clone(): ModifyAttrOp<Modifier, K>;
@@ -488,15 +543,17 @@ export const $modifyOp: s.Schema<ModifyOp<Delta<any>>>;
488
543
  export const $textOp: s.Schema<TextOp>;
489
544
  export const $deleteOp: s.Schema<DeleteOp<any>>;
490
545
  export const $retainOp: s.Schema<RetainOp>;
491
- export const $anyOp: s.Schema<TextOp | InsertOp<any> | DeleteOp<any> | ModifyOp<Delta<any>>>;
546
+ export const $anyOp: s.Schema<DeleteOp<any> | TextOp | InsertOp<any> | ModifyOp<Delta<any>>>;
492
547
  export const $setAttrOp: s.Schema<SetAttrOp<any>>;
493
548
  export const $modifyAttrOp: s.Schema<ModifyAttrOp<any>>;
494
549
  export const $deleteAttrOp: s.Schema<DeleteAttrOp<any>>;
495
- export const $anyAttrOp: s.Schema<SetAttrOp<any, any> | DeleteAttrOp<any, string | number> | ModifyAttrOp<any, string>>;
550
+ export const $anyAttrOp: s.Schema<ModifyAttrOp<any, string> | SetAttrOp<any, any> | DeleteAttrOp<any, string | number>>;
496
551
  export function $setAttrOpWith<Content extends fingerprintTrait.Fingerprintable>($content: s.Schema<Content>): s.Schema<SetAttrOp<Content>>;
497
552
  export function $insertOpWith<Content extends fingerprintTrait.Fingerprintable>($content: s.Schema<Content>): s.Schema<InsertOp<Content>>;
498
553
  export function $modifyOpWith<Modify extends DeltaAny>($content: s.Schema<Modify>): s.Schema<ModifyOp<Modify>>;
499
554
  export function $modifyAttrOpWith<Modify extends DeltaAny>($content: s.Schema<Modify>): s.Schema<ModifyAttrOp<Modify>>;
555
+ export const $mark: s.Schema<Mark>;
556
+ export function createMark(key: number | string, id?: string, assoc?: 1 | -1, attrs?: object | null): Mark;
500
557
  /**
501
558
  * @template {DeltaConf} [Conf={}]
502
559
  * @extends {DeltaData<
@@ -551,6 +608,14 @@ export class Delta<Conf extends DeltaConf = {}> extends DeltaData<DeltaConfGetNa
551
608
  }
552
609
  export function slice<Conf_1 extends DeltaConf>(d: Delta<Conf_1>, start?: number, end?: number, currNode?: ChildrenOpAny | null): DeltaBuilder<Conf_1>;
553
610
  export function clone<D extends DeltaAny>(d: D): D extends Delta<infer Conf_1> ? DeltaBuilder<Conf_1> : never;
611
+ export function cloneShallow<D extends DeltaAny>(d: D): D extends Delta<infer Conf_1> ? DeltaBuilder<Conf_1> : never;
612
+ export function _mergeChildWithPrev(d: DeltaBuilderAny, op: InsertOp<any> | RetainOp | DeleteOp<any> | TextOp | ModifyOp<any>): boolean;
613
+ export function _splitChildAt(d: DeltaBuilderAny, op: ChildrenOpAny, offset: number): ChildrenOpAny;
614
+ export function _insertChild(d: DeltaBuilderAny, ref: ChildrenOpAny | null, op: ChildrenOpAny): ChildrenOpAny;
615
+ export function _removeChild(d: DeltaBuilderAny, op: ChildrenOpAny): void;
616
+ export function _shrinkChild(d: DeltaBuilderAny, op: ChildrenOpAny, offset: number, len: number): void;
617
+ export function _growRun(d: DeltaBuilderAny, op: RetainOp | DeleteOp<any>, n: number): void;
618
+ export function _spliceInsert(d: DeltaBuilderAny, op: InsertOp<any>, offset: number, elems: Array<any>): void;
554
619
  /**
555
620
  * @template {DeltaConf} [Conf={}]
556
621
  * @template {boolean} [FixedConf=false]
@@ -615,6 +680,30 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
615
680
  modify<NewContent extends Extract<DeltaConfGetAllowedChildren<Conf, FixedConf>, Delta | DeltaData<any, any, any, any> | DeltaBuilder>>(modify: NewContent, formatting?: FormattingAttributes | null, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
616
681
  children: DeltaConfGetChildren<Conf> | NewContent;
617
682
  }>, FixedConf>;
683
+ /**
684
+ * Add a cursor/selection {@link Mark} at `pos` — a {@link import('./position.js').Pos}: a `path` of
685
+ * content-index / attribute-key steps plus an `assoc` and optional immutable `attrs` (user data
686
+ * carried with the mark). Returns `this` for chaining (like every other builder method). Pass an
687
+ * explicit `id` to reference the mark later — re-adding the same `id` replaces it (e.g. to move a
688
+ * cursor or update its `attrs`) and {@link DeltaBuilder#removeMark} deletes it; an anonymous one-shot
689
+ * mark gets a fresh GUID otherwise.
690
+ *
691
+ * @param {import('./position.js').Pos} pos
692
+ * @param {string} [id]
693
+ * @return {this}
694
+ */
695
+ addMark(pos: import("./position.js").Pos, id?: string): this;
696
+ /**
697
+ * Remove the mark with `id`, located via `pos` (the position it was added at). On a settled document
698
+ * that holds the mark this removes it in place; on a fresh/markless builder it records a transmittable
699
+ * `deleteMarks` change (symmetric to {@link DeltaBuilder#addMark}), so
700
+ * `delta.create().removeMark(pos, id)` yields the delete-mark change to apply / rebase / transmit.
701
+ *
702
+ * @param {import('./position.js').Pos} pos
703
+ * @param {string} id
704
+ * @return {this}
705
+ */
706
+ removeMark(pos: import("./position.js").Pos, id: string): this;
618
707
  /**
619
708
  * @param {number} len
620
709
  * @param {FormattingAttributes?} [format]
@@ -668,9 +757,10 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
668
757
  * @template {Extract<DeltaConfGetAllowedAttrs<Conf, FixedConf>[Key],DeltaAny>} D
669
758
  * @param {Key} key
670
759
  * @param {D} modify
760
+ * @param {Attribution?} attribution
671
761
  * @return {DeltaBuilder<DeltaConfOverwrite<Conf,{attrs:AddToAttrs<DeltaConfGetAttrs<Conf>,Key,D>}>, FixedConf>}
672
762
  */
673
- modifyAttr<Key extends DeltaConfGetAllowedAttrs<Conf, FixedConf> extends infer As ? { [K in keyof As]: Extract<As[K], DeltaAny> extends never ? never : K; }[keyof As] : never, D extends Extract<DeltaConfGetAllowedAttrs<Conf, FixedConf>[Key], DeltaAny>>(key: Key, modify: D): DeltaBuilder<DeltaConfOverwrite<Conf, {
763
+ modifyAttr<Key extends DeltaConfGetAllowedAttrs<Conf, FixedConf> extends infer As ? { [K in keyof As]: Extract<As[K], DeltaAny> extends never ? never : K; }[keyof As] : never, D extends Extract<DeltaConfGetAllowedAttrs<Conf, FixedConf>[Key], DeltaAny>>(key: Key, modify: D, attribution?: Attribution | null): DeltaBuilder<DeltaConfOverwrite<Conf, {
674
764
  attrs: AddToAttrs<DeltaConfGetAttrs<Conf>, Key, D>;
675
765
  }>, FixedConf>;
676
766
  /**
@@ -687,11 +777,14 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
687
777
  * attribute). Any kind of `delete` op might be considered a bug. A final delta is not idempotent.
688
778
  *
689
779
  * @param {Delta<Conf>?} other
690
- * @param {{ final?: boolean }} opts -- (experimental)
780
+ * @param {{ final?: boolean, move?: boolean }} [opts] `move`: the caller donates `other` (it is not
781
+ * read again), so its content is consumed (shared mutable) rather than frozen-cloned — see {@link
782
+ * InsertOp#clone}. UNSAFE if the caller keeps using `other`.
691
783
  * @return {DeltaBuilder<Conf>}
692
784
  */
693
- apply(other: Delta<Conf> | null, { final }?: {
785
+ apply(other: Delta<Conf> | null, { final, move }?: {
694
786
  final?: boolean;
787
+ move?: boolean;
695
788
  }): DeltaBuilder<Conf>;
696
789
  /**
697
790
  * Rebase this op against a concurrent op. We can apply this op on a doc that already applied
@@ -727,9 +820,14 @@ export class DeltaBuilder<Conf extends DeltaConf = {}, FixedConf extends boolean
727
820
  text: true;
728
821
  } : never)>, FixedConf>;
729
822
  }
823
+ export function remapRootMarks(node: DeltaAny, mapKey: (key: number | string) => number | string | null): void;
824
+ export function addRootMark(node: DeltaAny, mark: Mark): void;
825
+ export function deleteRootMark(node: DeltaAny, id: string): void;
826
+ export function mergeRootMarks(target: DeltaAny, source: DeltaAny, mapKey?: (key: number | string) => number | string | null): void;
730
827
  /**
731
828
  * @template {DeltaConf} Conf
732
829
  * @extends {s.Schema<Delta<Conf>>}
830
+ * @internal use the {@link $delta} factory; this class is exported only for the `$$delta` predicate.
733
831
  */
734
832
  export class $Delta<Conf extends DeltaConf> extends s.Schema<Delta<Conf>> {
735
833
  /**
@@ -764,7 +862,28 @@ export class $Delta<Conf extends DeltaConf> extends s.Schema<Delta<Conf>> {
764
862
  }>;
765
863
  };
766
864
  }
767
- export function $delta<DeltaConf extends ReadableDeltaConf = {}>({ name, attrs, children, text, formats, recursiveChildren: recursive }: DeltaConf): s.Schema<Delta<ReadDeltaConf<DeltaConf>>>;
865
+ /**
866
+ * Name-first form: a string-literal `name` as the first argument is preserved as a literal type
867
+ * (generic argument inference), so callers don't need `s.$literal('x')` / `@type {const}` to keep the
868
+ * node name literal. The remaining options follow in `opts`.
869
+ *
870
+ * @template {string} Name
871
+ * @template {Omit<ReadableDeltaConf, 'name'>} [Opts={}]
872
+ * @overload
873
+ * @param {Name} name
874
+ * @param {Opts} [opts]
875
+ * @return {s.Schema<Delta<ReadDeltaConf<Opts & { name: Name }>>>}
876
+ */
877
+ export function $delta<Name extends string, Opts extends Omit<ReadableDeltaConf, "name"> = {}>(name: Name, opts?: Opts | undefined): s.Schema<Delta<ReadDeltaConf<Opts & {
878
+ name: Name;
879
+ }>>>;
880
+ /**
881
+ * @template {ReadableDeltaConf} [Conf={}]
882
+ * @overload
883
+ * @param {Conf} opts
884
+ * @return {s.Schema<Delta<ReadDeltaConf<Conf>>>}
885
+ */
886
+ export function $delta<Conf extends ReadableDeltaConf = {}>(opts: Conf): s.Schema<Delta<ReadDeltaConf<Conf>>>;
768
887
  export const $$delta: s.Schema<$Delta<DeltaConf>>;
769
888
  export const $deltaAny: s.Schema<Delta<any>>;
770
889
  export const $deltaBuilderAny: s.Schema<DeltaBuilderAny>;
@@ -779,6 +898,7 @@ export function random<Conf_1 extends DeltaConf>(gen: prng.PRNG, $d: s.Schema<De
779
898
  source?: DeltaAny | null | undefined;
780
899
  minChildOps?: number | undefined;
781
900
  maxChildOps?: number | undefined;
901
+ attribution?: boolean | undefined;
782
902
  }): DeltaBuilder<Conf_1>;
783
903
  /**
784
904
  * @overload
@@ -796,13 +916,13 @@ export function create<NodeName extends string | null>(nodeName: NodeName): Delt
796
916
  } : {}>;
797
917
  /**
798
918
  * @template {string} NodeName
799
- * @template {DeltaConf} Conf
919
+ * @template {s.Schema<DeltaAny>} Schema
800
920
  * @overload
801
921
  * @param {NodeName} nodeName
802
- * @param {s.Schema<Delta<Conf>>} schema
803
- * @return {DeltaBuilder<Conf, true>}
922
+ * @param {Schema} schema
923
+ * @return {Schema extends s.Schema<Delta<infer Conf>> ? DeltaBuilder<Conf, true> : never}
804
924
  */
805
- export function create<NodeName extends string | null, Conf extends DeltaConf>(nodeName: NodeName, schema: s.Schema<Delta<Conf>>): DeltaBuilder<Conf, true>;
925
+ export function create<NodeName extends string | null, Schema extends s.Schema<DeltaAny>>(nodeName: NodeName, schema: Schema): Schema extends s.Schema<Delta<infer Conf_1>> ? DeltaBuilder<Conf_1, true> : never;
806
926
  /**
807
927
  * @template {s.Schema<DeltaAny>} Schema
808
928
  * @overload
@@ -922,11 +1042,19 @@ export type Attribution = {
922
1042
  export type FormattingAttributes = {
923
1043
  [key: string]: any;
924
1044
  };
1045
+ export type MarkJSON = {
1046
+ id: string;
1047
+ key: number | string;
1048
+ assoc: 1 | -1;
1049
+ attrs?: object;
1050
+ };
925
1051
  export type DeltaJSON = {
926
1052
  type: "delta";
927
1053
  name?: string;
928
1054
  attrs?: { [Key in string | number]: DeltaAttrOpJSON; };
929
1055
  children?: Array<DeltaListOpJSON>;
1056
+ marks?: Array<MarkJSON>;
1057
+ deleteMarks?: Array<string>;
930
1058
  };
931
1059
  export type DeltaListOpJSON = {
932
1060
  type: "insert";
@@ -960,6 +1088,7 @@ export type DeltaAttrOpJSON = {
960
1088
  } | {
961
1089
  type: "modify";
962
1090
  value: DeltaJSON;
1091
+ attribution?: Attribution;
963
1092
  };
964
1093
  export type ChildrenOpAny = TextOp | InsertOp<any> | DeleteOp | RetainOp | ModifyOp<any>;
965
1094
  export type AttrOpAny = SetAttrOp<any> | DeleteAttrOp<any> | ModifyAttrOp;
@@ -987,8 +1116,8 @@ export type DeltaConf = {
987
1116
  */
988
1117
  export type AsDeltaConf<T> = T extends infer DC extends DeltaConf ? DC : never;
989
1118
  export type DeltaConfGetName<Conf_1 extends DeltaConf> = Conf_1 extends {
990
- name: infer Name;
991
- } ? (unknown extends Name ? any : (Exclude<Name, undefined>)) : any;
1119
+ name: infer Name_1;
1120
+ } ? (unknown extends Name_1 ? any : (Exclude<Name_1, undefined>)) : any;
992
1121
  export type DeltaConfGetChildren<Conf_1 extends DeltaConf> = (Conf_1 extends {
993
1122
  children: infer Children_1;
994
1123
  } ? (unknown extends Children_1 ? any : Children_1) : never) | (Conf_1 extends {
@@ -1079,6 +1208,67 @@ import * as fingerprintTrait from '../trait/fingerprint.js';
1079
1208
  * @template {{[Key in string|number|symbol]: any}} NewAttrs
1080
1209
  * @typedef {{ [K in (keyof NewAttrs | keyof Attrs)]: (unknown extends Attrs[K] ? never : Attrs[K]) | (unknown extends NewAttrs[K] ? never : NewAttrs[K]) }} MergeAttrs
1081
1210
  */
1211
+ /**
1212
+ * A cursor/selection anchor stored inside a delta tree (see {@link import('./position.js').marksToPositions}).
1213
+ *
1214
+ * - `key` — the *terminal* step of the position: a content offset (number) or an attribute key
1215
+ * (string) within the node that holds the mark.
1216
+ * - `id` — a unique, user-defined identifier.
1217
+ * - `assoc` — the gravity at a boundary (left `-1` / right `1`).
1218
+ * - `attrs` — optional user-supplied data carried with the mark **by reference**: the same
1219
+ * object is shared across the mark, its `copy`/`clone`s, `toJSON`, and every `MarkPos` from
1220
+ * `marksToPositions`, so the caller must treat it as immutable (do not mutate it after attaching).
1221
+ *
1222
+ * A `Mark` is **immutable** — never mutate one in place; to "move" a mark, replace it with a fresh
1223
+ * `Mark` via {@link Mark#copy} (the {@link Marks} set keys by id, so re-adding the same id replaces
1224
+ * it). Immutability lets a `Mark` be shared freely across a delta and its clones. The class is not
1225
+ * exported — construct via {@link createMark} and validate via {@link $mark}.
1226
+ */
1227
+ declare class Mark {
1228
+ /**
1229
+ * @param {number|string} key
1230
+ * @param {string} [id] unique id; defaults to a fresh GUID
1231
+ * @param {1|-1} [assoc] gravity at a boundary; defaults to right (`1`)
1232
+ * @param {object?} [attrs] optional user data, stored by reference; treat as immutable
1233
+ */
1234
+ constructor(key: number | string, id?: string, assoc?: 1 | -1, attrs?: object | null);
1235
+ /**
1236
+ * @readonly
1237
+ * @type {number|string}
1238
+ */
1239
+ readonly key: number | string;
1240
+ /**
1241
+ * @readonly
1242
+ * @type {string}
1243
+ */
1244
+ readonly id: string;
1245
+ /**
1246
+ * @readonly
1247
+ * @type {1|-1}
1248
+ */
1249
+ readonly assoc: 1 | -1;
1250
+ /**
1251
+ * @readonly
1252
+ * @type {object?}
1253
+ */
1254
+ readonly attrs: object | null;
1255
+ /**
1256
+ * A copy of this mark, optionally at a different `key` (used to "move" an otherwise-immutable mark).
1257
+ *
1258
+ * @param {number|string} [key]
1259
+ * @return {Mark}
1260
+ */
1261
+ copy(key?: number | string): Mark;
1262
+ /**
1263
+ * @return {MarkJSON}
1264
+ */
1265
+ toJSON(): MarkJSON;
1266
+ $type: s.Schema<Mark>;
1267
+ /**
1268
+ * @param {Mark} other
1269
+ */
1270
+ [equalityTrait.EqualityTraitSymbol](other: Mark): boolean;
1271
+ }
1082
1272
  /**
1083
1273
  * @typedef {Delta<any>} DeltaAny
1084
1274
  */
@@ -1198,7 +1388,68 @@ declare class DeltaData<Name extends string, Attrs extends { [K in string | numb
1198
1388
  * Is the final document and does not contain delete, modify, or retain ops.
1199
1389
  */
1200
1390
  isFinal: boolean;
1391
+ /**
1392
+ * Leaf {@link Mark marks} whose cursor sits in THIS node (in a settled delta), or the marks to ADD
1393
+ * to the target node (in a change delta). Local/ephemeral cursor state — NOT part of the document
1394
+ * fingerprint or equality. `null` when there are none. See {@link Marks}.
1395
+ *
1396
+ * @type {Marks?}
1397
+ */
1398
+ marks: Marks | null;
1399
+ /**
1400
+ * Mark ids to DELETE (tombstones). Only present in a (non-settled) change delta — like a
1401
+ * `DeleteAttrOp`, a deletion is dropped from a final delta (a materialized document carries none, at
1402
+ * any depth). `null` when there are none. Marks follow *last-writer-wins*, treating each op as an
1403
+ * absolute per-id assignment (present vs absent): adding a mark cancels a pending delete of the same
1404
+ * id ({@link addMarkTo}) and a delete cancels a present add ({@link deleteMarkTo}), so a node never
1405
+ * holds both an add and a delete for one id. {@link deleteMarkTo} is the sole writer of this set
1406
+ * (and `addMarkTo`'s mirror); see {@link applyMarkOps}.
1407
+ *
1408
+ * @type {Set<string>?}
1409
+ */
1410
+ deleteMarks: Set<string> | null;
1411
+ /**
1412
+ * Conservative "this subtree might hold a {@link Mark}" flag (own {@link DeltaData#marks} or any
1413
+ * descendant's). Set `true` when a mark is introduced and OR-propagated up to every ancestor; it is
1414
+ * **never** decremented (removal leaves it conservatively `true`). {@link
1415
+ * import('./position.js').marksToPositions} is the sole resetter: it prunes subtrees where this is
1416
+ * `false` (a guaranteed-empty subtree) and lazily clears a stale `true` to `false` when a descended
1417
+ * subtree turns out to hold none. `false` therefore *guarantees* no marks; `true` only *maybe*.
1418
+ */
1419
+ maybeHasMarks: boolean;
1201
1420
  }
1202
1421
  import * as prng from '../prng.js';
1422
+ /**
1423
+ * The set of leaf {@link Mark marks} on a single delta node, deduplicated by id (so adding the same id
1424
+ * again replaces it). An internal data-shape class (never a public/`new`-from-outside class): every
1425
+ * mutation goes through its methods, so a stored {@link Mark} is treated as immutable and is never
1426
+ * manipulated in place — to "move" a mark you replace it with a fresh `Mark`. {@link clone}/{@link
1427
+ * slice} copy the set so a `done` delta's marks are never mutated through a shared reference. Marks are
1428
+ * local/ephemeral cursor state
1429
+ * and not part of a delta's identity, so this set has no fingerprint/equality of its own.
1430
+ */
1431
+ declare class Marks {
1432
+ /**
1433
+ * @type {Array<Mark>}
1434
+ */
1435
+ _marks: Array<Mark>;
1436
+ get size(): number;
1437
+ /**
1438
+ * Add or replace `mark` (by id). Returns `true` if it was added as a new mark, `false` if it
1439
+ * replaced an existing one with the same id.
1440
+ *
1441
+ * @param {Mark} mark
1442
+ * @return {boolean}
1443
+ */
1444
+ add(mark: Mark): boolean;
1445
+ /**
1446
+ * Remove the mark with `id`. Returns `true` if a mark was present and removed, `false` if absent.
1447
+ *
1448
+ * @param {string} id
1449
+ * @return {boolean}
1450
+ */
1451
+ delete(id: string): boolean;
1452
+ [Symbol.iterator](): ArrayIterator<Mark>;
1453
+ }
1203
1454
  export {};
1204
1455
  //# sourceMappingURL=delta.d.ts.map
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index.
3
+ *
4
+ * @typedef {string|number} PosStep
5
+ */
6
+ /**
7
+ * A location in a delta tree. `path` descends from the node the position is relative to and ends in
8
+ * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the
9
+ * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is
10
+ * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is
11
+ * stored on the {@link import('./delta.js').createMark mark} when the position is written with
12
+ * {@link import('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}.
13
+ *
14
+ * @typedef {{ path: Array<PosStep>, assoc: -1|1, attrs?: object|null }} Pos
15
+ */
16
+ /**
17
+ * A {@link Pos} tagged with the unique id of a stored {@link import('./delta.js').createMark mark} —
18
+ * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with
19
+ * {@link import('./delta.js').DeltaBuilder#addMark}.
20
+ *
21
+ * @typedef {{ id: string } & Pos} MarkPos
22
+ */
23
+ /**
24
+ * Schema for a {@link Pos}.
25
+ *
26
+ * @type {s.Schema<Pos>}
27
+ */
28
+ export const $pos: s.Schema<Pos>;
29
+ export function create(path: Array<PosStep>, assoc?: -1 | 1, attrs?: object | null): Pos;
30
+ export function equals(a: Pos | MarkPos, b: Pos | MarkPos): boolean;
31
+ /**
32
+ * Schema for a {@link MarkPos}.
33
+ *
34
+ * @type {s.Schema<MarkPos>}
35
+ */
36
+ export const $markPos: s.Schema<MarkPos>;
37
+ export function marksToPositions(d: delta.DeltaAny): Array<MarkPos>;
38
+ /**
39
+ * A single step of a {@link Pos} path: a `string` attribute key, or a `number` content index.
40
+ */
41
+ export type PosStep = string | number;
42
+ /**
43
+ * A location in a delta tree. `path` descends from the node the position is relative to and ends in
44
+ * the terminal (a trailing-number cursor gap, or a trailing-string attribute leaf). `assoc` is the
45
+ * gravity at a boundary: `-1` binds to the preceding content, `1` to the following content. `attrs` is
46
+ * optional immutable user data carried with the position (e.g. an RDT's clientID/user metadata); it is
47
+ * stored on the {@link import ('./delta.js').createMark mark} when the position is written with
48
+ * {@link import ('./delta.js').DeltaBuilder#addMark} and read back by {@link marksToPositions}.
49
+ */
50
+ export type Pos = {
51
+ path: Array<PosStep>;
52
+ assoc: -1 | 1;
53
+ attrs?: object | null;
54
+ };
55
+ /**
56
+ * A {@link Pos} tagged with the unique id of a stored {@link import ('./delta.js').createMark mark} —
57
+ * what {@link marksToPositions} returns (its `attrs` is the mark's stored metadata). Add marks with
58
+ * {@link import ('./delta.js').DeltaBuilder#addMark}.
59
+ */
60
+ export type MarkPos = {
61
+ id: string;
62
+ } & Pos;
63
+ import * as s from '../schema.js';
64
+ import * as delta from './delta.js';
65
+ //# sourceMappingURL=position.d.ts.map