edytor 3.0.0 → 5.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 (231) hide show
  1. package/README.md +2 -2
  2. package/dist/block/block.svelte.js +6 -21
  3. package/dist/block/inlineBlock.svelte.js +4 -6
  4. package/dist/clipboard/moveText.js +6 -8
  5. package/dist/cloudflare/DocumentRoom.d.ts +23 -12
  6. package/dist/cloudflare/DocumentRoom.js +10 -6
  7. package/dist/cloudflare/index.d.ts +1 -1
  8. package/dist/cloudflare/room/access.d.ts +8 -3
  9. package/dist/cloudflare/room/access.js +44 -20
  10. package/dist/cloudflare/room/admission.js +28 -5
  11. package/dist/cloudflare/room/comments.js +28 -1
  12. package/dist/cloudflare/room/context.d.ts +139 -129
  13. package/dist/cloudflare/room/context.js +11 -4
  14. package/dist/cloudflare/room/forged.d.ts +14 -0
  15. package/dist/cloudflare/room/forged.js +30 -2
  16. package/dist/cloudflare/room/frames.d.ts +4 -0
  17. package/dist/cloudflare/room/frames.js +5 -1
  18. package/dist/cloudflare/room/purge.d.ts +6 -3
  19. package/dist/cloudflare/room/purge.js +45 -19
  20. package/dist/cloudflare/room/replicas.d.ts +4 -2
  21. package/dist/cloudflare/room/replicas.js +8 -3
  22. package/dist/cloudflare/room/suggest.d.ts +7 -0
  23. package/dist/cloudflare/room/suggest.js +143 -0
  24. package/dist/cloudflare/room/updates.d.ts +3 -4
  25. package/dist/cloudflare/room/updates.js +6 -8
  26. package/dist/cloudflare/routeDocumentSocket.d.ts +10 -1
  27. package/dist/cloudflare/routeDocumentSocket.js +5 -3
  28. package/dist/components/Content.svelte +9 -1
  29. package/dist/crdt/anchors.js +3 -2
  30. package/dist/crdt/attribution/attribution.d.ts +34 -12
  31. package/dist/crdt/attribution/attribution.js +59 -21
  32. package/dist/crdt/attribution/block.d.ts +3 -3
  33. package/dist/crdt/attribution/block.js +7 -8
  34. package/dist/crdt/attribution/index.d.ts +1 -1
  35. package/dist/crdt/attribution/index.js +1 -1
  36. package/dist/crdt/data.d.ts +62 -31
  37. package/dist/crdt/data.js +211 -103
  38. package/dist/crdt/doc/capability.js +9 -13
  39. package/dist/crdt/doc/delete.d.ts +1 -1
  40. package/dist/crdt/doc/delete.js +13 -30
  41. package/dist/crdt/doc/funnel.d.ts +1 -1
  42. package/dist/crdt/doc/funnel.js +34 -26
  43. package/dist/crdt/doc/gate.d.ts +3 -3
  44. package/dist/crdt/doc/history.d.ts +31 -9
  45. package/dist/crdt/doc/history.js +204 -73
  46. package/dist/crdt/doc/layout.js +16 -27
  47. package/dist/crdt/doc/meta.js +17 -23
  48. package/dist/crdt/doc/moves.d.ts +1 -1
  49. package/dist/crdt/doc/moves.js +52 -32
  50. package/dist/crdt/doc/reads.d.ts +2 -2
  51. package/dist/crdt/doc/reads.js +20 -30
  52. package/dist/crdt/doc/seed.js +2 -2
  53. package/dist/crdt/doc/split-merge.js +12 -15
  54. package/dist/crdt/doc/steps.d.ts +25 -13
  55. package/dist/crdt/doc/steps.js +55 -125
  56. package/dist/crdt/doc/suggest.d.ts +167 -0
  57. package/dist/crdt/doc/suggest.js +579 -0
  58. package/dist/crdt/doc/types.d.ts +21 -9
  59. package/dist/crdt/document.d.ts +26 -6
  60. package/dist/crdt/document.js +40 -15
  61. package/dist/crdt/edytor-doc.d.ts +410 -390
  62. package/dist/crdt/edytor-doc.js +143 -95
  63. package/dist/crdt/engine-api.d.ts +39 -1
  64. package/dist/crdt/engine.d.ts +2 -2
  65. package/dist/crdt/engine.js +4 -5
  66. package/dist/crdt/flow.d.ts +2 -2
  67. package/dist/crdt/flow.js +29 -37
  68. package/dist/crdt/index.d.ts +134 -127
  69. package/dist/crdt/index.js +4 -1
  70. package/dist/crdt/operations.d.ts +12 -3
  71. package/dist/crdt/parts.d.ts +43 -0
  72. package/dist/crdt/parts.js +44 -0
  73. package/dist/crdt/placement/display.d.ts +6 -31
  74. package/dist/crdt/placement/display.js +41 -146
  75. package/dist/crdt/placement/keys.d.ts +63 -0
  76. package/dist/crdt/placement/keys.js +95 -0
  77. package/dist/crdt/placement/model.d.ts +119 -118
  78. package/dist/crdt/placement/model.js +242 -142
  79. package/dist/crdt/placement/resolve.d.ts +123 -35
  80. package/dist/crdt/placement/resolve.js +188 -153
  81. package/dist/crdt/placement/slots.d.ts +134 -0
  82. package/dist/crdt/placement/slots.js +152 -0
  83. package/dist/crdt/protocol.d.ts +1 -1
  84. package/dist/crdt/protocol.js +1 -1
  85. package/dist/crdt/protocols/auth.d.ts +11 -1
  86. package/dist/crdt/protocols/auth.js +17 -1
  87. package/dist/crdt/protocols/comments.d.ts +16 -1
  88. package/dist/crdt/protocols/comments.js +9 -1
  89. package/dist/crdt/providers/index.d.ts +6 -4
  90. package/dist/crdt/providers/index.js +3 -1
  91. package/dist/crdt/providers/room.d.ts +16 -2
  92. package/dist/crdt/providers/room.js +64 -17
  93. package/dist/crdt/providers/websocket.d.ts +6 -4
  94. package/dist/crdt/providers/websocket.js +14 -7
  95. package/dist/crdt/purge.d.ts +24 -9
  96. package/dist/crdt/purge.js +266 -126
  97. package/dist/crdt/restore.d.ts +4 -3
  98. package/dist/crdt/restore.js +27 -34
  99. package/dist/crdt/schema.d.ts +30 -21
  100. package/dist/crdt/schema.js +39 -23
  101. package/dist/crdt/storage.d.ts +1 -1
  102. package/dist/crdt/storage.js +1 -1
  103. package/dist/crdt/structs.d.ts +17 -15
  104. package/dist/crdt/structs.js +10 -22
  105. package/dist/crdt/text/index/cache.js +4 -0
  106. package/dist/crdt/text/index/claims.js +13 -23
  107. package/dist/crdt/text/index/fold.d.ts +2 -3
  108. package/dist/crdt/text/index/fold.js +194 -44
  109. package/dist/crdt/text/index/layout.d.ts +2 -4
  110. package/dist/crdt/text/index/layout.js +14 -30
  111. package/dist/crdt/text/index/placement.d.ts +26 -18
  112. package/dist/crdt/text/index/placement.js +420 -157
  113. package/dist/crdt/text/index/records.d.ts +3 -3
  114. package/dist/crdt/text/index/records.js +24 -31
  115. package/dist/crdt/text/index/shared.d.ts +11 -3
  116. package/dist/crdt/text/index/shared.js +29 -17
  117. package/dist/crdt/text/index/state.d.ts +21 -17
  118. package/dist/crdt/text/index/state.js +15 -17
  119. package/dist/crdt/text/index/streams.d.ts +10 -5
  120. package/dist/crdt/text/index/streams.js +78 -27
  121. package/dist/crdt/text/items.d.ts +10 -3
  122. package/dist/crdt/text/items.js +7 -0
  123. package/dist/crdt/text/model.d.ts +87 -62
  124. package/dist/crdt/text/model.js +91 -169
  125. package/dist/crdt/text/ranges.d.ts +1 -1
  126. package/dist/crdt/text/ranges.js +3 -3
  127. package/dist/crdt/text/rows.d.ts +13 -7
  128. package/dist/crdt/text/rows.js +24 -7
  129. package/dist/crdt/text/runs.d.ts +51 -42
  130. package/dist/crdt/text/runs.js +24 -7
  131. package/dist/crdt/text/streams.d.ts +26 -13
  132. package/dist/crdt/text/streams.js +41 -14
  133. package/dist/crdt/vendor/yjs/UPSTREAM.md +651 -21
  134. package/dist/crdt/vendor/yjs/dts/global.d.ts +2 -0
  135. package/dist/crdt/vendor/yjs/dts/index.d.ts +1 -1
  136. package/dist/crdt/vendor/yjs/dts/structs/AbstractStruct.d.ts +7 -0
  137. package/dist/crdt/vendor/yjs/dts/structs/Item.d.ts +197 -10
  138. package/dist/crdt/vendor/yjs/dts/utils/Doc.d.ts +6 -3
  139. package/dist/crdt/vendor/yjs/dts/utils/StructStore.d.ts +5 -18
  140. package/dist/crdt/vendor/yjs/dts/utils/Transaction.d.ts +15 -1
  141. package/dist/crdt/vendor/yjs/dts/utils/UpdateDecoder.d.ts +14 -6
  142. package/dist/crdt/vendor/yjs/dts/utils/UpdateEncoder.d.ts +33 -6
  143. package/dist/crdt/vendor/yjs/dts/utils/ids.d.ts +1 -65
  144. package/dist/crdt/vendor/yjs/dts/utils/marks.d.ts +6 -1
  145. package/dist/crdt/vendor/yjs/dts/ynode.d.ts +54 -7
  146. package/dist/crdt/vendor/yjs/global.d.ts +2 -0
  147. package/dist/crdt/vendor/yjs/src/index.js +1 -1
  148. package/dist/crdt/vendor/yjs/src/structs/AbstractStruct.js +10 -0
  149. package/dist/crdt/vendor/yjs/src/structs/Item.js +649 -51
  150. package/dist/crdt/vendor/yjs/src/utils/BlockSet.js +18 -9
  151. package/dist/crdt/vendor/yjs/src/utils/Doc.js +5 -3
  152. package/dist/crdt/vendor/yjs/src/utils/StructStore.js +5 -0
  153. package/dist/crdt/vendor/yjs/src/utils/Transaction.js +36 -13
  154. package/dist/crdt/vendor/yjs/src/utils/UpdateDecoder.js +88 -18
  155. package/dist/crdt/vendor/yjs/src/utils/UpdateEncoder.js +119 -32
  156. package/dist/crdt/vendor/yjs/src/utils/encoding.js +13 -1
  157. package/dist/crdt/vendor/yjs/src/utils/ids.js +7 -7
  158. package/dist/crdt/vendor/yjs/src/utils/marks.js +193 -8
  159. package/dist/crdt/vendor/yjs/src/utils/redo.js +1 -1
  160. package/dist/crdt/vendor/yjs/src/utils/transaction-helpers.js +1 -1
  161. package/dist/crdt/vendor/yjs/src/utils/updates.js +3 -3
  162. package/dist/crdt/vendor/yjs/src/ynode.js +199 -12
  163. package/dist/edytor.svelte.d.ts +1 -1
  164. package/dist/edytor.svelte.js +103 -75
  165. package/dist/events/beforeInputCommands.d.ts +2 -2
  166. package/dist/events/beforeInputCommands.js +2 -2
  167. package/dist/events/nativeInteractiveControl.d.ts +11 -1
  168. package/dist/events/nativeInteractiveControl.js +41 -1
  169. package/dist/events/onBeforeInput.js +3 -3
  170. package/dist/events/onFocus.js +9 -11
  171. package/dist/events/onPageHide.d.ts +3 -0
  172. package/dist/events/onPageHide.js +16 -0
  173. package/dist/export/forms.d.ts +50 -50
  174. package/dist/index.d.ts +4 -2
  175. package/dist/index.js +1 -1
  176. package/dist/labels.d.ts +8 -0
  177. package/dist/labels.js +6 -1
  178. package/dist/plugins/comments/CommentsController.svelte.d.ts +5 -1
  179. package/dist/plugins/comments/CommentsController.svelte.js +14 -4
  180. package/dist/plugins/find/search.js +2 -2
  181. package/dist/plugins/index.d.ts +1 -0
  182. package/dist/plugins/index.js +1 -0
  183. package/dist/plugins/suggestions/SuggestionBars.svelte +40 -23
  184. package/dist/plugins/suggestions/SuggestionBars.svelte.d.ts +3 -1
  185. package/dist/plugins/suggestions/SuggestionRuns.svelte +77 -0
  186. package/dist/plugins/suggestions/SuggestionRuns.svelte.d.ts +9 -0
  187. package/dist/plugins/suggestions/shared.svelte.d.ts +58 -0
  188. package/dist/plugins/suggestions/shared.svelte.js +421 -0
  189. package/dist/plugins/suggestions/suggestionsPlugin.d.ts +15 -4
  190. package/dist/selection/domSelection.d.ts +2 -0
  191. package/dist/selection/domSelection.js +6 -2
  192. package/dist/selection/pointer.svelte.js +75 -48
  193. package/dist/selection/replaceSelection.js +2 -6
  194. package/dist/selection/selection.svelte.d.ts +3 -3
  195. package/dist/selection/selection.svelte.js +39 -32
  196. package/dist/selection/selection.utils.d.ts +14 -0
  197. package/dist/selection/selection.utils.js +28 -3
  198. package/dist/session/commands.js +21 -11
  199. package/dist/session/composition.svelte.d.ts +5 -3
  200. package/dist/session/composition.svelte.js +21 -17
  201. package/dist/session/handles.d.ts +4 -17
  202. package/dist/session/handles.js +11 -37
  203. package/dist/session/navigation.js +6 -9
  204. package/dist/session/selection.d.ts +11 -5
  205. package/dist/session/selection.js +14 -48
  206. package/dist/session/suggestions.svelte.d.ts +38 -9
  207. package/dist/session/suggestions.svelte.js +37 -18
  208. package/dist/session/virtual.d.ts +1 -1
  209. package/dist/surface/attributes.d.ts +5 -0
  210. package/dist/surface/attributes.js +2 -2
  211. package/dist/surface/cells.d.ts +2 -26
  212. package/dist/surface/cells.js +2 -33
  213. package/dist/surface/observer.svelte.d.ts +6 -1
  214. package/dist/surface/observer.svelte.js +130 -83
  215. package/dist/surface/pin.svelte.d.ts +9 -9
  216. package/dist/surface/pin.svelte.js +15 -22
  217. package/dist/surface/projector.svelte.d.ts +15 -3
  218. package/dist/surface/projector.svelte.js +67 -22
  219. package/dist/text/text.svelte.js +14 -19
  220. package/dist/themes/notion.css +29 -0
  221. package/package.json +4 -2
  222. package/dist/crdt/placement/rank.d.ts +0 -87
  223. package/dist/crdt/placement/rank.js +0 -332
  224. package/dist/crdt/placement/source.d.ts +0 -43
  225. package/dist/crdt/placement/source.js +0 -66
  226. package/dist/crdt/text/delete-index.d.ts +0 -129
  227. package/dist/crdt/text/delete-index.js +0 -365
  228. package/dist/crdt/text/deletes.d.ts +0 -76
  229. package/dist/crdt/text/deletes.js +0 -362
  230. package/dist/crdt/text/index/anchored.d.ts +0 -17
  231. 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, unhide } 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,160 @@ 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`).
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
+ * @param {Item} item
436
+ */
437
+ delete(transaction: Transaction, item: Item): void;
438
+ /**
439
+ * @param {Transaction} _tr
440
+ */
441
+ gc(_tr: Transaction): void;
442
+ /**
443
+ * @param {UpdateEncoder} encoder
444
+ * @param {number} offset
445
+ * @param {number} offsetEnd
446
+ */
447
+ write(encoder: UpdateEncoder, offset: number, offsetEnd: number): void;
448
+ /**
449
+ * @return {11}
450
+ */
451
+ getRef(): 11;
452
+ }
453
+ export function hideIds(tr: Transaction, ids: Array<number>): void;
454
+ export function unhide(tr: Transaction): void;
455
+ export function applyPending(tr: Transaction, clients: Array<number>): void;
456
+ /**
457
+ * A move record: one countable unit at its destination, naming the units
458
+ * it moves (`client, clock, len` ranges, in the order they show) with a
459
+ * Lamport `priority`, a `side` (`0`: it stands after what precedes it,
460
+ * `1`: before what follows it — its sort class among the items of one
461
+ * origin, `markClass`), and for the sort of two records at one origin
462
+ * (`utils/marks.js` `sourceOrder`) the chain of units it stands at (`at`:
463
+ * the home slots from the root sequence down to that unit, else the first
464
+ * unit it names) and its `part` there. While the record is live, each named unit shows at
465
+ * the record that wins its movers and is hidden at home; deleting the
466
+ * record (an undo) hands the unit to the next record, else home. A record
467
+ * waits for the units it names as an item waits for its origin
468
+ * (`getMissing`), so two records at one origin sort by their units' home
469
+ * order on every replica (`sourceOrder`). Immutable once written, so
470
+ * replicas converge in any order. The record's item is the one integrating
471
+ * or deleting it (it is what the units' `movers` hold).
352
472
  */
473
+ export class ContentMove {
474
+ /**
475
+ * @param {number} priority
476
+ * @param {number} side
477
+ * @param {Array<number>} ids
478
+ * @param {number} [part] the writer's order among the records standing at one unit (0–7)
479
+ * @param {Array<ID>|null} [at] the chain the record stands at, outermost first (`null`: the first unit it names)
480
+ */
481
+ constructor(priority: number, side: number, ids: Array<number>, part?: number, at?: Array<ID> | null);
482
+ priority: number;
483
+ side: number;
484
+ ids: number[];
485
+ part: number;
486
+ at: ID[] | null;
487
+ /**
488
+ * @return {number}
489
+ */
490
+ getLength(): number;
491
+ /**
492
+ * @return {Array<any>}
493
+ */
494
+ getContent(): Array<any>;
495
+ /**
496
+ * @return {boolean}
497
+ */
498
+ isCountable(): boolean;
499
+ /**
500
+ * @return {ContentMove}
501
+ */
502
+ copy(): ContentMove;
503
+ /**
504
+ * @param {number} _offset
505
+ * @return {ContentMove}
506
+ */
507
+ splice(_offset: number): ContentMove;
508
+ /**
509
+ * @param {ContentMove} _right
510
+ * @return {boolean}
511
+ */
512
+ mergeWith(_right: ContentMove): boolean;
513
+ /**
514
+ * @param {Transaction} transaction
515
+ * @param {Item} item
516
+ */
517
+ integrate(transaction: Transaction, item: Item): void;
518
+ /**
519
+ * @param {Transaction} transaction
520
+ * @param {Item} item
521
+ */
522
+ delete(transaction: Transaction, item: Item): void;
523
+ /**
524
+ * @param {Transaction} _tr
525
+ */
526
+ gc(_tr: Transaction): void;
527
+ /**
528
+ * @param {UpdateEncoder} encoder
529
+ * @param {number} _offset
530
+ * @param {number} _offsetEnd
531
+ */
532
+ write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number): void;
533
+ /**
534
+ * @return {12}
535
+ */
536
+ getRef(): 12;
537
+ }
538
+ export function readFormatValue(decoder: UpdateDecoder, key: string, id: ID): any;
353
539
  export class ContentFormat {
354
540
  /**
355
541
  * @param {string} key
@@ -401,8 +587,9 @@ export class ContentFormat {
401
587
  * @param {UpdateEncoder} encoder
402
588
  * @param {number} _offset
403
589
  * @param {number} _offsetEnd
590
+ * @param {Item} [item] YP25: the item, whose id a mark's operation id usually is
404
591
  */
405
- write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number): void;
592
+ write(encoder: UpdateEncoder, _offset: number, _offsetEnd: number, item?: Item): void;
406
593
  /**
407
594
  * @return {6}
408
595
  */
@@ -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;