@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,320 +0,0 @@
1
- import * as error from 'lib0/error'
2
- import * as encoding from 'lib0/encoding'
3
-
4
- import {
5
- ID // eslint-disable-line
6
- } from '../internals.js'
7
-
8
- export class IdSetEncoderV1 {
9
- constructor () {
10
- this.restEncoder = encoding.createEncoder()
11
- }
12
-
13
- toUint8Array () {
14
- return encoding.toUint8Array(this.restEncoder)
15
- }
16
-
17
- resetIdSetCurVal () {
18
- // nop
19
- }
20
-
21
- /**
22
- * @param {number} clock
23
- */
24
- writeIdSetClock (clock) {
25
- encoding.writeVarUint(this.restEncoder, clock)
26
- }
27
-
28
- /**
29
- * @param {number} len
30
- */
31
- writeIdSetLen (len) {
32
- encoding.writeVarUint(this.restEncoder, len)
33
- }
34
- }
35
-
36
- export class UpdateEncoderV1 extends IdSetEncoderV1 {
37
- /**
38
- * @param {ID} id
39
- */
40
- writeLeftID (id) {
41
- encoding.writeVarUint(this.restEncoder, id.client)
42
- encoding.writeVarUint(this.restEncoder, id.clock)
43
- }
44
-
45
- /**
46
- * @param {ID} id
47
- */
48
- writeRightID (id) {
49
- encoding.writeVarUint(this.restEncoder, id.client)
50
- encoding.writeVarUint(this.restEncoder, id.clock)
51
- }
52
-
53
- /**
54
- * Use writeClient and writeClock instead of writeID if possible.
55
- * @param {number} client
56
- */
57
- writeClient (client) {
58
- encoding.writeVarUint(this.restEncoder, client)
59
- }
60
-
61
- /**
62
- * @param {number} info An unsigned 8-bit integer
63
- */
64
- writeInfo (info) {
65
- encoding.writeUint8(this.restEncoder, info)
66
- }
67
-
68
- /**
69
- * @param {string} s
70
- */
71
- writeString (s) {
72
- encoding.writeVarString(this.restEncoder, s)
73
- }
74
-
75
- /**
76
- * @param {boolean} isYKey
77
- */
78
- writeParentInfo (isYKey) {
79
- encoding.writeVarUint(this.restEncoder, isYKey ? 1 : 0)
80
- }
81
-
82
- /**
83
- * @param {number} info An unsigned 8-bit integer
84
- */
85
- writeTypeRef (info) {
86
- encoding.writeVarUint(this.restEncoder, info)
87
- }
88
-
89
- /**
90
- * Write len of a struct - well suited for Opt RLE encoder.
91
- *
92
- * @param {number} len
93
- */
94
- writeLen (len) {
95
- encoding.writeVarUint(this.restEncoder, len)
96
- }
97
-
98
- /**
99
- * @param {any} any
100
- */
101
- writeAny (any) {
102
- encoding.writeAny(this.restEncoder, any)
103
- }
104
-
105
- /**
106
- * @param {Uint8Array} buf
107
- */
108
- writeBuf (buf) {
109
- encoding.writeVarUint8Array(this.restEncoder, buf)
110
- }
111
-
112
- /**
113
- * @param {any} embed
114
- */
115
- writeJSON (embed) {
116
- encoding.writeVarString(this.restEncoder, JSON.stringify(embed))
117
- }
118
-
119
- /**
120
- * @param {string} key
121
- */
122
- writeKey (key) {
123
- encoding.writeVarString(this.restEncoder, key)
124
- }
125
- }
126
-
127
- export class IdSetEncoderV2 {
128
- constructor () {
129
- this.restEncoder = encoding.createEncoder() // encodes all the rest / non-optimized
130
- this.dsCurrVal = 0
131
- }
132
-
133
- toUint8Array () {
134
- return encoding.toUint8Array(this.restEncoder)
135
- }
136
-
137
- resetIdSetCurVal () {
138
- this.dsCurrVal = 0
139
- }
140
-
141
- /**
142
- * @param {number} clock
143
- */
144
- writeIdSetClock (clock) {
145
- const diff = clock - this.dsCurrVal
146
- this.dsCurrVal = clock
147
- encoding.writeVarUint(this.restEncoder, diff)
148
- }
149
-
150
- /**
151
- * @param {number} len
152
- */
153
- writeIdSetLen (len) {
154
- if (len === 0) {
155
- error.unexpectedCase()
156
- }
157
- encoding.writeVarUint(this.restEncoder, len - 1)
158
- this.dsCurrVal += len
159
- }
160
- }
161
-
162
- export class UpdateEncoderV2 extends IdSetEncoderV2 {
163
- constructor () {
164
- super()
165
- /**
166
- * @type {Map<string,number>}
167
- */
168
- this.keyMap = new Map()
169
- /**
170
- * Refers to the next unique key-identifier to me used.
171
- * See writeKey method for more information.
172
- *
173
- * @type {number}
174
- */
175
- this.keyClock = 0
176
- this.keyClockEncoder = new encoding.IntDiffOptRleEncoder()
177
- this.clientEncoder = new encoding.UintOptRleEncoder()
178
- this.leftClockEncoder = new encoding.IntDiffOptRleEncoder()
179
- this.rightClockEncoder = new encoding.IntDiffOptRleEncoder()
180
- this.infoEncoder = new encoding.RleEncoder(encoding.writeUint8)
181
- this.stringEncoder = new encoding.StringEncoder()
182
- this.parentInfoEncoder = new encoding.RleEncoder(encoding.writeUint8)
183
- this.typeRefEncoder = new encoding.UintOptRleEncoder()
184
- this.lenEncoder = new encoding.UintOptRleEncoder()
185
- }
186
-
187
- toUint8Array () {
188
- const encoder = encoding.createEncoder()
189
- encoding.writeVarUint(encoder, 0) // this is a feature flag that we might use in the future
190
- encoding.writeVarUint8Array(encoder, this.keyClockEncoder.toUint8Array())
191
- encoding.writeVarUint8Array(encoder, this.clientEncoder.toUint8Array())
192
- encoding.writeVarUint8Array(encoder, this.leftClockEncoder.toUint8Array())
193
- encoding.writeVarUint8Array(encoder, this.rightClockEncoder.toUint8Array())
194
- encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.infoEncoder))
195
- encoding.writeVarUint8Array(encoder, this.stringEncoder.toUint8Array())
196
- encoding.writeVarUint8Array(encoder, encoding.toUint8Array(this.parentInfoEncoder))
197
- encoding.writeVarUint8Array(encoder, this.typeRefEncoder.toUint8Array())
198
- encoding.writeVarUint8Array(encoder, this.lenEncoder.toUint8Array())
199
- // @note The rest encoder is appended! (note the missing var)
200
- encoding.writeUint8Array(encoder, encoding.toUint8Array(this.restEncoder))
201
- return encoding.toUint8Array(encoder)
202
- }
203
-
204
- /**
205
- * @param {ID} id
206
- */
207
- writeLeftID (id) {
208
- this.clientEncoder.write(id.client)
209
- this.leftClockEncoder.write(id.clock)
210
- }
211
-
212
- /**
213
- * @param {ID} id
214
- */
215
- writeRightID (id) {
216
- this.clientEncoder.write(id.client)
217
- this.rightClockEncoder.write(id.clock)
218
- }
219
-
220
- /**
221
- * @param {number} client
222
- */
223
- writeClient (client) {
224
- this.clientEncoder.write(client)
225
- }
226
-
227
- /**
228
- * @param {number} info An unsigned 8-bit integer
229
- */
230
- writeInfo (info) {
231
- this.infoEncoder.write(info)
232
- }
233
-
234
- /**
235
- * @param {string} s
236
- */
237
- writeString (s) {
238
- this.stringEncoder.write(s)
239
- }
240
-
241
- /**
242
- * @param {boolean} isYKey
243
- */
244
- writeParentInfo (isYKey) {
245
- this.parentInfoEncoder.write(isYKey ? 1 : 0)
246
- }
247
-
248
- /**
249
- * @param {number} info An unsigned 8-bit integer
250
- */
251
- writeTypeRef (info) {
252
- this.typeRefEncoder.write(info)
253
- }
254
-
255
- /**
256
- * Write len of a struct - well suited for Opt RLE encoder.
257
- *
258
- * @param {number} len
259
- */
260
- writeLen (len) {
261
- this.lenEncoder.write(len)
262
- }
263
-
264
- /**
265
- * @param {any} any
266
- */
267
- writeAny (any) {
268
- encoding.writeAny(this.restEncoder, any)
269
- }
270
-
271
- /**
272
- * @param {Uint8Array} buf
273
- */
274
- writeBuf (buf) {
275
- encoding.writeVarUint8Array(this.restEncoder, buf)
276
- }
277
-
278
- /**
279
- * This is mainly here for legacy purposes.
280
- *
281
- * Initial we incoded objects using JSON. Now we use the much faster lib0/any-encoder. This method mainly exists for legacy purposes for the v1 encoder.
282
- *
283
- * @param {any} embed
284
- */
285
- writeJSON (embed) {
286
- encoding.writeAny(this.restEncoder, embed)
287
- }
288
-
289
- /**
290
- * Property keys are often reused. For example, in y-prosemirror the key `bold` might
291
- * occur very often. For a 3d application, the key `position` might occur very often.
292
- *
293
- * We cache these keys in a Map and refer to them via a unique number.
294
- *
295
- * @param {string} key
296
- */
297
- writeKey (key) {
298
- const clock = this.keyMap.get(key)
299
- if (clock === undefined) {
300
- /**
301
- * @todo uncomment to introduce this feature finally
302
- *
303
- * Background. The ContentFormat object was always encoded using writeKey, but the decoder used to use readString.
304
- * Furthermore, I forgot to set the keyclock. So everything was working fine.
305
- *
306
- * However, this feature here is basically useless as it is not being used (it actually only consumes extra memory).
307
- *
308
- * I don't know yet how to reintroduce this feature..
309
- *
310
- * Older clients won't be able to read updates when we reintroduce this feature. So this should probably be done using a flag.
311
- *
312
- */
313
- // this.keyMap.set(key, this.keyClock)
314
- this.keyClockEncoder.write(this.keyClock++)
315
- this.stringEncoder.write(key)
316
- } else {
317
- this.keyClockEncoder.write(clock)
318
- }
319
- }
320
- }
@@ -1,216 +0,0 @@
1
- import {
2
- diffIdSet,
3
- mergeIdSets,
4
- noAttributionsManager,
5
- AbstractAttributionManager, Item, AbstractType, Transaction, AbstractStruct // eslint-disable-line
6
- } from '../internals.js'
7
-
8
- import * as map from 'lib0/map'
9
- import * as delta from 'lib0/delta' // eslint-disable-line
10
- import * as set from 'lib0/set'
11
-
12
- /**
13
- * @typedef {import('./types.js').YType} _YType
14
- */
15
-
16
- /**
17
- * @template {AbstractType<any,any>} Target
18
- * YEvent describes the changes on a YType.
19
- */
20
- export class YEvent {
21
- /**
22
- * @param {Target} target The changed type.
23
- * @param {Transaction} transaction
24
- * @param {Set<any>?} subs The keys that changed
25
- */
26
- constructor (target, transaction, subs) {
27
- /**
28
- * The type on which this event was created on.
29
- * @type {Target}
30
- */
31
- this.target = target
32
- /**
33
- * The current target on which the observe callback is called.
34
- * @type {_YType}
35
- */
36
- this.currentTarget = target
37
- /**
38
- * The transaction that triggered this event.
39
- * @type {Transaction}
40
- */
41
- this.transaction = transaction
42
- /**
43
- * @type {(Target extends AbstractType<infer D,any> ? D : delta.Delta<any,any,any,any,any>)|null}
44
- */
45
- this._delta = null
46
- /**
47
- * @type {(Target extends AbstractType<infer D,any> ? import('../internals.js').ToDeepEventDelta<D> : delta.Delta<any,any,any,any,any>)|null}
48
- */
49
- this._deltaDeep = null
50
- /**
51
- * @type {Array<string|number>|null}
52
- */
53
- this._path = null
54
- /**
55
- * Whether the children changed.
56
- * @type {Boolean}
57
- * @private
58
- */
59
- this.childListChanged = false
60
- /**
61
- * Set of all changed attributes.
62
- * @type {Set<string>}
63
- */
64
- this.keysChanged = new Set()
65
- subs?.forEach((sub) => {
66
- if (sub === null) {
67
- this.childListChanged = true
68
- } else {
69
- this.keysChanged.add(sub)
70
- }
71
- })
72
- }
73
-
74
- /**
75
- * Computes the path from `y` to the changed type.
76
- *
77
- * @todo v14 should standardize on path: Array<{parent, index}> because that is easier to work with.
78
- *
79
- * The following property holds:
80
- * @example
81
- * let type = y
82
- * event.path.forEach(dir => {
83
- * type = type.get(dir)
84
- * })
85
- * type === event.target // => true
86
- */
87
- get path () {
88
- return this._path || (this._path = getPathTo(this.currentTarget, this.target))
89
- }
90
-
91
- /**
92
- * Check if a struct is deleted by this event.
93
- *
94
- * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.
95
- *
96
- * @param {AbstractStruct} struct
97
- * @return {boolean}
98
- */
99
- deletes (struct) {
100
- return this.transaction.deleteSet.hasId(struct.id)
101
- }
102
-
103
- /**
104
- * Check if a struct is added by this event.
105
- *
106
- * In contrast to change.deleted, this method also returns true if the struct was added and then deleted.
107
- *
108
- * @param {AbstractStruct} struct
109
- * @return {boolean}
110
- */
111
- adds (struct) {
112
- return this.transaction.insertSet.hasId(struct.id)
113
- }
114
-
115
- /**
116
- * @template {boolean} [Deep=false]
117
- * @param {AbstractAttributionManager} am
118
- * @param {object} [opts]
119
- * @param {Deep} [opts.deep]
120
- * @return {Target extends AbstractType<infer D,any> ? (Deep extends true ? import('../internals.js').ToDeepEventDelta<D> : D) : delta.Delta<any,any,any,any>} The Delta representation of this type.
121
- *
122
- * @public
123
- */
124
- getDelta (am = noAttributionsManager, { deep } = {}) {
125
- const itemsToRender = mergeIdSets([diffIdSet(this.transaction.insertSet, this.transaction.deleteSet), diffIdSet(this.transaction.deleteSet, this.transaction.insertSet)])
126
- /**
127
- * @todo this should be done only one in the transaction step
128
- *
129
- * @type {Map<import('./types.js').YType,Set<string|null>>|null}
130
- */
131
- let modified = this.transaction.changed
132
- if (deep) {
133
- // need to add deep changes to copy of modified
134
- const dchanged = new Map()
135
- modified.forEach((attrs, type) => {
136
- dchanged.set(type, new Set(attrs))
137
- })
138
- for (let m of modified.keys()) {
139
- while (m._item != null) {
140
- const item = m._item
141
- const ms = map.setIfUndefined(dchanged, item?.parent, set.create)
142
- if (item && !ms.has(item.parentSub)) {
143
- ms.add(item.parentSub)
144
- m = /** @type {any} */ (item.parent)
145
- } else {
146
- break
147
- }
148
- }
149
- }
150
- modified = dchanged
151
- }
152
- return /** @type {any} */ (this.target.getContent(am, { itemsToRender, retainDeletes: true, deletedItems: this.transaction.deleteSet, deep: !!deep, modified }))
153
- }
154
-
155
- /**
156
- * Compute the changes in the delta format.
157
- * A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document.
158
- *
159
- * @type {Target extends AbstractType<infer D,any> ? D : delta.Delta<any,any,any,any,any>} The Delta representation of this type.
160
- * @public
161
- */
162
- get delta () {
163
- return /** @type {any} */ (this._delta ?? (this._delta = this.getDelta().done()))
164
- }
165
-
166
- /**
167
- * Compute the changes in the delta format.
168
- * A {@link https://quilljs.com/docs/delta/|Quill Delta}) that represents the changes on the document.
169
- *
170
- * @type {Target extends AbstractType<infer D,any> ? D : delta.Delta<any,any,any,any,any>} The Delta representation of this type.
171
- * @public
172
- */
173
- get deltaDeep () {
174
- return /** @type {any} */ (this._deltaDeep ?? (this._deltaDeep = this.getDelta(noAttributionsManager, { deep: true })))
175
- }
176
- }
177
-
178
- /**
179
- * Compute the path from this type to the specified target.
180
- *
181
- * @example
182
- * // `child` should be accessible via `type.get(path[0]).get(path[1])..`
183
- * const path = type.getPathTo(child)
184
- * // assuming `type instanceof YArray`
185
- * console.log(path) // might look like => [2, 'key1']
186
- * child === type.get(path[0]).get(path[1])
187
- *
188
- * @param {_YType} parent
189
- * @param {_YType} child target
190
- * @return {Array<string|number>} Path to the target
191
- *
192
- * @private
193
- * @function
194
- */
195
- const getPathTo = (parent, child) => {
196
- const path = []
197
- while (child._item !== null && child !== parent) {
198
- if (child._item.parentSub !== null) {
199
- // parent is map-ish
200
- path.unshift(child._item.parentSub)
201
- } else {
202
- // parent is array-ish
203
- let i = 0
204
- let c = /** @type {import('../utils/types.js').YType} */ (child._item.parent)._start
205
- while (c !== child._item && c !== null) {
206
- if (!c.deleted && c.countable) {
207
- i += c.length
208
- }
209
- c = c.right
210
- }
211
- path.unshift(i)
212
- }
213
- child = /** @type {_YType} */ (child._item.parent)
214
- }
215
- return path
216
- }
@@ -1,54 +0,0 @@
1
- import {
2
- createInsertSetFromStructStore,
3
- createDeleteSetFromStructStore,
4
- createAttributionManagerFromDiff,
5
- diffIdSet,
6
- mergeIdSets,
7
- Item,
8
- AbstractType, Doc, // eslint-disable-line
9
- iterateStructsByIdSet
10
- } from '../internals.js'
11
- import * as delta from 'lib0/delta'
12
- import * as map from 'lib0/map'
13
- import * as set from 'lib0/set'
14
-
15
- /**
16
- * @param {Doc} v1
17
- * @param {Doc} v2
18
- * @return {delta.DeltaBuilderAny}
19
- */
20
- export const diffDocsToDelta = (v1, v2, { am = createAttributionManagerFromDiff(v1, v2) } = {}) => {
21
- const d = delta.create()
22
- v2.transact(tr => {
23
- v2.share.forEach((type, typename) => {
24
- const insertDiff = diffIdSet(createInsertSetFromStructStore(v2.store, false), createInsertSetFromStructStore(v1.store, false))
25
- const deleteDiff = diffIdSet(createDeleteSetFromStructStore(v2.store), createDeleteSetFromStructStore(v1.store))
26
- // don't render items that have been inserted and then deleted
27
- const insertsOnly = diffIdSet(insertDiff, deleteDiff)
28
- const deletesOnly = diffIdSet(deleteDiff, insertDiff)
29
- const itemsToRender = mergeIdSets([insertsOnly, deleteDiff])
30
- /**
31
- * @type {Map<AbstractType, Set<string|null>>}
32
- */
33
- const changedTypes = new Map()
34
- iterateStructsByIdSet(tr, itemsToRender, /** @param {any} item */ item => {
35
- while (item instanceof Item) {
36
- const parent = /** @type {AbstractType} */ (item.parent)
37
- const conf = map.setIfUndefined(changedTypes, parent, set.create)
38
- if (conf.has(item.parentSub)) break // has already been marked as modified
39
- conf.add(item.parentSub)
40
- item = parent._item
41
- }
42
- })
43
- const typeConf = changedTypes.get(type)
44
- if (typeConf) {
45
- // @ts-ignore
46
- const shareDelta = type.getContent(am, {
47
- itemsToRender, retainDeletes: true, deletedItems: deletesOnly, modified: changedTypes, deep: true
48
- })
49
- d.update(typename, shareDelta)
50
- }
51
- })
52
- })
53
- return d
54
- }