edytor 3.0.0 → 4.0.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 (143) hide show
  1. package/README.md +2 -2
  2. package/dist/cloudflare/DocumentRoom.d.ts +13 -9
  3. package/dist/cloudflare/DocumentRoom.js +10 -6
  4. package/dist/cloudflare/room/context.d.ts +27 -26
  5. package/dist/cloudflare/room/context.js +2 -2
  6. package/dist/cloudflare/room/purge.d.ts +6 -3
  7. package/dist/cloudflare/room/purge.js +44 -19
  8. package/dist/cloudflare/room/updates.d.ts +3 -4
  9. package/dist/cloudflare/room/updates.js +6 -8
  10. package/dist/crdt/attribution/attribution.d.ts +31 -12
  11. package/dist/crdt/attribution/attribution.js +56 -18
  12. package/dist/crdt/attribution/block.d.ts +3 -3
  13. package/dist/crdt/attribution/block.js +7 -8
  14. package/dist/crdt/attribution/index.d.ts +1 -1
  15. package/dist/crdt/attribution/index.js +1 -1
  16. package/dist/crdt/data.d.ts +62 -31
  17. package/dist/crdt/data.js +211 -103
  18. package/dist/crdt/doc/delete.d.ts +1 -1
  19. package/dist/crdt/doc/delete.js +13 -30
  20. package/dist/crdt/doc/funnel.js +29 -24
  21. package/dist/crdt/doc/gate.d.ts +3 -3
  22. package/dist/crdt/doc/history.d.ts +25 -9
  23. package/dist/crdt/doc/history.js +150 -40
  24. package/dist/crdt/doc/layout.js +11 -22
  25. package/dist/crdt/doc/meta.js +12 -17
  26. package/dist/crdt/doc/moves.d.ts +1 -1
  27. package/dist/crdt/doc/moves.js +52 -32
  28. package/dist/crdt/doc/reads.js +2 -2
  29. package/dist/crdt/doc/seed.js +2 -2
  30. package/dist/crdt/doc/split-merge.js +12 -15
  31. package/dist/crdt/doc/steps.d.ts +25 -13
  32. package/dist/crdt/doc/steps.js +52 -122
  33. package/dist/crdt/doc/types.d.ts +21 -9
  34. package/dist/crdt/document.d.ts +16 -5
  35. package/dist/crdt/document.js +21 -4
  36. package/dist/crdt/edytor-doc.d.ts +62 -64
  37. package/dist/crdt/edytor-doc.js +18 -13
  38. package/dist/crdt/engine-api.d.ts +33 -1
  39. package/dist/crdt/engine.d.ts +0 -1
  40. package/dist/crdt/engine.js +1 -4
  41. package/dist/crdt/flow.d.ts +1 -1
  42. package/dist/crdt/flow.js +25 -27
  43. package/dist/crdt/index.d.ts +26 -25
  44. package/dist/crdt/index.js +1 -1
  45. package/dist/crdt/placement/display.d.ts +5 -30
  46. package/dist/crdt/placement/display.js +39 -144
  47. package/dist/crdt/placement/keys.d.ts +58 -0
  48. package/dist/crdt/placement/keys.js +90 -0
  49. package/dist/crdt/placement/model.d.ts +119 -118
  50. package/dist/crdt/placement/model.js +242 -142
  51. package/dist/crdt/placement/resolve.d.ts +123 -35
  52. package/dist/crdt/placement/resolve.js +187 -153
  53. package/dist/crdt/placement/slots.d.ts +134 -0
  54. package/dist/crdt/placement/slots.js +152 -0
  55. package/dist/crdt/providers/room.d.ts +16 -2
  56. package/dist/crdt/providers/room.js +64 -17
  57. package/dist/crdt/providers/websocket.js +5 -3
  58. package/dist/crdt/purge.d.ts +17 -8
  59. package/dist/crdt/purge.js +236 -126
  60. package/dist/crdt/restore.d.ts +2 -2
  61. package/dist/crdt/restore.js +18 -34
  62. package/dist/crdt/schema.d.ts +22 -21
  63. package/dist/crdt/schema.js +29 -23
  64. package/dist/crdt/storage.d.ts +1 -1
  65. package/dist/crdt/storage.js +1 -1
  66. package/dist/crdt/structs.d.ts +15 -15
  67. package/dist/crdt/structs.js +8 -22
  68. package/dist/crdt/text/index/cache.js +4 -0
  69. package/dist/crdt/text/index/claims.js +12 -0
  70. package/dist/crdt/text/index/fold.d.ts +2 -3
  71. package/dist/crdt/text/index/fold.js +194 -44
  72. package/dist/crdt/text/index/layout.js +5 -8
  73. package/dist/crdt/text/index/placement.d.ts +26 -18
  74. package/dist/crdt/text/index/placement.js +404 -138
  75. package/dist/crdt/text/index/records.d.ts +3 -3
  76. package/dist/crdt/text/index/records.js +24 -31
  77. package/dist/crdt/text/index/shared.d.ts +11 -3
  78. package/dist/crdt/text/index/shared.js +12 -3
  79. package/dist/crdt/text/index/state.d.ts +21 -17
  80. package/dist/crdt/text/index/state.js +15 -17
  81. package/dist/crdt/text/index/streams.d.ts +10 -5
  82. package/dist/crdt/text/index/streams.js +78 -27
  83. package/dist/crdt/text/items.d.ts +10 -3
  84. package/dist/crdt/text/items.js +7 -0
  85. package/dist/crdt/text/model.d.ts +77 -62
  86. package/dist/crdt/text/model.js +84 -169
  87. package/dist/crdt/text/ranges.d.ts +1 -1
  88. package/dist/crdt/text/ranges.js +3 -3
  89. package/dist/crdt/text/rows.d.ts +13 -7
  90. package/dist/crdt/text/rows.js +24 -7
  91. package/dist/crdt/text/runs.d.ts +17 -12
  92. package/dist/crdt/text/runs.js +24 -7
  93. package/dist/crdt/text/streams.d.ts +26 -13
  94. package/dist/crdt/text/streams.js +41 -14
  95. package/dist/crdt/vendor/yjs/UPSTREAM.md +568 -21
  96. package/dist/crdt/vendor/yjs/dts/global.d.ts +2 -0
  97. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  98. package/dist/crdt/vendor/yjs/dts/structs/AbstractStruct.d.ts +7 -0
  99. package/dist/crdt/vendor/yjs/dts/structs/Item.d.ts +194 -10
  100. package/dist/crdt/vendor/yjs/dts/utils/Doc.d.ts +6 -3
  101. package/dist/crdt/vendor/yjs/dts/utils/StructStore.d.ts +5 -18
  102. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +15 -1
  103. package/dist/crdt/vendor/yjs/dts/utils/UpdateDecoder.d.ts +14 -6
  104. package/dist/crdt/vendor/yjs/dts/utils/UpdateEncoder.d.ts +33 -6
  105. package/dist/crdt/vendor/yjs/dts/utils/ids.d.ts +1 -65
  106. package/dist/crdt/vendor/yjs/dts/utils/marks.d.ts +6 -1
  107. package/dist/crdt/vendor/yjs/dts/ynode.d.ts +43 -7
  108. package/dist/crdt/vendor/yjs/global.d.ts +2 -0
  109. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  110. package/dist/crdt/vendor/yjs/src/structs/AbstractStruct.js +10 -0
  111. package/dist/crdt/vendor/yjs/src/structs/Item.js +610 -51
  112. package/dist/crdt/vendor/yjs/src/utils/BlockSet.js +18 -9
  113. package/dist/crdt/vendor/yjs/src/utils/Doc.js +5 -3
  114. package/dist/crdt/vendor/yjs/src/utils/StructStore.js +5 -0
  115. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +36 -13
  116. package/dist/crdt/vendor/yjs/src/utils/UpdateDecoder.js +88 -18
  117. package/dist/crdt/vendor/yjs/src/utils/UpdateEncoder.js +119 -32
  118. package/dist/crdt/vendor/yjs/src/utils/encoding.js +13 -1
  119. package/dist/crdt/vendor/yjs/src/utils/ids.js +7 -7
  120. package/dist/crdt/vendor/yjs/src/utils/marks.js +193 -8
  121. package/dist/crdt/vendor/yjs/src/utils/redo.js +1 -1
  122. package/dist/crdt/vendor/yjs/src/utils/transaction-helpers.js +1 -1
  123. package/dist/crdt/vendor/yjs/src/utils/updates.js +3 -3
  124. package/dist/crdt/vendor/yjs/src/ynode.js +177 -12
  125. package/dist/edytor.svelte.js +4 -1
  126. package/dist/events/beforeInputCommands.js +2 -2
  127. package/dist/events/onPageHide.d.ts +3 -0
  128. package/dist/events/onPageHide.js +16 -0
  129. package/dist/export/forms.d.ts +25 -25
  130. package/dist/surface/observer.svelte.js +2 -2
  131. package/dist/surface/projector.svelte.d.ts +15 -3
  132. package/dist/surface/projector.svelte.js +59 -8
  133. package/package.json +2 -2
  134. package/dist/crdt/placement/rank.d.ts +0 -87
  135. package/dist/crdt/placement/rank.js +0 -332
  136. package/dist/crdt/placement/source.d.ts +0 -43
  137. package/dist/crdt/placement/source.js +0 -66
  138. package/dist/crdt/text/delete-index.d.ts +0 -129
  139. package/dist/crdt/text/delete-index.js +0 -365
  140. package/dist/crdt/text/deletes.d.ts +0 -76
  141. package/dist/crdt/text/deletes.js +0 -362
  142. package/dist/crdt/text/index/anchored.d.ts +0 -17
  143. package/dist/crdt/text/index/anchored.js +0 -197
@@ -25,6 +25,8 @@ declare type ContentAny = import('./structs/Item.js').ContentAny
25
25
  declare type ContentFormat = import('./structs/Item.js').ContentFormat
26
26
  declare type ContentDeleted = import('./structs/Item.js').ContentDeleted
27
27
  declare type ContentString = import('./structs/Item.js').ContentString
28
+ declare type ContentHold = import('./structs/Item.js').ContentHold
29
+ declare type ContentMove = import('./structs/Item.js').ContentMove
28
30
 
29
31
 
30
32
  // @todo the below should have a separate Y/[mod] export
@@ -17,4 +17,4 @@ export { idAtIndex, indexOfId } from "./utils/positions.js";
17
17
  export { findIndexSS, getItemCleanStart, getItemCleanEnd, isKeptReplaced } from "./utils/transaction-helpers.js";
18
18
  export { Transaction, transact } from "./utils/Transaction.js";
19
19
  export { redoItem, keepItem } from "./utils/redo.js";
20
- export { Item, followRedone, ContentBinary, ContentDeleted, ContentFormat, ContentAny, ContentString, ContentType } from "./structs/Item.js";
20
+ export { Item, followRedone, ContentBinary, ContentDeleted, ContentFormat, ContentAny, ContentString, ContentType, ContentMove } from "./structs/Item.js";
@@ -10,6 +10,13 @@ export class AbstractStruct {
10
10
  * @type {boolean}
11
11
  */
12
12
  get deleted(): boolean;
13
+ /**
14
+ * Whether the engine deleted this struct (YP20: an item can be hidden without
15
+ * being removed; a GC struct is removed, a Skip is not).
16
+ *
17
+ * @type {boolean}
18
+ */
19
+ get removed(): boolean;
13
20
  /**
14
21
  * Merge this struct with the item to the right.
15
22
  * This method is already assuming that `this.id.clock + this.length === this.id.clock`.
@@ -67,6 +67,21 @@ export class Item extends AbstractStruct {
67
67
  * @type {number} byte
68
68
  */
69
69
  info: number;
70
+ /**
71
+ * YP20: how many live hold records (`ContentHold`) name this item. A
72
+ * held item reads as deleted; the count is local, never encoded (each
73
+ * replica counts the records it integrated).
74
+ * @type {number}
75
+ */
76
+ holds: number;
77
+ /**
78
+ * YP22: the live move records (`ContentMove`) naming this item, the
79
+ * strongest first — the greatest `(priority, client, clock)` — or `null`.
80
+ * The first is its mover: the item shows there, hidden at home. Local,
81
+ * never encoded.
82
+ * @type {Array<Item>|null}
83
+ */
84
+ movers: Array<Item> | null;
70
85
  /**
71
86
  * This is used to mark the item as an indexed fast-search marker
72
87
  *
@@ -80,6 +95,18 @@ export class Item extends AbstractStruct {
80
95
  */
81
96
  get keep(): boolean;
82
97
  get countable(): boolean;
98
+ /**
99
+ * Whether this item shows nowhere: removed or held (YP22; a moved item
100
+ * shows at its mover).
101
+ * @type {Boolean}
102
+ */
103
+ get gone(): boolean;
104
+ /**
105
+ * YP22: the live move record this item shows at (the strongest of
106
+ * `movers`), or `null` at home.
107
+ * @type {Item|null}
108
+ */
109
+ get mover(): Item | null;
83
110
  markDeleted(): void;
84
111
  /**
85
112
  * Computes the last content address of this Item.
@@ -110,7 +137,7 @@ export class Item extends AbstractStruct {
110
137
  * @return {Item}
111
138
  */
112
139
  split(transaction: Transaction | null, diff: number): Item;
113
- get ref(): 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
140
+ get ref(): 2 | 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13;
114
141
  /**
115
142
  * @type {true}
116
143
  */
@@ -159,8 +186,9 @@ export class AbstractContent {
159
186
  integrate(_transaction: Transaction, _item: Item): void;
160
187
  /**
161
188
  * @param {Transaction} _transaction
189
+ * @param {Item} [_item] the item deleted (YP22: a move record reads it)
162
190
  */
163
- delete(_transaction: Transaction): void;
191
+ delete(_transaction: Transaction, _item?: Item): void;
164
192
  /**
165
193
  * @param {Transaction} _transaction
166
194
  */
@@ -169,12 +197,13 @@ export class AbstractContent {
169
197
  * @param {UpdateEncoder} _encoder
170
198
  * @param {number} _offset
171
199
  * @param {number} _offsetEnd
200
+ * @param {Item} [_item] the item written (YP25: a format item reads its id)
172
201
  */
173
- write(_encoder: UpdateEncoder, _offset: number, _offsetEnd: number): void;
202
+ write(_encoder: UpdateEncoder, _offset: number, _offsetEnd: number, _item?: Item): void;
174
203
  /**
175
- * @return {1|2|3|4|5|6|7|8|9}
204
+ * @return {1|2|3|4|5|6|7|8|9|11|12|13}
176
205
  */
177
- getRef(): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
206
+ getRef(): 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | 12 | 13;
178
207
  }
179
208
  export class ContentAny {
180
209
  /**
@@ -294,9 +323,19 @@ export class ContentBinary {
294
323
  export class ContentDeleted {
295
324
  /**
296
325
  * @param {number} len
326
+ * @param {number} [cls] YP29: a collected mark's or claim's sort class
297
327
  */
298
- constructor(len: number);
328
+ constructor(len: number, cls?: number);
299
329
  len: number;
330
+ /**
331
+ * YP29: what a collected paired mark item or claim item keeps, for each
332
+ * of its units: its sort class (`markClass`: `0` a left-side mark, `2` a
333
+ * right-side one, `3` a claim), which orders concurrent inserts at its
334
+ * origin on every replica (`undefined`: none, any other deleted content).
335
+ *
336
+ * @type {number|undefined}
337
+ */
338
+ cls: number | undefined;
300
339
  /**
301
340
  * @return {number}
302
341
  */
@@ -343,13 +382,157 @@ export class ContentDeleted {
343
382
  */
344
383
  write(encoder: UpdateEncoder, offset: number, offsetEnd: number): void;
345
384
  /**
346
- * @return {1}
385
+ * @return {1|13}
347
386
  */
348
- getRef(): 1;
387
+ getRef(): 1 | 13;
349
388
  }
350
389
  /**
351
- * @private
390
+ * A hold record: one unit per held id range (`client, clock, len`). While the
391
+ * record is live, the items it names read as deleted; deleting the record
392
+ * shows them again (an undo), unless another live record holds them. A record
393
+ * integrates at once; what it names that has not arrived takes its hold when
394
+ * it does (`applyPending`).
352
395
  */
396
+ export class ContentHold {
397
+ /**
398
+ * @param {Array<number>} ids
399
+ */
400
+ constructor(ids: Array<number>);
401
+ ids: number[];
402
+ /**
403
+ * @return {number}
404
+ */
405
+ getLength(): number;
406
+ /**
407
+ * @return {Array<any>}
408
+ */
409
+ getContent(): Array<any>;
410
+ /**
411
+ * @return {boolean}
412
+ */
413
+ isCountable(): boolean;
414
+ /**
415
+ * @return {ContentHold}
416
+ */
417
+ copy(): ContentHold;
418
+ /**
419
+ * @param {number} offset
420
+ * @return {ContentHold}
421
+ */
422
+ splice(offset: number): ContentHold;
423
+ /**
424
+ * @param {ContentHold} right
425
+ * @return {boolean}
426
+ */
427
+ mergeWith(right: ContentHold): boolean;
428
+ /**
429
+ * @param {Transaction} transaction
430
+ * @param {Item} _item
431
+ */
432
+ integrate(transaction: Transaction, _item: Item): void;
433
+ /**
434
+ * @param {Transaction} transaction
435
+ */
436
+ delete(transaction: Transaction): void;
437
+ /**
438
+ * @param {Transaction} _tr
439
+ */
440
+ gc(_tr: Transaction): void;
441
+ /**
442
+ * @param {UpdateEncoder} encoder
443
+ * @param {number} offset
444
+ * @param {number} offsetEnd
445
+ */
446
+ write(encoder: UpdateEncoder, offset: number, offsetEnd: number): void;
447
+ /**
448
+ * @return {11}
449
+ */
450
+ getRef(): 11;
451
+ }
452
+ export function applyPending(tr: Transaction, clients: Array<number>): void;
453
+ /**
454
+ * A move record: one countable unit at its destination, naming the units
455
+ * it moves (`client, clock, len` ranges, in the order they show) with a
456
+ * Lamport `priority`, a `side` (`0`: it stands after what precedes it,
457
+ * `1`: before what follows it — its sort class among the items of one
458
+ * origin, `markClass`), and for the sort of two records at one origin
459
+ * (`utils/marks.js` `sourceOrder`) the chain of units it stands at (`at`:
460
+ * the home slots from the root sequence down to that unit, else the first
461
+ * unit it names) and its `part` there. While the record is live, each named unit shows at
462
+ * the record that wins its movers and is hidden at home; deleting the
463
+ * record (an undo) hands the unit to the next record, else home. A record
464
+ * waits for the units it names as an item waits for its origin
465
+ * (`getMissing`), so two records at one origin sort by their units' home
466
+ * order on every replica (`sourceOrder`). Immutable once written, so
467
+ * replicas converge in any order. The record's item is the one integrating
468
+ * or deleting it (it is what the units' `movers` hold).
469
+ */
470
+ export class ContentMove {
471
+ /**
472
+ * @param {number} priority
473
+ * @param {number} side
474
+ * @param {Array<number>} ids
475
+ * @param {number} [part] the writer's order among the records standing at one unit (0–7)
476
+ * @param {Array<ID>|null} [at] the chain the record stands at, outermost first (`null`: the first unit it names)
477
+ */
478
+ constructor(priority: number, side: number, ids: Array<number>, part?: number, at?: Array<ID> | null);
479
+ priority: number;
480
+ side: number;
481
+ ids: number[];
482
+ part: number;
483
+ at: ID[] | null;
484
+ /**
485
+ * @return {number}
486
+ */
487
+ getLength(): number;
488
+ /**
489
+ * @return {Array<any>}
490
+ */
491
+ getContent(): Array<any>;
492
+ /**
493
+ * @return {boolean}
494
+ */
495
+ isCountable(): boolean;
496
+ /**
497
+ * @return {ContentMove}
498
+ */
499
+ copy(): ContentMove;
500
+ /**
501
+ * @param {number} _offset
502
+ * @return {ContentMove}
503
+ */
504
+ splice(_offset: number): ContentMove;
505
+ /**
506
+ * @param {ContentMove} _right
507
+ * @return {boolean}
508
+ */
509
+ mergeWith(_right: ContentMove): boolean;
510
+ /**
511
+ * @param {Transaction} transaction
512
+ * @param {Item} item
513
+ */
514
+ integrate(transaction: Transaction, item: Item): void;
515
+ /**
516
+ * @param {Transaction} transaction
517
+ * @param {Item} item
518
+ */
519
+ delete(transaction: Transaction, item: Item): void;
520
+ /**
521
+ * @param {Transaction} _tr
522
+ */
523
+ gc(_tr: Transaction): void;
524
+ /**
525
+ * @param {UpdateEncoder} encoder
526
+ * @param {number} _offset
527
+ * @param {number} _offsetEnd
528
+ */
529
+ write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number): void;
530
+ /**
531
+ * @return {12}
532
+ */
533
+ getRef(): 12;
534
+ }
535
+ export function readFormatValue(decoder: UpdateDecoder, key: string, id: ID): any;
353
536
  export class ContentFormat {
354
537
  /**
355
538
  * @param {string} key
@@ -401,8 +584,9 @@ export class ContentFormat {
401
584
  * @param {UpdateEncoder} encoder
402
585
  * @param {number} _offset
403
586
  * @param {number} _offsetEnd
587
+ * @param {Item} [item] YP25: the item, whose id a mark's operation id usually is
404
588
  */
405
- write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number): void;
589
+ write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number, item?: Item): void;
406
590
  /**
407
591
  * @return {6}
408
592
  */
@@ -9,6 +9,7 @@
9
9
  * @property {function(Uint8Array<ArrayBuffer>, any, Doc, Transaction):void} DocEvents.update
10
10
  * @property {function(Doc):void} DocEvents.beforeAllTransactions
11
11
  * @property {function(Transaction, Doc):void} DocEvents.beforeTransaction
12
+ * @property {function(Transaction, Doc):void} DocEvents.beforeCommit
12
13
  * @property {function(Transaction, Doc):void} DocEvents.commit
13
14
  * @property {function(Transaction, Doc):void} DocEvents.afterTransaction
14
15
  * @property {function(Doc, Array<Transaction>):void} DocEvents.afterAllTransactions
@@ -41,11 +42,12 @@ export class Doc extends ObservableV2<DocEvents> {
41
42
  keepReplaced: ((item: import("../structs/Item.js").Item) => boolean) | null;
42
43
  clientID: number;
43
44
  /**
44
- * YP13: the greatest Lamport timestamp of a paired mark this document
45
- * integrated (see `utils/marks.js`).
45
+ * YP13, YP22: the greatest Lamport timestamp of a paired mark or a move
46
+ * record this document integrated (see `utils/marks.js`,
47
+ * `structs/Item.js` `ContentMove`); the next one it writes takes `_clock + 1`.
46
48
  * @type {number}
47
49
  */
48
- _markClock: number;
50
+ _clock: number;
49
51
  /**
50
52
  * @type {Map<string, YNode>}
51
53
  */
@@ -97,6 +99,7 @@ export type DocEvents = {
97
99
  update: (arg0: Uint8Array<ArrayBuffer>, arg1: any, arg2: Doc, arg3: Transaction) => void;
98
100
  beforeAllTransactions: (arg0: Doc) => void;
99
101
  beforeTransaction: (arg0: Transaction, arg1: Doc) => void;
102
+ beforeCommit: (arg0: Transaction, arg1: Doc) => void;
100
103
  commit: (arg0: Transaction, arg1: Doc) => void;
101
104
  afterTransaction: (arg0: Transaction, arg1: Doc) => void;
102
105
  afterAllTransactions: (arg0: Doc, arg1: Array<Transaction>) => void;
@@ -14,6 +14,11 @@ export class StructStore {
14
14
  * @type {null | Uint8Array<ArrayBuffer>}
15
15
  */
16
16
  pendingDs: null | Uint8Array<ArrayBuffer>;
17
+ /**
18
+ * YP20: holds whose items have not arrived, `client → [clock, len, delta, …]`.
19
+ * @type {Map<number, Array<number>>|null}
20
+ */
21
+ pendingHolds: Map<number, Array<number>> | null;
17
22
  skips: import("./ids.js").IdSet;
18
23
  get ds(): import("./ids.js").IdSet;
19
24
  /**
@@ -21,13 +26,6 @@ export class StructStore {
21
26
  * @function
22
27
  */
23
28
  add(struct: GC | Item | Skip): void;
24
- /**
25
- * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
26
- *
27
- * @param {ID} id
28
- * @return {GC|Item}
29
- */
30
- get(id: ID): GC | Item;
31
29
  /**
32
30
  * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
33
31
  *
@@ -45,17 +43,6 @@ export class StructStore {
45
43
  * @function
46
44
  */
47
45
  public getClock(client: number): number;
48
- /**
49
- * Perform a binary search on a sorted array
50
- * @param {ID} id
51
- * @return {{ structs: Array<GC|Item|Skip>, index: number }}
52
- *
53
- * @function
54
- */
55
- getIndex(id: ID): {
56
- structs: Array<GC | Item | Skip>;
57
- index: number;
58
- };
59
46
  }
60
47
  export function getStateVector(store: StructStore): Map<number, number>;
61
48
  import { Skip } from '../structs/Skip.js';
@@ -5,7 +5,8 @@ export const generateNewClientId: typeof random.uint53;
5
5
  * minimize the number of messages sent.
6
6
  *
7
7
  * YP19: a commit is told through the document's events (`commit`, then
8
- * `afterTransaction`); nodes have no observers.
8
+ * `afterTransaction`); nodes have no observers. YP30: `beforeCommit` runs
9
+ * before them, inside the transaction.
9
10
  *
10
11
  * @public
11
12
  */
@@ -29,6 +30,19 @@ export class Transaction {
29
30
  * Describes the set of inserted items by ids
30
31
  */
31
32
  insertSet: import("./ids.js").IdSet;
33
+ /**
34
+ * YP20: the visibility changes hold records made, in order: per item,
35
+ * `client, clock, len` (`len > 0`: shown, `< 0`: hidden; an item removed
36
+ * while held is logged shown, as the delete set counts it hidden).
37
+ * @type {Array<number>}
38
+ */
39
+ holds: Array<number>;
40
+ /**
41
+ * YP22: the units whose mover changed (a move record integrated or
42
+ * deleted, a moved unit removed), in order: per item `client, clock, len`.
43
+ * @type {Array<number>}
44
+ */
45
+ moves: Array<number>;
32
46
  /**
33
47
  * All types that were directly modified (property added or child
34
48
  * inserted/deleted). New types are not included in this Set.
@@ -9,6 +9,12 @@ export class IdSetDecoder {
9
9
  private dsCurrVal;
10
10
  restDecoder: decoding.Decoder<ArrayBufferLike>;
11
11
  resetDsCurVal(): void;
12
+ /**
13
+ * YP26: the client of a delete set's ranges.
14
+ *
15
+ * @return {number}
16
+ */
17
+ readDsClient(): number;
12
18
  /**
13
19
  * @return {number}
14
20
  */
@@ -26,15 +32,18 @@ export class UpdateDecoder extends IdSetDecoder {
26
32
  * @type {Array<string>}
27
33
  */
28
34
  keys: Array<string>;
29
- keyClockDecoder: decoding.IntDiffOptRleDecoder;
35
+ keyClockDecoder: decoding.UintOptRleDecoder;
30
36
  clientDecoder: decoding.UintOptRleDecoder;
31
37
  leftClockDecoder: decoding.IntDiffOptRleDecoder;
32
38
  rightClockDecoder: decoding.IntDiffOptRleDecoder;
33
39
  infoDecoder: decoding.RleDecoder<number>;
34
40
  stringDecoder: decoding.StringDecoder;
35
- parentInfoDecoder: decoding.RleDecoder<number>;
36
41
  typeRefDecoder: decoding.UintOptRleDecoder;
37
42
  lenDecoder: decoding.UintOptRleDecoder;
43
+ /**
44
+ * @type {Array<number>}
45
+ */
46
+ clients: Array<number>;
38
47
  /**
39
48
  * @return {ID}
40
49
  */
@@ -46,6 +55,9 @@ export class UpdateDecoder extends IdSetDecoder {
46
55
  /**
47
56
  * Read the next client id.
48
57
  * Use this in favor of readID whenever possible to reduce the number of objects created.
58
+ * YP26: an index in the update's client table (a new one's id follows it).
59
+ *
60
+ * @return {number}
49
61
  */
50
62
  readClient(): number;
51
63
  /**
@@ -56,10 +68,6 @@ export class UpdateDecoder extends IdSetDecoder {
56
68
  * @return {string}
57
69
  */
58
70
  readString(): string;
59
- /**
60
- * @return {boolean}
61
- */
62
- readParentInfo(): boolean;
63
71
  /**
64
72
  * @return {number} An unsigned 8-bit integer
65
73
  */
@@ -1,8 +1,19 @@
1
+ /**
2
+ * The update encoding this fork writes and reads, in upstream's reserved
3
+ * feature-flag varuint (upstream writes `0`): `1`, a string table per update.
4
+ */
5
+ export const UPDATE_ENCODING: 1;
1
6
  export class IdSetEncoder {
2
7
  restEncoder: encoding.Encoder;
3
8
  dsCurrVal: number;
4
9
  toUint8Array(): Uint8Array<ArrayBuffer>;
5
10
  resetIdSetCurVal(): void;
11
+ /**
12
+ * YP26: the client of a delete set's ranges.
13
+ *
14
+ * @param {number} client
15
+ */
16
+ writeDsClient(client: number): void;
6
17
  /**
7
18
  * @param {number} clock
8
19
  */
@@ -24,15 +35,28 @@ export class UpdateEncoder extends IdSetEncoder {
24
35
  * @type {number}
25
36
  */
26
37
  keyClock: number;
27
- keyClockEncoder: encoding.IntDiffOptRleEncoder;
38
+ keyClockEncoder: encoding.UintOptRleEncoder;
28
39
  clientEncoder: encoding.UintOptRleEncoder;
29
40
  leftClockEncoder: encoding.IntDiffOptRleEncoder;
30
41
  rightClockEncoder: encoding.IntDiffOptRleEncoder;
31
42
  infoEncoder: encoding.RleEncoder<number>;
32
43
  stringEncoder: encoding.StringEncoder;
33
- parentInfoEncoder: encoding.RleEncoder<number>;
34
44
  typeRefEncoder: encoding.UintOptRleEncoder;
35
45
  lenEncoder: encoding.UintOptRleEncoder;
46
+ /**
47
+ * Each client's index, in first-use order.
48
+ *
49
+ * @type {Map<number,number>}
50
+ */
51
+ clientTable: Map<number, number>;
52
+ /**
53
+ * YP26: write `client` to the client column as its index in the update's
54
+ * client table, in first-use order: a new client's index (the table's
55
+ * size) is followed by its id, once.
56
+ *
57
+ * @param {number} client
58
+ */
59
+ clientIndex(client: number): void;
36
60
  /**
37
61
  * @param {ID} id
38
62
  */
@@ -53,10 +77,6 @@ export class UpdateEncoder extends IdSetEncoder {
53
77
  * @param {string} s
54
78
  */
55
79
  writeString(s: string): void;
56
- /**
57
- * @param {boolean} isYKey
58
- */
59
- writeParentInfo(isYKey: boolean): void;
60
80
  /**
61
81
  * @param {number} info An unsigned 8-bit integer
62
82
  */
@@ -85,6 +105,13 @@ export class UpdateEncoder extends IdSetEncoder {
85
105
  *
86
106
  * We cache these keys in a Map and refer to them via a unique number.
87
107
  *
108
+ * YP24: the cache is on (upstream left it off for decoders older than its
109
+ * own), and every map key, root name and string of a content value goes
110
+ * through it: an update writes each distinct string once. The key column
111
+ * says `0` for a new string (the next in the string column) and the index
112
+ * of a known one plus one, so a key repeated block after block is the same
113
+ * small number every time.
114
+ *
88
115
  * @param {string} key
89
116
  */
90
117
  writeKey(key: string): void;
@@ -21,27 +21,6 @@ export class IdRange {
21
21
  */
22
22
  copyWith(clock: number, len: number): IdRange;
23
23
  }
24
- export class MaybeIdRange {
25
- /**
26
- * @param {number} clock
27
- * @param {number} len
28
- * @param {boolean} exists
29
- */
30
- constructor(clock: number, len: number, exists: boolean);
31
- /**
32
- * @type {number}
33
- */
34
- clock: number;
35
- /**
36
- * @type {number}
37
- */
38
- len: number;
39
- /**
40
- * @type {boolean}
41
- */
42
- exists: boolean;
43
- }
44
- export function createMaybeIdRange(clock: number, len: number, exists: boolean): MaybeIdRange;
45
24
  export class IdRanges {
46
25
  /**
47
26
  * @param {Array<IdRange>} ids
@@ -69,19 +48,12 @@ export class IdRanges {
69
48
  */
70
49
  getIds(): IdRange[];
71
50
  }
72
- /**
73
- * @implements {traits.EqualityTrait}
74
- */
75
- export class IdSet implements traits.EqualityTrait {
51
+ export class IdSet {
76
52
  /**
77
53
  * @type {Map<number,IdRanges>}
78
54
  */
79
55
  clients: Map<number, IdRanges>;
80
56
  isEmpty(): boolean;
81
- /**
82
- * @param {(idrange:IdRange, client:number) => void} f
83
- */
84
- forEach(f: (idrange: IdRange, client: number) => void): void;
85
57
  /**
86
58
  * @param {ID} id
87
59
  * @return {boolean}
@@ -102,37 +74,6 @@ export class IdSet implements traits.EqualityTrait {
102
74
  * @return {boolean}
103
75
  */
104
76
  intersects(client: number, clock: number, len: number): boolean;
105
- /**
106
- * Whether the entire range `[clock, clock+len)` of `client` is contained in this set.
107
- * Allocation-free (binary search). Because `getIds()` returns maximal, merged ranges, full
108
- * coverage of a range implies it lies within a single range.
109
- *
110
- * @param {number} client
111
- * @param {number} clock
112
- * @param {number} len
113
- * @return {boolean}
114
- */
115
- covers(client: number, clock: number, len: number): boolean;
116
- /**
117
- * Total number of ids in `[clock, clock+len)` of `client` contained in this set.
118
- * Allocation-free (binary search + linear scan of the overlapping ranges). Equivalent to
119
- * `slice(client, clock, len).reduce((s, r) => r.exists ? s + r.len : s, 0)` without allocating.
120
- *
121
- * @param {number} client
122
- * @param {number} clock
123
- * @param {number} len
124
- * @return {number}
125
- */
126
- coveredLength(client: number, clock: number, len: number): number;
127
- /**
128
- * Return slices of ids that exist in this idset.
129
- *
130
- * @param {number} client
131
- * @param {number} clock
132
- * @param {number} len
133
- * @return {Array<MaybeIdRange>}
134
- */
135
- slice(client: number, clock: number, len: number): Array<MaybeIdRange>;
136
77
  /**
137
78
  * @param {number} client
138
79
  * @param {number} clock
@@ -145,10 +86,6 @@ export class IdSet implements traits.EqualityTrait {
145
86
  * @param {number} len
146
87
  */
147
88
  delete(client: number, clock: number, len: number): void;
148
- /**
149
- * @param {any} other
150
- */
151
- [traits.EqualityTraitSymbol](other: any): boolean;
152
89
  }
153
90
  export function _deleteRangeFromIdSet(set: IdSet, client: number, clock: number, len: number): void;
154
91
  export function iterateStructsByIdSet(transaction: Transaction, ds: IdSet, f: (arg0: GC | Item) => void): void;
@@ -179,4 +116,3 @@ export type ContentIds = {
179
116
  inserts: IdSet;
180
117
  deletes: IdSet;
181
118
  };
182
- import * as traits from 'lib0-v14/traits';
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @typedef {import('./Transaction.js').Transaction} Transaction
3
+ */
1
4
  /**
2
5
  * Paired marks — an edytor fork addition (UPSTREAM.md YP13), not upstream source.
3
6
  *
@@ -80,4 +83,6 @@ export function foldPaired(formats: Map<string, any>, content: {
80
83
  }): boolean;
81
84
  export function formatValue(value: any): any;
82
85
  export function markClass(item: any): number;
83
- export function sortsBefore(o: any, item: any): boolean;
86
+ export function sequenceOrder(x: any, y: any): number;
87
+ export function sortsBefore(o: any, item: any, tr: Transaction): boolean;
88
+ export type Transaction = import("./Transaction.js").Transaction;