@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.
- package/dist/{index-DyTeTfmj.js → index-BV-j5wdP.js} +2 -2
- package/dist/{index-R7GxO-36.js.map → index-BV-j5wdP.js.map} +1 -1
- package/dist/{internals.mjs → internals.js} +1 -1
- package/dist/internals.js.map +1 -0
- package/dist/{testHelper.mjs → testHelper.js} +2 -2
- package/dist/testHelper.js.map +1 -0
- package/dist/{yjs.mjs → yjs.js} +2 -2
- package/dist/yjs.js.map +1 -0
- package/package.json +9 -18
- package/dist/Skip-j0kX7pdq.js +0 -12173
- package/dist/Skip-j0kX7pdq.js.map +0 -1
- package/dist/index-DyTeTfmj.js.map +0 -1
- package/dist/index-R7GxO-36.js +0 -165
- package/dist/internals.cjs +0 -286
- package/dist/internals.cjs.map +0 -1
- package/dist/internals.mjs.map +0 -1
- package/dist/testHelper.cjs +0 -780
- package/dist/testHelper.cjs.map +0 -1
- package/dist/testHelper.mjs.map +0 -1
- package/dist/yjs.cjs +0 -151
- package/dist/yjs.cjs.map +0 -1
- package/dist/yjs.mjs.map +0 -1
- package/src/index.js +0 -153
- package/src/internals.js +0 -44
- package/src/structs/AbstractStruct.js +0 -59
- package/src/structs/ContentAny.js +0 -115
- package/src/structs/ContentBinary.js +0 -93
- package/src/structs/ContentDeleted.js +0 -101
- package/src/structs/ContentDoc.js +0 -141
- package/src/structs/ContentEmbed.js +0 -98
- package/src/structs/ContentFormat.js +0 -105
- package/src/structs/ContentJSON.js +0 -119
- package/src/structs/ContentString.js +0 -113
- package/src/structs/ContentType.js +0 -176
- package/src/structs/GC.js +0 -80
- package/src/structs/Item.js +0 -845
- package/src/structs/Skip.js +0 -75
- package/src/types/AbstractType.js +0 -1434
- package/src/types/YArray.js +0 -270
- package/src/types/YMap.js +0 -244
- package/src/types/YText.js +0 -934
- package/src/types/YXmlElement.js +0 -227
- package/src/types/YXmlFragment.js +0 -266
- package/src/types/YXmlHook.js +0 -68
- package/src/types/YXmlText.js +0 -66
- package/src/utils/AbstractConnector.js +0 -25
- package/src/utils/AttributionManager.js +0 -619
- package/src/utils/Doc.js +0 -372
- package/src/utils/EventHandler.js +0 -87
- package/src/utils/ID.js +0 -89
- package/src/utils/IdMap.js +0 -629
- package/src/utils/IdSet.js +0 -823
- package/src/utils/RelativePosition.js +0 -352
- package/src/utils/Snapshot.js +0 -220
- package/src/utils/StructSet.js +0 -137
- package/src/utils/StructStore.js +0 -289
- package/src/utils/Transaction.js +0 -489
- package/src/utils/UndoManager.js +0 -391
- package/src/utils/UpdateDecoder.js +0 -281
- package/src/utils/UpdateEncoder.js +0 -320
- package/src/utils/YEvent.js +0 -216
- package/src/utils/delta-helpers.js +0 -54
- package/src/utils/encoding.js +0 -623
- package/src/utils/isParentOf.js +0 -21
- package/src/utils/logging.js +0 -21
- package/src/utils/types.js +0 -28
- package/src/utils/updates.js +0 -715
- package/tests/testHelper.js +0 -600
package/src/types/YArray.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module YArray
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AbstractType,
|
|
7
|
-
typeListGet,
|
|
8
|
-
typeListToArray,
|
|
9
|
-
typeListForEach,
|
|
10
|
-
typeListCreateIterator,
|
|
11
|
-
typeListInsertGenerics,
|
|
12
|
-
typeListPushGenerics,
|
|
13
|
-
typeListDelete,
|
|
14
|
-
typeListMap,
|
|
15
|
-
YArrayRefID,
|
|
16
|
-
transact,
|
|
17
|
-
warnPrematureAccess,
|
|
18
|
-
typeListSlice,
|
|
19
|
-
noAttributionsManager,
|
|
20
|
-
AbstractAttributionManager, ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line
|
|
21
|
-
} from '../internals.js'
|
|
22
|
-
|
|
23
|
-
import * as delta from 'lib0/delta' // eslint-disable-line
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* A shared Array implementation.
|
|
27
|
-
* @template {import('../utils/types.js').YValue} T
|
|
28
|
-
* @extends {AbstractType<delta.ArrayDelta<T>,YArray<T>>}
|
|
29
|
-
* @implements {Iterable<T>}
|
|
30
|
-
*/
|
|
31
|
-
// @todo remove this
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
export class YArray extends AbstractType {
|
|
34
|
-
constructor () {
|
|
35
|
-
super()
|
|
36
|
-
/**
|
|
37
|
-
* @type {Array<any>?}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this._prelimContent = []
|
|
41
|
-
/**
|
|
42
|
-
* @type {Array<ArraySearchMarker>}
|
|
43
|
-
*/
|
|
44
|
-
this._searchMarker = []
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Construct a new YArray containing the specified items.
|
|
49
|
-
* @template {import('../utils/types.js').YValue} T
|
|
50
|
-
* @param {Array<T>} items
|
|
51
|
-
* @return {YArray<T>}
|
|
52
|
-
*/
|
|
53
|
-
static from (items) {
|
|
54
|
-
/**
|
|
55
|
-
* @type {YArray<T>}
|
|
56
|
-
*/
|
|
57
|
-
const a = new YArray()
|
|
58
|
-
a.push(items)
|
|
59
|
-
return a
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Integrate this type into the Yjs instance.
|
|
64
|
-
*
|
|
65
|
-
* * Save this struct in the os
|
|
66
|
-
* * This type is sent to other client
|
|
67
|
-
* * Observer functions are fired
|
|
68
|
-
*
|
|
69
|
-
* @param {Doc} y The Yjs instance
|
|
70
|
-
* @param {Item?} item
|
|
71
|
-
*/
|
|
72
|
-
_integrate (y, item) {
|
|
73
|
-
super._integrate(y, item)
|
|
74
|
-
this.insert(0, /** @type {Array<any>} */ (this._prelimContent))
|
|
75
|
-
this._prelimContent = null
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Makes a copy of this data type that can be included somewhere else.
|
|
80
|
-
*
|
|
81
|
-
* Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
|
|
82
|
-
*
|
|
83
|
-
* @return {YArray<T>}
|
|
84
|
-
*/
|
|
85
|
-
clone () {
|
|
86
|
-
/**
|
|
87
|
-
* @type {this}
|
|
88
|
-
*/
|
|
89
|
-
const arr = /** @type {this} */ (new YArray())
|
|
90
|
-
arr.insert(0, this.toArray().map(el =>
|
|
91
|
-
// @ts-ignore
|
|
92
|
-
el instanceof AbstractType ? /** @type {any} */ (el.clone()) : el
|
|
93
|
-
))
|
|
94
|
-
return arr
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get length () {
|
|
98
|
-
this.doc ?? warnPrematureAccess()
|
|
99
|
-
return this._length
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Inserts new content at an index.
|
|
104
|
-
*
|
|
105
|
-
* Important: This function expects an array of content. Not just a content
|
|
106
|
-
* object. The reason for this "weirdness" is that inserting several elements
|
|
107
|
-
* is very efficient when it is done as a single operation.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* // Insert character 'a' at position 0
|
|
111
|
-
* yarray.insert(0, ['a'])
|
|
112
|
-
* // Insert numbers 1, 2 at position 1
|
|
113
|
-
* yarray.insert(1, [1, 2])
|
|
114
|
-
*
|
|
115
|
-
* @param {number} index The index to insert content at.
|
|
116
|
-
* @param {Array<T>} content The array of content
|
|
117
|
-
*/
|
|
118
|
-
insert (index, content) {
|
|
119
|
-
if (this.doc !== null) {
|
|
120
|
-
transact(this.doc, transaction => {
|
|
121
|
-
typeListInsertGenerics(transaction, this, index, /** @type {any} */ (content))
|
|
122
|
-
})
|
|
123
|
-
} else {
|
|
124
|
-
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Appends content to this YArray.
|
|
130
|
-
*
|
|
131
|
-
* @param {Array<T>} content Array of content to append.
|
|
132
|
-
*
|
|
133
|
-
* @todo Use the following implementation in all types.
|
|
134
|
-
*/
|
|
135
|
-
push (content) {
|
|
136
|
-
if (this.doc !== null) {
|
|
137
|
-
transact(this.doc, transaction => {
|
|
138
|
-
typeListPushGenerics(transaction, this, /** @type {any} */ (content))
|
|
139
|
-
})
|
|
140
|
-
} else {
|
|
141
|
-
/** @type {Array<any>} */ (this._prelimContent).push(...content)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Prepends content to this YArray.
|
|
147
|
-
*
|
|
148
|
-
* @param {Array<T>} content Array of content to prepend.
|
|
149
|
-
*/
|
|
150
|
-
unshift (content) {
|
|
151
|
-
this.insert(0, content)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Deletes elements starting from an index.
|
|
156
|
-
*
|
|
157
|
-
* @param {number} index Index at which to start deleting elements
|
|
158
|
-
* @param {number} length The number of elements to remove. Defaults to 1.
|
|
159
|
-
*/
|
|
160
|
-
delete (index, length = 1) {
|
|
161
|
-
if (this.doc !== null) {
|
|
162
|
-
transact(this.doc, transaction => {
|
|
163
|
-
typeListDelete(transaction, this, index, length)
|
|
164
|
-
})
|
|
165
|
-
} else {
|
|
166
|
-
/** @type {Array<any>} */ (this._prelimContent).splice(index, length)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Returns the i-th element from a YArray.
|
|
172
|
-
*
|
|
173
|
-
* @param {number} index The index of the element to return from the YArray
|
|
174
|
-
* @return {T}
|
|
175
|
-
*/
|
|
176
|
-
get (index) {
|
|
177
|
-
return typeListGet(this, index)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Transforms this YArray to a JavaScript Array.
|
|
182
|
-
*
|
|
183
|
-
* @return {Array<T>}
|
|
184
|
-
*/
|
|
185
|
-
toArray () {
|
|
186
|
-
return typeListToArray(this)
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Render the difference to another ydoc (which can be empty) and highlight the differences with
|
|
191
|
-
* attributions.
|
|
192
|
-
*
|
|
193
|
-
* Note that deleted content that was not deleted in prevYdoc is rendered as an insertion with the
|
|
194
|
-
* attribution `{ isDeleted: true, .. }`.
|
|
195
|
-
*
|
|
196
|
-
* @param {AbstractAttributionManager} am
|
|
197
|
-
* @return {delta.ArrayDelta<import('./AbstractType.js').TypeToDelta<T>>} The Delta representation of this type.
|
|
198
|
-
*
|
|
199
|
-
* @public
|
|
200
|
-
*/
|
|
201
|
-
getContentDeep (am = noAttributionsManager) {
|
|
202
|
-
return super.getContentDeep(am)
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Returns a portion of this YArray into a JavaScript Array selected
|
|
207
|
-
* from start to end (end not included).
|
|
208
|
-
*
|
|
209
|
-
* @param {number} [start]
|
|
210
|
-
* @param {number} [end]
|
|
211
|
-
* @return {Array<T>}
|
|
212
|
-
*/
|
|
213
|
-
slice (start = 0, end = this.length) {
|
|
214
|
-
return typeListSlice(this, start, end)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Transforms this Shared Type to a JSON object.
|
|
219
|
-
*
|
|
220
|
-
* @return {Array<any>}
|
|
221
|
-
*/
|
|
222
|
-
toJSON () {
|
|
223
|
-
return this.map(c => c instanceof AbstractType ? c.toJSON() : c)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Returns an Array with the result of calling a provided function on every
|
|
228
|
-
* element of this YArray.
|
|
229
|
-
*
|
|
230
|
-
* @template M
|
|
231
|
-
* @param {function(T,number,YArray<T>):M} f Function that produces an element of the new Array
|
|
232
|
-
* @return {Array<M>} A new array with each element being the result of the
|
|
233
|
-
* callback function
|
|
234
|
-
*/
|
|
235
|
-
map (f) {
|
|
236
|
-
return typeListMap(this, /** @type {any} */ (f))
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Executes a provided function once on every element of this YArray.
|
|
241
|
-
*
|
|
242
|
-
* @param {function(T,number,YArray<T>):void} f A function to execute on every element of this YArray.
|
|
243
|
-
*/
|
|
244
|
-
forEach (f) {
|
|
245
|
-
typeListForEach(this, f)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* @return {IterableIterator<T>}
|
|
250
|
-
*/
|
|
251
|
-
[Symbol.iterator] () {
|
|
252
|
-
return typeListCreateIterator(this)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
257
|
-
*/
|
|
258
|
-
_write (encoder) {
|
|
259
|
-
encoder.writeTypeRef(YArrayRefID)
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
|
|
265
|
-
* @return {import('../utils/types.js').YType}
|
|
266
|
-
*
|
|
267
|
-
* @private
|
|
268
|
-
* @function
|
|
269
|
-
*/
|
|
270
|
-
export const readYArray = _decoder => new YArray()
|
package/src/types/YMap.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module YMap
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
AbstractType,
|
|
7
|
-
typeMapDelete,
|
|
8
|
-
typeMapSet,
|
|
9
|
-
typeMapGet,
|
|
10
|
-
typeMapHas,
|
|
11
|
-
createMapIterator,
|
|
12
|
-
YMapRefID,
|
|
13
|
-
transact,
|
|
14
|
-
warnPrematureAccess,
|
|
15
|
-
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item // eslint-disable-line
|
|
16
|
-
} from '../internals.js'
|
|
17
|
-
|
|
18
|
-
import * as iterator from 'lib0/iterator'
|
|
19
|
-
import * as delta from 'lib0/delta' // eslint-disable-line
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @template MapType
|
|
23
|
-
* A shared Map implementation.
|
|
24
|
-
*
|
|
25
|
-
* @extends AbstractType<delta.MapDelta<{[K in string]:MapType}>>
|
|
26
|
-
* @implements {Iterable<[string, MapType]>}
|
|
27
|
-
*/
|
|
28
|
-
export class YMap extends AbstractType {
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @param {Iterable<readonly [string, any]>=} entries - an optional iterable to initialize the YMap
|
|
32
|
-
*/
|
|
33
|
-
constructor (entries) {
|
|
34
|
-
super()
|
|
35
|
-
/**
|
|
36
|
-
* @type {Map<string,any>?}
|
|
37
|
-
* @private
|
|
38
|
-
*/
|
|
39
|
-
this._prelimContent = null
|
|
40
|
-
|
|
41
|
-
if (entries === undefined) {
|
|
42
|
-
this._prelimContent = new Map()
|
|
43
|
-
} else {
|
|
44
|
-
this._prelimContent = new Map(entries)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Integrate this type into the Yjs instance.
|
|
50
|
-
*
|
|
51
|
-
* * Save this struct in the os
|
|
52
|
-
* * This type is sent to other client
|
|
53
|
-
* * Observer functions are fired
|
|
54
|
-
*
|
|
55
|
-
* @param {Doc} y The Yjs instance
|
|
56
|
-
* @param {Item?} item
|
|
57
|
-
*/
|
|
58
|
-
_integrate (y, item) {
|
|
59
|
-
super._integrate(y, item)
|
|
60
|
-
;/** @type {Map<string, any>} */ (this._prelimContent).forEach((value, key) => {
|
|
61
|
-
this.set(key, value)
|
|
62
|
-
})
|
|
63
|
-
this._prelimContent = null
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Makes a copy of this data type that can be included somewhere else.
|
|
68
|
-
*
|
|
69
|
-
* Note that the content is only readable _after_ it has been included somewhere in the Ydoc.
|
|
70
|
-
*
|
|
71
|
-
* @return {this}
|
|
72
|
-
*/
|
|
73
|
-
clone () {
|
|
74
|
-
const map = this._copy()
|
|
75
|
-
this.forEach((value, key) => {
|
|
76
|
-
map.set(key, value instanceof AbstractType ? /** @type {typeof value} */ (value.clone()) : value)
|
|
77
|
-
})
|
|
78
|
-
return map
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Transforms this Shared Type to a JSON object.
|
|
83
|
-
*
|
|
84
|
-
* @return {Object<string,any>}
|
|
85
|
-
*/
|
|
86
|
-
toJSON () {
|
|
87
|
-
this.doc ?? warnPrematureAccess()
|
|
88
|
-
/**
|
|
89
|
-
* @type {Object<string,MapType>}
|
|
90
|
-
*/
|
|
91
|
-
const map = {}
|
|
92
|
-
this._map.forEach((item, key) => {
|
|
93
|
-
if (!item.deleted) {
|
|
94
|
-
const v = item.content.getContent()[item.length - 1]
|
|
95
|
-
map[key] = v instanceof AbstractType ? v.toJSON() : v
|
|
96
|
-
}
|
|
97
|
-
})
|
|
98
|
-
return map
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Returns the size of the YMap (count of key/value pairs)
|
|
103
|
-
*
|
|
104
|
-
* @return {number}
|
|
105
|
-
*/
|
|
106
|
-
get size () {
|
|
107
|
-
return [...createMapIterator(this)].length
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Returns the keys for each element in the YMap Type.
|
|
112
|
-
*
|
|
113
|
-
* @return {IterableIterator<string>}
|
|
114
|
-
*/
|
|
115
|
-
keys () {
|
|
116
|
-
return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[0])
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Returns the values for each element in the YMap Type.
|
|
121
|
-
*
|
|
122
|
-
* @return {IterableIterator<MapType>}
|
|
123
|
-
*/
|
|
124
|
-
values () {
|
|
125
|
-
return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => v[1].content.getContent()[v[1].length - 1])
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Returns an Iterator of [key, value] pairs
|
|
130
|
-
*
|
|
131
|
-
* @return {IterableIterator<[string, MapType]>}
|
|
132
|
-
*/
|
|
133
|
-
entries () {
|
|
134
|
-
return iterator.iteratorMap(createMapIterator(this), /** @param {any} v */ v => /** @type {any} */ ([v[0], v[1].content.getContent()[v[1].length - 1]]))
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Executes a provided function on once on every key-value pair.
|
|
139
|
-
*
|
|
140
|
-
* @param {function(MapType,string,YMap<MapType>):void} f A function to execute on every element of this YArray.
|
|
141
|
-
*/
|
|
142
|
-
forEach (f) {
|
|
143
|
-
this.doc ?? warnPrematureAccess()
|
|
144
|
-
this._map.forEach((item, key) => {
|
|
145
|
-
if (!item.deleted) {
|
|
146
|
-
f(item.content.getContent()[item.length - 1], key, this)
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Returns an Iterator of [key, value] pairs
|
|
153
|
-
*
|
|
154
|
-
* @return {IterableIterator<[string, MapType]>}
|
|
155
|
-
*/
|
|
156
|
-
[Symbol.iterator] () {
|
|
157
|
-
return this.entries()
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Remove a specified element from this YMap.
|
|
162
|
-
*
|
|
163
|
-
* @param {string} key The key of the element to remove.
|
|
164
|
-
*/
|
|
165
|
-
delete (key) {
|
|
166
|
-
if (this.doc !== null) {
|
|
167
|
-
transact(this.doc, transaction => {
|
|
168
|
-
typeMapDelete(transaction, this, key)
|
|
169
|
-
})
|
|
170
|
-
} else {
|
|
171
|
-
/** @type {Map<string, any>} */ (this._prelimContent).delete(key)
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Adds or updates an element with a specified key and value.
|
|
177
|
-
* @template {MapType} VAL
|
|
178
|
-
*
|
|
179
|
-
* @param {string} key The key of the element to add to this YMap
|
|
180
|
-
* @param {VAL} value The value of the element to add
|
|
181
|
-
* @return {VAL}
|
|
182
|
-
*/
|
|
183
|
-
set (key, value) {
|
|
184
|
-
if (this.doc !== null) {
|
|
185
|
-
transact(this.doc, transaction => {
|
|
186
|
-
typeMapSet(transaction, this, key, /** @type {any} */ (value))
|
|
187
|
-
})
|
|
188
|
-
} else {
|
|
189
|
-
/** @type {Map<string, any>} */ (this._prelimContent).set(key, value)
|
|
190
|
-
}
|
|
191
|
-
return value
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Returns a specified element from this YMap.
|
|
196
|
-
*
|
|
197
|
-
* @param {string} key
|
|
198
|
-
* @return {MapType|undefined}
|
|
199
|
-
*/
|
|
200
|
-
get (key) {
|
|
201
|
-
return /** @type {any} */ (typeMapGet(this, key))
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Returns a boolean indicating whether the specified key exists or not.
|
|
206
|
-
*
|
|
207
|
-
* @param {string} key The key to test.
|
|
208
|
-
* @return {boolean}
|
|
209
|
-
*/
|
|
210
|
-
has (key) {
|
|
211
|
-
return typeMapHas(this, key)
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Removes all elements from this YMap.
|
|
216
|
-
*/
|
|
217
|
-
clear () {
|
|
218
|
-
if (this.doc !== null) {
|
|
219
|
-
transact(this.doc, transaction => {
|
|
220
|
-
this.forEach(function (_value, key, map) {
|
|
221
|
-
typeMapDelete(transaction, map, key)
|
|
222
|
-
})
|
|
223
|
-
})
|
|
224
|
-
} else {
|
|
225
|
-
/** @type {Map<string, any>} */ (this._prelimContent).clear()
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
|
|
231
|
-
*/
|
|
232
|
-
_write (encoder) {
|
|
233
|
-
encoder.writeTypeRef(YMapRefID)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
|
|
239
|
-
* @return {import('../utils/types.js').YType}
|
|
240
|
-
*
|
|
241
|
-
* @private
|
|
242
|
-
* @function
|
|
243
|
-
*/
|
|
244
|
-
export const readYMap = _decoder => new YMap()
|