@y/y 14.0.0-rc.2 → 14.0.0-rc.21

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 (166) hide show
  1. package/README.md +36 -12
  2. package/dist/src/index.d.ts +24 -1
  3. package/dist/src/index.d.ts.map +1 -1
  4. package/dist/src/structs/AbstractStruct.d.ts +14 -17
  5. package/dist/src/structs/AbstractStruct.d.ts.map +1 -1
  6. package/dist/src/structs/GC.d.ts +9 -14
  7. package/dist/src/structs/GC.d.ts.map +1 -1
  8. package/dist/src/structs/Item.d.ts +569 -31
  9. package/dist/src/structs/Item.d.ts.map +1 -1
  10. package/dist/src/structs/Skip.d.ts +9 -11
  11. package/dist/src/structs/Skip.d.ts.map +1 -1
  12. package/dist/src/utils/BlockSet.d.ts +8 -7
  13. package/dist/src/utils/BlockSet.d.ts.map +1 -1
  14. package/dist/src/utils/Doc.d.ts +4 -9
  15. package/dist/src/utils/Doc.d.ts.map +1 -1
  16. package/dist/src/utils/ID.d.ts +0 -1
  17. package/dist/src/utils/ID.d.ts.map +1 -1
  18. package/dist/src/utils/RelativePosition.d.ts +2 -5
  19. package/dist/src/utils/RelativePosition.d.ts.map +1 -1
  20. package/dist/src/utils/Renderer.d.ts +144 -0
  21. package/dist/src/utils/Renderer.d.ts.map +1 -0
  22. package/dist/src/utils/Snapshot.d.ts +7 -11
  23. package/dist/src/utils/Snapshot.d.ts.map +1 -1
  24. package/dist/src/utils/StructStore.d.ts +45 -23
  25. package/dist/src/utils/StructStore.d.ts.map +1 -1
  26. package/dist/src/utils/Transaction.d.ts +11 -21
  27. package/dist/src/utils/Transaction.d.ts.map +1 -1
  28. package/dist/src/utils/UndoManager.d.ts +13 -14
  29. package/dist/src/utils/UndoManager.d.ts.map +1 -1
  30. package/dist/src/utils/UpdateDecoder.d.ts +1 -1
  31. package/dist/src/utils/UpdateDecoder.d.ts.map +1 -1
  32. package/dist/src/utils/UpdateEncoder.d.ts +0 -1
  33. package/dist/src/utils/UpdateEncoder.d.ts.map +1 -1
  34. package/dist/src/utils/YEvent.d.ts +22 -26
  35. package/dist/src/utils/YEvent.d.ts.map +1 -1
  36. package/dist/src/utils/content-helper.d.ts +2 -0
  37. package/dist/src/utils/content-helper.d.ts.map +1 -0
  38. package/dist/src/utils/delta-helpers.d.ts +2 -3
  39. package/dist/src/utils/delta-helpers.d.ts.map +1 -1
  40. package/dist/src/utils/encoding-helpers.d.ts +6 -0
  41. package/dist/src/utils/encoding-helpers.d.ts.map +1 -0
  42. package/dist/src/utils/encoding.d.ts +16 -18
  43. package/dist/src/utils/encoding.d.ts.map +1 -1
  44. package/dist/src/utils/ids.d.ts +331 -0
  45. package/dist/src/utils/ids.d.ts.map +1 -0
  46. package/dist/src/utils/isParentOf.d.ts +1 -2
  47. package/dist/src/utils/isParentOf.d.ts.map +1 -1
  48. package/dist/src/utils/logging.d.ts +0 -1
  49. package/dist/src/utils/logging.d.ts.map +1 -1
  50. package/dist/src/utils/meta.d.ts +15 -64
  51. package/dist/src/utils/meta.d.ts.map +1 -1
  52. package/dist/src/utils/renderer-helpers.d.ts +99 -0
  53. package/dist/src/utils/renderer-helpers.d.ts.map +1 -0
  54. package/dist/src/utils/schemas.d.ts +3 -0
  55. package/dist/src/utils/schemas.d.ts.map +1 -0
  56. package/dist/src/utils/transaction-helpers.d.ts +18 -0
  57. package/dist/src/utils/transaction-helpers.d.ts.map +1 -0
  58. package/dist/src/utils/updates.d.ts +19 -25
  59. package/dist/src/utils/updates.d.ts.map +1 -1
  60. package/dist/src/ytype.d.ts +144 -41
  61. package/dist/src/ytype.d.ts.map +1 -1
  62. package/global.d.ts +53 -0
  63. package/package.json +12 -16
  64. package/src/index.js +32 -124
  65. package/src/structs/AbstractStruct.js +21 -16
  66. package/src/structs/GC.js +15 -20
  67. package/src/structs/Item.js +992 -318
  68. package/src/structs/Skip.js +16 -19
  69. package/src/utils/BlockSet.js +20 -20
  70. package/src/utils/Doc.js +18 -29
  71. package/src/utils/ID.js +0 -2
  72. package/src/utils/RelativePosition.js +15 -25
  73. package/src/utils/{AttributionManager.js → Renderer.js} +42 -197
  74. package/src/utils/Snapshot.js +15 -37
  75. package/src/utils/StructStore.js +89 -227
  76. package/src/utils/Transaction.js +89 -321
  77. package/src/utils/UndoManager.js +157 -19
  78. package/src/utils/UpdateDecoder.js +2 -3
  79. package/src/utils/UpdateEncoder.js +0 -4
  80. package/src/utils/YEvent.js +20 -26
  81. package/src/utils/content-helper.js +0 -0
  82. package/src/utils/delta-helpers.js +21 -42
  83. package/src/utils/encoding-helpers.js +110 -0
  84. package/src/utils/encoding.js +197 -122
  85. package/src/utils/ids.js +1527 -0
  86. package/src/utils/isParentOf.js +2 -4
  87. package/src/utils/logging.js +0 -4
  88. package/src/utils/meta.js +57 -46
  89. package/src/utils/renderer-helpers.js +110 -0
  90. package/src/utils/schemas.js +3 -0
  91. package/src/utils/transaction-helpers.js +413 -0
  92. package/src/utils/updates.js +24 -146
  93. package/src/ytype.js +626 -255
  94. package/tests/testHelper.js +10 -12
  95. package/dist/src/internals.d.ts +0 -36
  96. package/dist/src/internals.d.ts.map +0 -1
  97. package/dist/src/structs/ContentAny.d.ts +0 -67
  98. package/dist/src/structs/ContentAny.d.ts.map +0 -1
  99. package/dist/src/structs/ContentBinary.d.ts +0 -64
  100. package/dist/src/structs/ContentBinary.d.ts.map +0 -1
  101. package/dist/src/structs/ContentDeleted.d.ts +0 -64
  102. package/dist/src/structs/ContentDeleted.d.ts.map +0 -1
  103. package/dist/src/structs/ContentDoc.d.ts +0 -72
  104. package/dist/src/structs/ContentDoc.d.ts.map +0 -1
  105. package/dist/src/structs/ContentEmbed.d.ts +0 -67
  106. package/dist/src/structs/ContentEmbed.d.ts.map +0 -1
  107. package/dist/src/structs/ContentFormat.d.ts +0 -69
  108. package/dist/src/structs/ContentFormat.d.ts.map +0 -1
  109. package/dist/src/structs/ContentJSON.d.ts +0 -70
  110. package/dist/src/structs/ContentJSON.d.ts.map +0 -1
  111. package/dist/src/structs/ContentString.d.ts +0 -70
  112. package/dist/src/structs/ContentString.d.ts.map +0 -1
  113. package/dist/src/structs/ContentType.d.ts +0 -77
  114. package/dist/src/structs/ContentType.d.ts.map +0 -1
  115. package/dist/src/utils/AttributionManager.d.ts +0 -238
  116. package/dist/src/utils/AttributionManager.d.ts.map +0 -1
  117. package/dist/src/utils/IdMap.d.ts +0 -164
  118. package/dist/src/utils/IdMap.d.ts.map +0 -1
  119. package/dist/src/utils/IdSet.d.ts +0 -163
  120. package/dist/src/utils/IdSet.d.ts.map +0 -1
  121. package/dist/tests/IdMap.tests.d.ts +0 -9
  122. package/dist/tests/IdMap.tests.d.ts.map +0 -1
  123. package/dist/tests/IdSet.tests.d.ts +0 -9
  124. package/dist/tests/IdSet.tests.d.ts.map +0 -1
  125. package/dist/tests/attribution.tests.d.ts +0 -9
  126. package/dist/tests/attribution.tests.d.ts.map +0 -1
  127. package/dist/tests/compatibility.tests.d.ts +0 -5
  128. package/dist/tests/compatibility.tests.d.ts.map +0 -1
  129. package/dist/tests/delta.tests.d.ts +0 -7
  130. package/dist/tests/delta.tests.d.ts.map +0 -1
  131. package/dist/tests/doc.tests.d.ts +0 -13
  132. package/dist/tests/doc.tests.d.ts.map +0 -1
  133. package/dist/tests/encoding.tests.d.ts +0 -5
  134. package/dist/tests/encoding.tests.d.ts.map +0 -1
  135. package/dist/tests/index.d.ts +0 -2
  136. package/dist/tests/index.d.ts.map +0 -1
  137. package/dist/tests/relativePositions.tests.d.ts +0 -11
  138. package/dist/tests/relativePositions.tests.d.ts.map +0 -1
  139. package/dist/tests/snapshot.tests.d.ts +0 -14
  140. package/dist/tests/snapshot.tests.d.ts.map +0 -1
  141. package/dist/tests/testHelper.d.ts +0 -171
  142. package/dist/tests/testHelper.d.ts.map +0 -1
  143. package/dist/tests/undo-redo.tests.d.ts +0 -27
  144. package/dist/tests/undo-redo.tests.d.ts.map +0 -1
  145. package/dist/tests/updates.tests.d.ts +0 -26
  146. package/dist/tests/updates.tests.d.ts.map +0 -1
  147. package/dist/tests/y-array.tests.d.ts +0 -43
  148. package/dist/tests/y-array.tests.d.ts.map +0 -1
  149. package/dist/tests/y-map.tests.d.ts +0 -42
  150. package/dist/tests/y-map.tests.d.ts.map +0 -1
  151. package/dist/tests/y-text.tests.d.ts +0 -49
  152. package/dist/tests/y-text.tests.d.ts.map +0 -1
  153. package/dist/tests/y-xml.tests.d.ts +0 -14
  154. package/dist/tests/y-xml.tests.d.ts.map +0 -1
  155. package/src/internals.js +0 -35
  156. package/src/structs/ContentAny.js +0 -115
  157. package/src/structs/ContentBinary.js +0 -93
  158. package/src/structs/ContentDeleted.js +0 -101
  159. package/src/structs/ContentDoc.js +0 -141
  160. package/src/structs/ContentEmbed.js +0 -98
  161. package/src/structs/ContentFormat.js +0 -105
  162. package/src/structs/ContentJSON.js +0 -119
  163. package/src/structs/ContentString.js +0 -113
  164. package/src/structs/ContentType.js +0 -152
  165. package/src/utils/IdMap.js +0 -673
  166. package/src/utils/IdSet.js +0 -825
@@ -1,154 +1,26 @@
1
- import {
2
- getItem,
3
- diffIdSet,
4
- createInsertSetFromStructStore,
5
- createDeleteSetFromStructStore,
6
- createIdMapFromIdSet,
7
- ContentDeleted,
8
- insertIntoIdMap,
9
- insertIntoIdSet,
10
- diffIdMap,
11
- createIdMap,
12
- mergeIdMaps,
13
- createID,
14
- mergeIdSets,
15
- applyUpdate,
16
- writeIdSet,
17
- UpdateEncoderV1,
18
- transact,
19
- createMaybeAttrRange,
20
- createIdSet,
21
- writeStructsFromIdSet,
22
- UndoManager,
23
- StackItem,
24
- getItemCleanStart,
25
- intersectSets,
26
- intersectMaps,
27
- ContentFormat,
28
- createContentAttribute,
29
- StructStore, Transaction, ID, IdSet, Item, Snapshot, Doc, AbstractContent, IdMap, // eslint-disable-line
30
- encodeStateAsUpdate
31
- } from '../internals.js'
32
-
33
- import * as error from 'lib0/error'
34
1
  import { ObservableV2 } from 'lib0/observable'
35
2
  import * as encoding from 'lib0/encoding'
36
- import * as s from 'lib0/schema'
37
-
38
- export const attributionJsonSchema = s.$object({
39
- insert: s.$array(s.$string).optional,
40
- insertedAt: s.$number.optional,
41
- delete: s.$array(s.$string).optional,
42
- deletedAt: s.$number.optional,
43
- format: s.$record(s.$string, s.$array(s.$string)).optional,
44
- formatAt: s.$number.optional
45
- })
46
3
 
47
- /**
48
- * @todo rename this to `insertBy`, `insertAt`, ..
49
- *
50
- * @typedef {s.Unwrap<typeof attributionJsonSchema>} Attribution
51
- */
52
-
53
- /**
54
- * @todo SHOULD NOT RETURN AN OBJECT!
55
- * @param {Array<import('./IdMap.js').ContentAttribute<any>>?} attrs
56
- * @param {boolean} deleted - whether the attributed item is deleted
57
- * @return {Attribution?}
58
- */
59
- export const createAttributionFromAttributionItems = (attrs, deleted) => {
60
- if (attrs == null) {
61
- return null
62
- }
63
- /**
64
- * @type {Attribution}
65
- */
66
- const attribution = {}
67
- if (deleted) {
68
- attribution.delete = []
69
- } else {
70
- attribution.insert = []
71
- }
72
- attrs.forEach(attr => {
73
- switch (attr.name) {
74
- // eslint-disable-next-line no-fallthrough
75
- case 'insert':
76
- case 'delete': {
77
- // needs to be non-ambiguous: don't add existing attr if it doesn't match the actual status
78
- attribution[attr.name]?.push(attr.val)
79
- break
80
- }
81
- default: {
82
- if (attr.name[0] !== '_') {
83
- /** @type {any} */ (attribution)[attr.name] = attr.val
84
- }
85
- }
86
- }
87
- })
88
- return attribution
89
- }
4
+ import { getItemCleanStart } from './transaction-helpers.js'
5
+ import { diffIdSet, createInsertSetFromStructStore, createDeleteSetFromStructStore, insertIntoIdSet, mergeIdSets, intersectSets, createIdSet, writeIdSet, createIdMapFromIdSet, insertIntoIdMap, diffIdMap, createIdMap, mergeIdMaps, intersectMaps, createMaybeAttrRange, createContentAttribute } from './ids.js'
6
+ import { ContentDeleted, ContentFormat } from '../structs/Item.js'
7
+ import { createID } from './ID.js'
8
+ import { writeStructsFromIdSet } from './encoding-helpers.js'
9
+ import { applyUpdate, encodeStateAsUpdate } from './encoding.js'
10
+ import { UpdateEncoderV1 } from './UpdateEncoder.js'
11
+ import { transact } from './Transaction.js'
12
+ import { UndoManager, StackItem } from './UndoManager.js'
90
13
 
91
- /**
92
- * @template T
93
- */
94
- export class AttributedContent {
95
- /**
96
- * @param {AbstractContent} content
97
- * @param {number} clock
98
- * @param {boolean} deleted
99
- * @param {Array<import('./IdMap.js').ContentAttribute<T>> | null} attrs
100
- * @param {0|1|2} renderBehavior
101
- */
102
- constructor (content, clock, deleted, attrs, renderBehavior) {
103
- this.content = content
104
- this.clock = clock
105
- this.deleted = deleted
106
- this.attrs = attrs
107
- this.render = renderBehavior === 0 ? false : (renderBehavior === 1 ? (!deleted || attrs != null) : true)
108
- }
109
- }
110
-
111
- /**
112
- * Abstract class for associating Attributions to content / changes
113
- *
114
- * Should fire an event when the attributions changed _after_ the original change happens. This
115
- * Event will be used to update the attribution on the current content.
116
- *
117
- * @extends {ObservableV2<{change:(idset:IdSet,origin:any,local:boolean)=>void}>}
118
- */
119
- export class AbstractAttributionManager extends ObservableV2 {
120
- /**
121
- * @param {Array<AttributedContent<any>>} _contents - where to write the result
122
- * @param {number} _client
123
- * @param {number} _clock
124
- * @param {boolean} _deleted
125
- * @param {AbstractContent} _content
126
- * @param {0|1|2} _shouldRender - 0: if undeleted or attributed, render as a retain operation. 1: render only if undeleted or attributed. 2: render as insert operation (if unattributed and deleted, render as delete).
127
- */
128
- readContent (_contents, _client, _clock, _deleted, _content, _shouldRender) {
129
- error.methodUnimplemented()
130
- }
14
+ import { $renderer, AttributedContent } from './renderer-helpers.js'
131
15
 
132
- /**
133
- * Calculate the length of the attributed content. This is used by iterators that walk through the
134
- * content.
135
- *
136
- * If the content is not countable, it should return 0.
137
- *
138
- * @param {Item} _item
139
- * @return {number}
140
- */
141
- contentLength (_item) {
142
- error.methodUnimplemented()
143
- }
144
- }
16
+ export { baseRenderer, BaseRenderer, AbstractRenderer, $renderer } from './renderer-helpers.js'
145
17
 
146
18
  /**
147
- * @implements AbstractAttributionManager
19
+ * @implements AbstractRenderer
148
20
  *
149
21
  * @extends {ObservableV2<{change:(idset:IdSet,origin:any,local:boolean)=>void}>}
150
22
  */
151
- export class TwosetAttributionManager extends ObservableV2 {
23
+ export class TwosetRenderer extends ObservableV2 {
152
24
  /**
153
25
  * @param {IdMap<any>} inserts
154
26
  * @param {IdMap<any>} deletes
@@ -159,6 +31,8 @@ export class TwosetAttributionManager extends ObservableV2 {
159
31
  this.deletes = deletes
160
32
  }
161
33
 
34
+ get $type () { return $renderer }
35
+
162
36
  /**
163
37
  * @param {Array<AttributedContent<any>>} contents - where to write the result
164
38
  * @param {number} client
@@ -196,39 +70,6 @@ export class TwosetAttributionManager extends ObservableV2 {
196
70
  }
197
71
  }
198
72
 
199
- /**
200
- * Abstract class for associating Attributions to content / changes
201
- *
202
- * @implements AbstractAttributionManager
203
- *
204
- * @extends {ObservableV2<{change:(idset:IdSet,origin:any,local:boolean)=>void}>}
205
- */
206
- export class NoAttributionsManager extends ObservableV2 {
207
- /**
208
- * @param {Array<AttributedContent<any>>} contents - where to write the result
209
- * @param {number} _client
210
- * @param {number} clock
211
- * @param {boolean} deleted
212
- * @param {AbstractContent} content
213
- * @param {0|1|2} shouldRender - whether this should render or just result in a `retain` operation
214
- */
215
- readContent (contents, _client, clock, deleted, content, shouldRender) {
216
- if (!deleted || shouldRender) {
217
- contents.push(new AttributedContent(content, clock, deleted, null, shouldRender))
218
- }
219
- }
220
-
221
- /**
222
- * @param {Item} item
223
- * @return {number}
224
- */
225
- contentLength (item) {
226
- return (item.deleted || !item.content.isCountable()) ? 0 : item.length
227
- }
228
- }
229
-
230
- export const noAttributionsManager = new NoAttributionsManager()
231
-
232
73
  /**
233
74
  * @param {StructStore} store
234
75
  * @param {number} client
@@ -237,7 +78,7 @@ export const noAttributionsManager = new NoAttributionsManager()
237
78
  */
238
79
  const getItemContent = (store, client, clock, len) => {
239
80
  // Retrieved item is never more fragmented than the newer item.
240
- const prevItem = getItem(store, createID(client, clock))
81
+ const prevItem = store.getItem(createID(client, clock))
241
82
  const diffStart = clock - prevItem.id.clock
242
83
  let content = prevItem.length > 1 ? prevItem.content.copy() : prevItem.content
243
84
  // trim itemContent to the correct size.
@@ -252,15 +93,15 @@ const getItemContent = (store, client, clock, len) => {
252
93
 
253
94
  /**
254
95
  * @param {Transaction?} tr - only specify this if you want to fill the content of deleted content
255
- * @param {DiffAttributionManager} am
96
+ * @param {DiffRenderer} renderer
256
97
  * @param {ID} start
257
98
  * @param {ID} end
258
99
  * @param {boolean} collectAll - collect as many items as possible. Accept adding redundant changes.
259
100
  */
260
- const collectSuggestedChanges = (tr, am, start, end, collectAll) => {
101
+ const collectSuggestedChanges = (tr, renderer, start, end, collectAll) => {
261
102
  const inserts = createIdSet()
262
103
  const deletes = createIdSet()
263
- const store = am._nextDoc.store
104
+ const store = renderer._nextDoc.store
264
105
  /**
265
106
  * make sure to collect suggestions until all formats are closed
266
107
  * @type {Set<string>}
@@ -269,8 +110,8 @@ const collectSuggestedChanges = (tr, am, start, end, collectAll) => {
269
110
  /**
270
111
  * @type {Item?}
271
112
  */
272
- let item = getItem(store, start)
273
- const endItem = start === end ? item : (end == null ? null : getItem(store, end))
113
+ let item = store.getItem(start)
114
+ const endItem = start === end ? item : (end == null ? null : store.getItem(end))
274
115
 
275
116
  // walk to the left and find first un-attributed change that is rendered
276
117
  while (item.left != null) {
@@ -280,7 +121,7 @@ const collectSuggestedChanges = (tr, am, start, end, collectAll) => {
280
121
  break
281
122
  }
282
123
  if (!item.deleted) {
283
- const slice = am.inserts.slice(item.id.client, item.id.clock, item.length)
124
+ const slice = renderer.inserts.slice(item.id.client, item.id.clock, item.length)
284
125
  if (slice.some(s => s.attrs === null)) {
285
126
  for (let i = slice.length - 1; i >= 0; i--) {
286
127
  const s = slice[i]
@@ -296,7 +137,7 @@ const collectSuggestedChanges = (tr, am, start, end, collectAll) => {
296
137
  // eslint-disable-next-line
297
138
  itemLoop: while (item != null) {
298
139
  const itemClient = item.id.client
299
- const slice = (item.deleted ? am.deletes : am.inserts).slice(itemClient, item.id.clock, item.length)
140
+ const slice = (item.deleted ? renderer.deletes : renderer.inserts).slice(itemClient, item.id.clock, item.length)
300
141
  foundEndItem ||= item === endItem
301
142
  if (item.deleted) {
302
143
  // item probably gc'd content. Need to split item and fill with content again
@@ -313,7 +154,7 @@ const collectSuggestedChanges = (tr, am, start, end, collectAll) => {
313
154
  if (tr != null) {
314
155
  const splicedItem = getItemCleanStart(tr, createID(itemClient, s.clock))
315
156
  if (s.attrs != null) {
316
- splicedItem.content = getItemContent(am._prevDocStore, itemClient, s.clock, s.len)
157
+ splicedItem.content = getItemContent(renderer._prevDocStore, itemClient, s.clock, s.len)
317
158
  }
318
159
  }
319
160
  }
@@ -356,15 +197,15 @@ export class Attributions {
356
197
  const extractAttributions = (attrs, slice) => attrs == null ? createIdMapFromIdSet(slice, []) : mergeIdMaps([intersectMaps(attrs, slice), createIdMapFromIdSet(slice, [])])
357
198
 
358
199
  /**
359
- * @implements AbstractAttributionManager
200
+ * @implements AbstractRenderer
360
201
  *
361
202
  * @extends {ObservableV2<{change:(idset:IdSet,origin:any,local:boolean)=>void}>}
362
203
  */
363
- export class DiffAttributionManager extends ObservableV2 {
204
+ export class DiffRenderer extends ObservableV2 {
364
205
  /**
365
206
  * @param {Doc} prevDoc
366
207
  * @param {Doc} nextDoc
367
- * @param {Object} [options] - options for the attribution manager
208
+ * @param {Object} [options] - options for the renderer
368
209
  * @param {Attributions?} [options.attrs] - the attributes to apply to the diff
369
210
  */
370
211
  constructor (prevDoc, nextDoc, { attrs = null } = {}) {
@@ -423,7 +264,7 @@ export class DiffAttributionManager extends ObservableV2 {
423
264
  })
424
265
  this._afterTrListener = nextDoc.on('afterTransaction', (tr) => {
425
266
  // apply deletes on attributed deletes (content that is already deleted, but is rendered by
426
- // the attribution manager)
267
+ // the renderer)
427
268
  if (!this.suggestionMode && tr.local && (this.suggestionOrigins == null || this.suggestionOrigins.some(o => o === tr.origin))) {
428
269
  const attributedDeletes = tr.meta.get('attributedDeletes')
429
270
  if (attributedDeletes != null) {
@@ -449,6 +290,8 @@ export class DiffAttributionManager extends ObservableV2 {
449
290
  prevDoc.on('destroy', this._destroyHandler)
450
291
  }
451
292
 
293
+ get $type () { return $renderer }
294
+
452
295
  destroy () {
453
296
  super.destroy()
454
297
  this._nextDoc.off('destroy', this._destroyHandler)
@@ -525,7 +368,7 @@ export class DiffAttributionManager extends ObservableV2 {
525
368
  continue
526
369
  }
527
370
  // Retrieved item is never more fragmented than the newer item.
528
- const prevItem = getItem(this._prevDocStore, createID(client, s.clock))
371
+ const prevItem = this._prevDocStore.getItem(createID(client, s.clock))
529
372
  const diffStart = s.clock - prevItem.id.clock
530
373
  content = prevItem.length > 1 ? prevItem.content.copy() : prevItem.content
531
374
  // trim itemContent to the correct size.
@@ -568,25 +411,25 @@ export class DiffAttributionManager extends ObservableV2 {
568
411
  *
569
412
  * @param {Doc} prevDoc
570
413
  * @param {Doc} nextDoc
571
- * @param {Object} [options] - options for the attribution manager
572
- * @param {import('./meta.js').ContentMap?} [options.attrs] - the attributes to apply to the diff
414
+ * @param {Object} [options] - options for the renderer
415
+ * @param {ContentMap?} [options.attrs] - the attributes to apply to the diff
573
416
  */
574
- export const createAttributionManagerFromDiff = (prevDoc, nextDoc, options) => new DiffAttributionManager(prevDoc, nextDoc, options)
417
+ export const createDiffRenderer = (prevDoc, nextDoc, options) => new DiffRenderer(prevDoc, nextDoc, options)
575
418
 
576
419
  /**
577
- * Intended for projects that used the v13 snapshot feature. With this AttributionManager you can
420
+ * Intended for projects that used the v13 snapshot feature. With this renderer you can
578
421
  * read content similar to the previous snapshot api. Requires that `ydoc.gc` is turned off.
579
422
  *
580
- * @implements AbstractAttributionManager
423
+ * @implements AbstractRenderer
581
424
  *
582
425
  * @extends {ObservableV2<{change:(idset:IdSet,origin:any,local:boolean)=>void}>}
583
426
  */
584
- export class SnapshotAttributionManager extends ObservableV2 {
427
+ export class SnapshotRenderer extends ObservableV2 {
585
428
  /**
586
429
  * @param {Snapshot} prevSnapshot
587
430
  * @param {Snapshot} nextSnapshot
588
- * @param {Object} [options] - options for the attribution manager
589
- * @param {Array<import('./IdMap.js').ContentAttribute<any>>} [options.attrs] - the attributes to apply to the diff
431
+ * @param {Object} [options] - options for the renderer
432
+ * @param {Array<ContentAttribute>} [options.attrs] - the attributes to apply to the diff
590
433
  */
591
434
  constructor (prevSnapshot, nextSnapshot) {
592
435
  super()
@@ -602,6 +445,8 @@ export class SnapshotAttributionManager extends ObservableV2 {
602
445
  this.attrs = mergeIdMaps([diffIdMap(inserts, prevSnapshot.ds), deletes])
603
446
  }
604
447
 
448
+ get $type () { return $renderer }
449
+
605
450
  /**
606
451
  * @param {Array<AttributedContent<any>>} contents - where to write the result
607
452
  * @param {number} client
@@ -650,4 +495,4 @@ export class SnapshotAttributionManager extends ObservableV2 {
650
495
  * @param {Snapshot} prevSnapshot
651
496
  * @param {Snapshot} nextSnapshot
652
497
  */
653
- export const createAttributionManagerFromSnapshots = (prevSnapshot, nextSnapshot = prevSnapshot) => new SnapshotAttributionManager(prevSnapshot, nextSnapshot)
498
+ export const createSnapshotRenderer = (prevSnapshot, nextSnapshot = prevSnapshot) => new SnapshotRenderer(prevSnapshot, nextSnapshot)
@@ -1,29 +1,18 @@
1
- import {
2
- createDeleteSetFromStructStore,
3
- getStateVector,
4
- getItemCleanStart,
5
- iterateStructsByIdSet,
6
- writeIdSet,
7
- writeStateVector,
8
- readIdSet,
9
- readStateVector,
10
- createIdSet,
11
- createID,
12
- getState,
13
- findIndexSS,
14
- UpdateEncoderV2,
15
- applyUpdateV2,
16
- LazyStructReader,
17
- equalIdSets,
18
- UpdateDecoderV1, UpdateDecoderV2, IdSetEncoderV1, IdSetEncoderV2, IdSetDecoderV1, IdSetDecoderV2, Transaction, Doc, IdSet, Item, // eslint-disable-line
19
- mergeIdSets
20
- } from '../internals.js'
21
-
22
1
  import * as map from 'lib0/map'
23
2
  import * as set from 'lib0/set'
24
3
  import * as decoding from 'lib0/decoding'
25
4
  import * as encoding from 'lib0/encoding'
26
5
 
6
+ import { createID } from './ID.js'
7
+ import { createDeleteSetFromStructStore, createIdSet, iterateStructsByIdSet, equalIdSets, mergeIdSets, writeIdSet, readIdSet } from './ids.js'
8
+ import { getStateVector } from './StructStore.js'
9
+ import { findIndexSS, getItemCleanStart } from './transaction-helpers.js'
10
+ import { writeStateVector, readStateVector, applyUpdateV2 } from './encoding.js'
11
+ import { UpdateDecoderV1, UpdateDecoderV2, IdSetDecoderV1, IdSetDecoderV2 } from './UpdateDecoder.js'
12
+ import { UpdateEncoderV2, IdSetEncoderV1, IdSetEncoderV2 } from './UpdateEncoder.js'
13
+ import { LazyStructReader } from './updates.js'
14
+ import { Doc } from './Doc.js'
15
+
27
16
  export class Snapshot {
28
17
  /**
29
18
  * @param {IdSet} ds
@@ -108,17 +97,6 @@ export const emptySnapshot = createSnapshot(createIdSet(), new Map())
108
97
  */
109
98
  export const snapshot = doc => createSnapshot(createDeleteSetFromStructStore(doc.store), getStateVector(doc.store))
110
99
 
111
- /**
112
- * @param {Item} item
113
- * @param {Snapshot|undefined} snapshot
114
- *
115
- * @protected
116
- * @function
117
- */
118
- export const isVisible = (item, snapshot) => snapshot === undefined
119
- ? !item.deleted
120
- : snapshot.sv.has(item.id.client) && (snapshot.sv.get(item.id.client) || 0) > item.id.clock && !snapshot.ds.hasId(item.id)
121
-
122
100
  /**
123
101
  * @param {Transaction} transaction
124
102
  * @param {Snapshot} snapshot
@@ -129,7 +107,7 @@ export const splitSnapshotAffectedStructs = (transaction, snapshot) => {
129
107
  // check if we already split for this snapshot
130
108
  if (!meta.has(snapshot)) {
131
109
  snapshot.sv.forEach((clock, client) => {
132
- if (clock < getState(store, client)) {
110
+ if (clock < store.getClock(client)) {
133
111
  getItemCleanStart(transaction, createID(client, clock))
134
112
  }
135
113
  })
@@ -141,11 +119,11 @@ export const splitSnapshotAffectedStructs = (transaction, snapshot) => {
141
119
  /**
142
120
  * @example
143
121
  * const ydoc = new Y.Doc({ gc: false })
144
- * ydoc.getText().insert(0, 'world!')
122
+ * ydoc.get().insert(0, 'world!')
145
123
  * const snapshot = Y.snapshot(ydoc)
146
- * ydoc.getText().insert(0, 'hello ')
124
+ * ydoc.get().insert(0, 'hello ')
147
125
  * const restored = Y.createDocFromSnapshot(ydoc, snapshot)
148
- * assert(restored.getText().toString() === 'world!')
126
+ * assert(restored.get().toString() === 'world!')
149
127
  *
150
128
  * @param {Doc} originDoc
151
129
  * @param {Snapshot} snapshot
@@ -173,7 +151,7 @@ export const createDocFromSnapshot = (originDoc, snapshot, newDoc = new Doc()) =
173
151
  if (clock === 0) {
174
152
  continue
175
153
  }
176
- if (clock < getState(originDoc.store, client)) {
154
+ if (clock < originDoc.store.getClock(client)) {
177
155
  getItemCleanStart(transaction, createID(client, clock))
178
156
  }
179
157
  const structs = originDoc.store.clients.get(client) || []