@y/y 14.0.0-16 → 14.0.0-18

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 (68) hide show
  1. package/dist/{index-DyTeTfmj.js → index-BV-j5wdP.js} +2 -2
  2. package/dist/{index-R7GxO-36.js.map → index-BV-j5wdP.js.map} +1 -1
  3. package/dist/{internals.mjs → internals.js} +1 -1
  4. package/dist/internals.js.map +1 -0
  5. package/dist/{testHelper.mjs → testHelper.js} +2 -2
  6. package/dist/testHelper.js.map +1 -0
  7. package/dist/{yjs.mjs → yjs.js} +2 -2
  8. package/dist/yjs.js.map +1 -0
  9. package/package.json +9 -18
  10. package/dist/Skip-j0kX7pdq.js +0 -12173
  11. package/dist/Skip-j0kX7pdq.js.map +0 -1
  12. package/dist/index-DyTeTfmj.js.map +0 -1
  13. package/dist/index-R7GxO-36.js +0 -165
  14. package/dist/internals.cjs +0 -286
  15. package/dist/internals.cjs.map +0 -1
  16. package/dist/internals.mjs.map +0 -1
  17. package/dist/testHelper.cjs +0 -780
  18. package/dist/testHelper.cjs.map +0 -1
  19. package/dist/testHelper.mjs.map +0 -1
  20. package/dist/yjs.cjs +0 -151
  21. package/dist/yjs.cjs.map +0 -1
  22. package/dist/yjs.mjs.map +0 -1
  23. package/src/index.js +0 -153
  24. package/src/internals.js +0 -44
  25. package/src/structs/AbstractStruct.js +0 -59
  26. package/src/structs/ContentAny.js +0 -115
  27. package/src/structs/ContentBinary.js +0 -93
  28. package/src/structs/ContentDeleted.js +0 -101
  29. package/src/structs/ContentDoc.js +0 -141
  30. package/src/structs/ContentEmbed.js +0 -98
  31. package/src/structs/ContentFormat.js +0 -105
  32. package/src/structs/ContentJSON.js +0 -119
  33. package/src/structs/ContentString.js +0 -113
  34. package/src/structs/ContentType.js +0 -176
  35. package/src/structs/GC.js +0 -80
  36. package/src/structs/Item.js +0 -845
  37. package/src/structs/Skip.js +0 -75
  38. package/src/types/AbstractType.js +0 -1434
  39. package/src/types/YArray.js +0 -270
  40. package/src/types/YMap.js +0 -244
  41. package/src/types/YText.js +0 -934
  42. package/src/types/YXmlElement.js +0 -227
  43. package/src/types/YXmlFragment.js +0 -266
  44. package/src/types/YXmlHook.js +0 -68
  45. package/src/types/YXmlText.js +0 -66
  46. package/src/utils/AbstractConnector.js +0 -25
  47. package/src/utils/AttributionManager.js +0 -619
  48. package/src/utils/Doc.js +0 -372
  49. package/src/utils/EventHandler.js +0 -87
  50. package/src/utils/ID.js +0 -89
  51. package/src/utils/IdMap.js +0 -629
  52. package/src/utils/IdSet.js +0 -823
  53. package/src/utils/RelativePosition.js +0 -352
  54. package/src/utils/Snapshot.js +0 -220
  55. package/src/utils/StructSet.js +0 -137
  56. package/src/utils/StructStore.js +0 -289
  57. package/src/utils/Transaction.js +0 -489
  58. package/src/utils/UndoManager.js +0 -391
  59. package/src/utils/UpdateDecoder.js +0 -281
  60. package/src/utils/UpdateEncoder.js +0 -320
  61. package/src/utils/YEvent.js +0 -216
  62. package/src/utils/delta-helpers.js +0 -54
  63. package/src/utils/encoding.js +0 -623
  64. package/src/utils/isParentOf.js +0 -21
  65. package/src/utils/logging.js +0 -21
  66. package/src/utils/types.js +0 -28
  67. package/src/utils/updates.js +0 -715
  68. package/tests/testHelper.js +0 -600
@@ -1,289 +0,0 @@
1
- import {
2
- GC,
3
- splitItem,
4
- createDeleteSetFromStructStore,
5
- createIdSet,
6
- Transaction, ID, Item, // eslint-disable-line
7
- Skip,
8
- createID,
9
- splitStruct
10
- } from '../internals.js'
11
-
12
- import * as math from 'lib0/math'
13
- import * as error from 'lib0/error'
14
-
15
- export class StructStore {
16
- constructor () {
17
- /**
18
- * @type {Map<number,Array<GC|Item>>}
19
- */
20
- this.clients = new Map()
21
- // this.ds = new IdSet()
22
- /**
23
- * @type {null | { missing: Map<number, number>, update: Uint8Array<ArrayBuffer> }}
24
- */
25
- this.pendingStructs = null
26
- /**
27
- * @type {null | Uint8Array<ArrayBuffer>}
28
- */
29
- this.pendingDs = null
30
- this.skips = createIdSet()
31
- }
32
-
33
- get ds () {
34
- return createDeleteSetFromStructStore(this)
35
- }
36
- }
37
-
38
- /**
39
- * Return the states as a Map<client,clock>.
40
- * Note that clock refers to the next expected clock id.
41
- *
42
- * @param {StructStore} store
43
- * @return {Map<number,number>}
44
- *
45
- * @public
46
- * @function
47
- */
48
- export const getStateVector = store => {
49
- const sm = new Map()
50
- store.clients.forEach((structs, client) => {
51
- const struct = structs[structs.length - 1]
52
- sm.set(client, struct.id.clock + struct.length)
53
- })
54
- store.skips.clients.forEach((range, client) => {
55
- sm.set(client, range.getIds()[0].clock)
56
- })
57
- return sm
58
- }
59
-
60
- /**
61
- * @param {StructStore} store
62
- * @param {number} client
63
- * @return {number}
64
- *
65
- * @public
66
- * @function
67
- */
68
- export const getState = (store, client) => {
69
- const structs = store.clients.get(client)
70
- if (structs === undefined) {
71
- return 0
72
- }
73
- const lastStruct = structs[structs.length - 1]
74
- return lastStruct.id.clock + lastStruct.length
75
- }
76
-
77
- /**
78
- * @param {StructStore} store
79
- *
80
- * @private
81
- * @function
82
- */
83
- export const integrityCheck = store => {
84
- store.clients.forEach(structs => {
85
- for (let i = 1; i < structs.length; i++) {
86
- const l = structs[i - 1]
87
- const r = structs[i]
88
- if (l.id.clock + l.length !== r.id.clock) {
89
- throw new Error('StructStore failed integrity check')
90
- }
91
- }
92
- })
93
- }
94
-
95
- /**
96
- * @param {StructStore} store
97
- * @param {GC|Item} struct
98
- *
99
- * @private
100
- * @function
101
- */
102
- export const addStruct = (store, struct) => {
103
- let structs = store.clients.get(struct.id.client)
104
- if (structs === undefined) {
105
- structs = []
106
- store.clients.set(struct.id.client, structs)
107
- } else {
108
- const lastStruct = structs[structs.length - 1]
109
- if (lastStruct.id.clock + lastStruct.length !== struct.id.clock) {
110
- // this replaces an integrated skip
111
- let index = findIndexSS(structs, struct.id.clock)
112
- const skip = structs[index]
113
- const diffStart = struct.id.clock - skip.id.clock
114
- const diffEnd = skip.id.clock + skip.length - struct.id.clock - struct.length
115
- if (diffStart > 0) {
116
- structs.splice(index++, 0, new Skip(createID(struct.id.client, skip.id.clock), diffStart))
117
- }
118
- if (diffEnd > 0) {
119
- structs.splice(index + 1, 0, new Skip(createID(struct.id.client, struct.id.clock + struct.length), diffEnd))
120
- }
121
- structs[index] = struct
122
- store.skips.delete(struct.id.client, struct.id.clock, struct.length)
123
- return
124
- }
125
- }
126
- structs.push(struct)
127
- }
128
-
129
- /**
130
- * Perform a binary search on a sorted array
131
- * @param {Array<Item|GC>} structs
132
- * @param {number} clock
133
- * @return {number}
134
- *
135
- * @private
136
- * @function
137
- */
138
- export const findIndexSS = (structs, clock) => {
139
- let left = 0
140
- let right = structs.length - 1
141
- let mid = structs[right]
142
- let midclock = mid.id.clock
143
- if (midclock === clock) {
144
- return right
145
- }
146
- // @todo does it even make sense to pivot the search?
147
- // If a good split misses, it might actually increase the time to find the correct item.
148
- // Currently, the only advantage is that search with pivoting might find the item on the first try.
149
- let midindex = math.floor((clock / (midclock + mid.length - 1)) * right) // pivoting the search
150
- while (left <= right) {
151
- mid = structs[midindex]
152
- midclock = mid.id.clock
153
- if (midclock <= clock) {
154
- if (clock < midclock + mid.length) {
155
- return midindex
156
- }
157
- left = midindex + 1
158
- } else {
159
- right = midindex - 1
160
- }
161
- midindex = math.floor((left + right) / 2)
162
- }
163
- // Always check state before looking for a struct in StructStore
164
- // Therefore the case of not finding a struct is unexpected
165
- throw error.unexpectedCase()
166
- }
167
-
168
- /**
169
- * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
170
- *
171
- * @param {StructStore} store
172
- * @param {ID} id
173
- * @return {GC|Item}
174
- *
175
- * @private
176
- * @function
177
- */
178
- export const find = (store, id) => {
179
- /**
180
- * @type {Array<GC|Item>}
181
- */
182
- // @ts-ignore
183
- const structs = store.clients.get(id.client)
184
- return structs[findIndexSS(structs, id.clock)]
185
- }
186
-
187
- /**
188
- * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
189
- * @private
190
- * @function
191
- */
192
- export const getItem = /** @type {function(StructStore,ID):Item} */ (find)
193
-
194
- /**
195
- * @param {Transaction?} transaction
196
- * @param {Array<Item|GC>} structs
197
- * @param {number} clock
198
- */
199
- export const findIndexCleanStart = (transaction, structs, clock) => {
200
- const index = findIndexSS(structs, clock)
201
- const struct = structs[index]
202
- if (struct.id.clock < clock) {
203
- structs.splice(index + 1, 0, splitStruct(transaction, struct, clock - struct.id.clock))
204
- return index + 1
205
- }
206
- return index
207
- }
208
-
209
- /**
210
- * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
211
- *
212
- * @param {Transaction} transaction
213
- * @param {ID} id
214
- * @return {Item}
215
- *
216
- * @private
217
- * @function
218
- */
219
- export const getItemCleanStart = (transaction, id) => {
220
- const structs = /** @type {Array<Item>} */ (transaction.doc.store.clients.get(id.client))
221
- return structs[findIndexCleanStart(transaction, structs, id.clock)]
222
- }
223
-
224
- /**
225
- * Expects that id is actually in store. This function throws or is an infinite loop otherwise.
226
- *
227
- * @param {Transaction} transaction
228
- * @param {StructStore} store
229
- * @param {ID} id
230
- * @return {Item}
231
- *
232
- * @private
233
- * @function
234
- */
235
- export const getItemCleanEnd = (transaction, store, id) => {
236
- /**
237
- * @type {Array<Item>}
238
- */
239
- // @ts-ignore
240
- const structs = store.clients.get(id.client)
241
- const index = findIndexSS(structs, id.clock)
242
- const struct = structs[index]
243
- if (id.clock !== struct.id.clock + struct.length - 1 && struct.constructor !== GC) {
244
- structs.splice(index + 1, 0, splitItem(transaction, struct, id.clock - struct.id.clock + 1))
245
- }
246
- return struct
247
- }
248
-
249
- /**
250
- * Replace `item` with `newitem` in store
251
- * @param {Transaction} tr
252
- * @param {GC|Item} struct
253
- * @param {GC|Item} newStruct
254
- *
255
- * @private
256
- * @function
257
- */
258
- export const replaceStruct = (tr, struct, newStruct) => {
259
- const structs = /** @type {Array<GC|Item>} */ (tr.doc.store.clients.get(struct.id.client))
260
- structs[findIndexSS(structs, struct.id.clock)] = newStruct
261
- tr._mergeStructs.push(newStruct)
262
- }
263
-
264
- /**
265
- * Iterate over a range of structs
266
- *
267
- * @param {Transaction} transaction
268
- * @param {Array<Item|GC>} structs
269
- * @param {number} clockStart Inclusive start
270
- * @param {number} len
271
- * @param {function(GC|Item):void} f
272
- *
273
- * @function
274
- */
275
- export const iterateStructs = (transaction, structs, clockStart, len, f) => {
276
- if (len === 0) {
277
- return
278
- }
279
- const clockEnd = clockStart + len
280
- let index = findIndexCleanStart(transaction, structs, clockStart)
281
- let struct
282
- do {
283
- struct = structs[index++]
284
- if (clockEnd < struct.id.clock + struct.length) {
285
- findIndexCleanStart(transaction, structs, clockEnd)
286
- }
287
- f(struct)
288
- } while (index < structs.length && structs[index].id.clock < clockEnd)
289
- }