@liveblocks/client 0.12.2 → 0.13.1

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 (44) hide show
  1. package/README.md +34 -6
  2. package/lib/cjs/AbstractCrdt.d.ts +61 -0
  3. package/lib/cjs/AbstractCrdt.js +98 -0
  4. package/lib/cjs/LiveList.d.ts +133 -0
  5. package/lib/cjs/LiveList.js +374 -0
  6. package/lib/cjs/LiveMap.d.ts +83 -0
  7. package/lib/cjs/LiveMap.js +272 -0
  8. package/lib/cjs/LiveObject.d.ts +66 -0
  9. package/lib/cjs/LiveObject.js +368 -0
  10. package/lib/cjs/LiveRegister.d.ts +21 -0
  11. package/lib/cjs/LiveRegister.js +69 -0
  12. package/lib/cjs/index.d.ts +3 -1
  13. package/lib/cjs/index.js +7 -5
  14. package/lib/cjs/room.d.ts +50 -9
  15. package/lib/cjs/room.js +476 -85
  16. package/lib/cjs/types.d.ts +220 -40
  17. package/lib/cjs/utils.d.ts +7 -0
  18. package/lib/cjs/utils.js +64 -1
  19. package/lib/esm/AbstractCrdt.d.ts +61 -0
  20. package/lib/esm/AbstractCrdt.js +94 -0
  21. package/lib/esm/LiveList.d.ts +133 -0
  22. package/lib/esm/LiveList.js +370 -0
  23. package/lib/esm/LiveMap.d.ts +83 -0
  24. package/lib/esm/LiveMap.js +268 -0
  25. package/lib/esm/LiveObject.d.ts +66 -0
  26. package/lib/esm/LiveObject.js +364 -0
  27. package/lib/esm/LiveRegister.d.ts +21 -0
  28. package/lib/esm/LiveRegister.js +65 -0
  29. package/lib/esm/index.d.ts +3 -1
  30. package/lib/esm/index.js +3 -1
  31. package/lib/esm/room.d.ts +50 -9
  32. package/lib/esm/room.js +478 -84
  33. package/lib/esm/types.d.ts +220 -40
  34. package/lib/esm/utils.d.ts +7 -0
  35. package/lib/esm/utils.js +58 -0
  36. package/package.json +3 -3
  37. package/lib/cjs/doc.d.ts +0 -347
  38. package/lib/cjs/doc.js +0 -1349
  39. package/lib/cjs/storage.d.ts +0 -21
  40. package/lib/cjs/storage.js +0 -68
  41. package/lib/esm/doc.d.ts +0 -347
  42. package/lib/esm/doc.js +0 -1342
  43. package/lib/esm/storage.d.ts +0 -21
  44. package/lib/esm/storage.js +0 -65
@@ -0,0 +1,133 @@
1
+ import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
+ import { SerializedList, SerializedCrdtWithId, Op } from "./live";
3
+ /**
4
+ * The LiveList class represents an ordered collection of items that is synchorinized across clients.
5
+ */
6
+ export declare class LiveList<T> extends AbstractCrdt {
7
+ #private;
8
+ constructor(items?: T[]);
9
+ /**
10
+ * INTERNAL
11
+ */
12
+ static _deserialize([id, item]: [id: string, item: SerializedList], parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveList<never>;
13
+ /**
14
+ * INTERNAL
15
+ */
16
+ _serialize(parentId?: string, parentKey?: string): Op[];
17
+ /**
18
+ * INTERNAL
19
+ */
20
+ _attach(id: string, doc: Doc): void;
21
+ /**
22
+ * INTERNAL
23
+ */
24
+ _detach(): void;
25
+ /**
26
+ * INTERNAL
27
+ */
28
+ _attachChild(id: string, key: string, child: AbstractCrdt): ApplyResult;
29
+ /**
30
+ * INTERNAL
31
+ */
32
+ _detachChild(child: AbstractCrdt): void;
33
+ /**
34
+ * INTERNAL
35
+ */
36
+ _setChildKey(key: string, child: AbstractCrdt): void;
37
+ /**
38
+ * INTERNAL
39
+ */
40
+ _apply(op: Op): ApplyResult;
41
+ /**
42
+ * Returns the number of elements.
43
+ */
44
+ get length(): number;
45
+ /**
46
+ * Adds one element to the end of the LiveList.
47
+ * @param element The element to add to the end of the LiveList.
48
+ */
49
+ push(element: T): void;
50
+ /**
51
+ * Inserts one element at a specified index.
52
+ * @param element The element to insert.
53
+ * @param index The index at which you want to insert the element.
54
+ */
55
+ insert(element: T, index: number): void;
56
+ /**
57
+ * Move one element from one index to another.
58
+ * @param index The index of the element to move
59
+ * @param targetIndex The index where the element should be after moving.
60
+ */
61
+ move(index: number, targetIndex: number): void;
62
+ /**
63
+ * Deletes an element at the specified index
64
+ * @param index The index of the element to delete
65
+ */
66
+ delete(index: number): void;
67
+ /**
68
+ * Returns an Array of all the elements in the LiveList.
69
+ */
70
+ toArray(): T[];
71
+ /**
72
+ * Tests whether all elements pass the test implemented by the provided function.
73
+ * @param predicate Function to test for each element, taking two arguments (the element and its index).
74
+ * @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
75
+ */
76
+ every(predicate: (value: T, index: number) => unknown): boolean;
77
+ /**
78
+ * Creates an array with all elements that pass the test implemented by the provided function.
79
+ * @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
80
+ * @returns An array with the elements that pass the test.
81
+ */
82
+ filter(predicate: (value: T, index: number) => unknown): T[];
83
+ /**
84
+ * Returns the first element that satisfies the provided testing function.
85
+ * @param predicate Function to execute on each value.
86
+ * @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
87
+ */
88
+ find(predicate: (value: T, index: number) => unknown): T | undefined;
89
+ /**
90
+ * Returns the index of the first element in the LiveList that satisfies the provided testing function.
91
+ * @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
92
+ * @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
93
+ */
94
+ findIndex(predicate: (value: T, index: number) => unknown): number;
95
+ /**
96
+ * Executes a provided function once for each element.
97
+ * @param callbackfn Function to execute on each element.
98
+ */
99
+ forEach(callbackfn: (value: T, index: number) => void): void;
100
+ /**
101
+ * Get the element at the specified index.
102
+ * @param index The index on the element to get.
103
+ * @returns The element at the specified index or undefined.
104
+ */
105
+ get(index: number): T | undefined;
106
+ /**
107
+ * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
108
+ * @param searchElement Element to locate.
109
+ * @param fromIndex The index to start the search at.
110
+ * @returns The first index of the element in the LiveList; -1 if not found.
111
+ */
112
+ indexOf(searchElement: T, fromIndex?: number): number;
113
+ /**
114
+ * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.
115
+ * @param searchElement Element to locate.
116
+ * @param fromIndex The index at which to start searching backwards.
117
+ * @returns
118
+ */
119
+ lastIndexOf(searchElement: T, fromIndex?: number): number;
120
+ /**
121
+ * Creates an array populated with the results of calling a provided function on every element.
122
+ * @param callback Function that is called for every element.
123
+ * @returns An array with each element being the result of the callback function.
124
+ */
125
+ map<U>(callback: (value: T, index: number) => U): U[];
126
+ /**
127
+ * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
128
+ * @param predicate Function to test for each element.
129
+ * @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
130
+ */
131
+ some(predicate: (value: T, index: number) => unknown): boolean;
132
+ [Symbol.iterator](): IterableIterator<T>;
133
+ }
@@ -0,0 +1,370 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
+ };
12
+ var _LiveList_items, _LiveListIterator_innerIterator;
13
+ import { AbstractCrdt } from "./AbstractCrdt";
14
+ import { deserialize, selfOrRegister, selfOrRegisterValue } from "./utils";
15
+ import { OpType, } from "./live";
16
+ import { makePosition, compare } from "./position";
17
+ /**
18
+ * The LiveList class represents an ordered collection of items that is synchorinized across clients.
19
+ */
20
+ export class LiveList extends AbstractCrdt {
21
+ constructor(items = []) {
22
+ super();
23
+ // TODO: Naive array at first, find a better data structure. Maybe an Order statistics tree?
24
+ _LiveList_items.set(this, []);
25
+ let position = undefined;
26
+ for (let i = 0; i < items.length; i++) {
27
+ const newPosition = makePosition(position);
28
+ const item = selfOrRegister(items[i]);
29
+ __classPrivateFieldGet(this, _LiveList_items, "f").push([item, newPosition]);
30
+ position = newPosition;
31
+ }
32
+ }
33
+ /**
34
+ * INTERNAL
35
+ */
36
+ static _deserialize([id, item], parentToChildren, doc) {
37
+ const list = new LiveList([]);
38
+ list._attach(id, doc);
39
+ const children = parentToChildren.get(id);
40
+ if (children == null) {
41
+ return list;
42
+ }
43
+ for (const entry of children) {
44
+ const child = deserialize(entry, parentToChildren, doc);
45
+ child._setParentLink(list, entry[1].parentKey);
46
+ __classPrivateFieldGet(list, _LiveList_items, "f").push([child, entry[1].parentKey]);
47
+ __classPrivateFieldGet(list, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
48
+ }
49
+ return list;
50
+ }
51
+ /**
52
+ * INTERNAL
53
+ */
54
+ _serialize(parentId, parentKey) {
55
+ if (this._id == null) {
56
+ throw new Error("Cannot serialize item is not attached");
57
+ }
58
+ if (parentId == null || parentKey == null) {
59
+ throw new Error("Cannot serialize list if parentId or parentKey is undefined");
60
+ }
61
+ const ops = [];
62
+ const op = {
63
+ id: this._id,
64
+ type: OpType.CreateList,
65
+ parentId,
66
+ parentKey,
67
+ };
68
+ ops.push(op);
69
+ for (const [value, key] of __classPrivateFieldGet(this, _LiveList_items, "f")) {
70
+ ops.push(...value._serialize(this._id, key));
71
+ }
72
+ return ops;
73
+ }
74
+ /**
75
+ * INTERNAL
76
+ */
77
+ _attach(id, doc) {
78
+ super._attach(id, doc);
79
+ for (const [item, position] of __classPrivateFieldGet(this, _LiveList_items, "f")) {
80
+ item._attach(doc.generateId(), doc);
81
+ }
82
+ }
83
+ /**
84
+ * INTERNAL
85
+ */
86
+ _detach() {
87
+ super._detach();
88
+ for (const [value] of __classPrivateFieldGet(this, _LiveList_items, "f")) {
89
+ value._detach();
90
+ }
91
+ }
92
+ /**
93
+ * INTERNAL
94
+ */
95
+ _attachChild(id, key, child) {
96
+ var _a;
97
+ if (this._doc == null) {
98
+ throw new Error("Can't attach child if doc is not present");
99
+ }
100
+ child._attach(id, this._doc);
101
+ child._setParentLink(this, key);
102
+ const index = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === key);
103
+ // Assign a temporary position until we get the fix from the backend
104
+ if (index !== -1) {
105
+ __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] = makePosition(key, (_a = __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1]) === null || _a === void 0 ? void 0 : _a[1]);
106
+ }
107
+ __classPrivateFieldGet(this, _LiveList_items, "f").push([child, key]);
108
+ __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
109
+ return { reverse: [{ type: OpType.DeleteCrdt, id }], modified: this };
110
+ }
111
+ /**
112
+ * INTERNAL
113
+ */
114
+ _detachChild(child) {
115
+ const indexToDelete = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((item) => item[0] === child);
116
+ __classPrivateFieldGet(this, _LiveList_items, "f").splice(indexToDelete, 1);
117
+ if (child) {
118
+ child._detach();
119
+ }
120
+ }
121
+ /**
122
+ * INTERNAL
123
+ */
124
+ _setChildKey(key, child) {
125
+ var _a;
126
+ child._setParentLink(this, key);
127
+ const index = __classPrivateFieldGet(this, _LiveList_items, "f").findIndex((entry) => entry[1] === key);
128
+ // Assign a temporary position until we get the fix from the backend
129
+ if (index !== -1) {
130
+ __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] = makePosition(key, (_a = __classPrivateFieldGet(this, _LiveList_items, "f")[index + 1]) === null || _a === void 0 ? void 0 : _a[1]);
131
+ }
132
+ const item = __classPrivateFieldGet(this, _LiveList_items, "f").find((item) => item[0] === child);
133
+ if (item) {
134
+ item[1] = key;
135
+ }
136
+ __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
137
+ }
138
+ /**
139
+ * INTERNAL
140
+ */
141
+ _apply(op) {
142
+ return super._apply(op);
143
+ }
144
+ /**
145
+ * Returns the number of elements.
146
+ */
147
+ get length() {
148
+ return __classPrivateFieldGet(this, _LiveList_items, "f").length;
149
+ }
150
+ /**
151
+ * Adds one element to the end of the LiveList.
152
+ * @param element The element to add to the end of the LiveList.
153
+ */
154
+ push(element) {
155
+ return this.insert(element, this.length);
156
+ }
157
+ /**
158
+ * Inserts one element at a specified index.
159
+ * @param element The element to insert.
160
+ * @param index The index at which you want to insert the element.
161
+ */
162
+ insert(element, index) {
163
+ if (index < 0 || index > __classPrivateFieldGet(this, _LiveList_items, "f").length) {
164
+ throw new Error(`Cannot delete list item at index "${index}". index should be between 0 and ${__classPrivateFieldGet(this, _LiveList_items, "f").length}`);
165
+ }
166
+ let before = __classPrivateFieldGet(this, _LiveList_items, "f")[index - 1] ? __classPrivateFieldGet(this, _LiveList_items, "f")[index - 1][1] : undefined;
167
+ let after = __classPrivateFieldGet(this, _LiveList_items, "f")[index] ? __classPrivateFieldGet(this, _LiveList_items, "f")[index][1] : undefined;
168
+ const position = makePosition(before, after);
169
+ const value = selfOrRegister(element);
170
+ value._setParentLink(this, position);
171
+ __classPrivateFieldGet(this, _LiveList_items, "f").push([value, position]);
172
+ __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
173
+ if (this._doc && this._id) {
174
+ const id = this._doc.generateId();
175
+ value._attach(id, this._doc);
176
+ this._doc.dispatch(value._serialize(this._id, position), [{ type: OpType.DeleteCrdt, id }], [this]);
177
+ }
178
+ }
179
+ /**
180
+ * Move one element from one index to another.
181
+ * @param index The index of the element to move
182
+ * @param targetIndex The index where the element should be after moving.
183
+ */
184
+ move(index, targetIndex) {
185
+ if (targetIndex < 0) {
186
+ throw new Error("targetIndex cannot be less than 0");
187
+ }
188
+ if (targetIndex >= __classPrivateFieldGet(this, _LiveList_items, "f").length) {
189
+ throw new Error("targetIndex cannot be greater or equal than the list length");
190
+ }
191
+ if (index < 0) {
192
+ throw new Error("index cannot be less than 0");
193
+ }
194
+ if (index >= __classPrivateFieldGet(this, _LiveList_items, "f").length) {
195
+ throw new Error("index cannot be greater or equal than the list length");
196
+ }
197
+ let beforePosition = null;
198
+ let afterPosition = null;
199
+ if (index < targetIndex) {
200
+ afterPosition =
201
+ targetIndex === __classPrivateFieldGet(this, _LiveList_items, "f").length - 1
202
+ ? undefined
203
+ : __classPrivateFieldGet(this, _LiveList_items, "f")[targetIndex + 1][1];
204
+ beforePosition = __classPrivateFieldGet(this, _LiveList_items, "f")[targetIndex][1];
205
+ }
206
+ else {
207
+ afterPosition = __classPrivateFieldGet(this, _LiveList_items, "f")[targetIndex][1];
208
+ beforePosition =
209
+ targetIndex === 0 ? undefined : __classPrivateFieldGet(this, _LiveList_items, "f")[targetIndex - 1][1];
210
+ }
211
+ const position = makePosition(beforePosition, afterPosition);
212
+ const item = __classPrivateFieldGet(this, _LiveList_items, "f")[index];
213
+ const previousPosition = item[1];
214
+ item[1] = position;
215
+ item[0]._setParentLink(this, position);
216
+ __classPrivateFieldGet(this, _LiveList_items, "f").sort((itemA, itemB) => compare(itemA[1], itemB[1]));
217
+ if (this._doc && this._id) {
218
+ this._doc.dispatch([
219
+ {
220
+ type: OpType.SetParentKey,
221
+ id: item[0]._id,
222
+ parentKey: position,
223
+ },
224
+ ], [
225
+ {
226
+ type: OpType.SetParentKey,
227
+ id: item[0]._id,
228
+ parentKey: previousPosition,
229
+ },
230
+ ], [this]);
231
+ }
232
+ }
233
+ /**
234
+ * Deletes an element at the specified index
235
+ * @param index The index of the element to delete
236
+ */
237
+ delete(index) {
238
+ if (index < 0 || index >= __classPrivateFieldGet(this, _LiveList_items, "f").length) {
239
+ throw new Error(`Cannot delete list item at index "${index}". index should be between 0 and ${__classPrivateFieldGet(this, _LiveList_items, "f").length - 1}`);
240
+ }
241
+ const item = __classPrivateFieldGet(this, _LiveList_items, "f")[index];
242
+ item[0]._detach();
243
+ __classPrivateFieldGet(this, _LiveList_items, "f").splice(index, 1);
244
+ if (this._doc) {
245
+ const childRecordId = item[0]._id;
246
+ if (childRecordId) {
247
+ this._doc.dispatch([
248
+ {
249
+ id: childRecordId,
250
+ type: OpType.DeleteCrdt,
251
+ },
252
+ ], item[0]._serialize(this._id, item[1]), [this]);
253
+ }
254
+ }
255
+ }
256
+ /**
257
+ * Returns an Array of all the elements in the LiveList.
258
+ */
259
+ toArray() {
260
+ return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry) => selfOrRegisterValue(entry[0]));
261
+ }
262
+ /**
263
+ * Tests whether all elements pass the test implemented by the provided function.
264
+ * @param predicate Function to test for each element, taking two arguments (the element and its index).
265
+ * @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
266
+ */
267
+ every(predicate) {
268
+ return this.toArray().every(predicate);
269
+ }
270
+ /**
271
+ * Creates an array with all elements that pass the test implemented by the provided function.
272
+ * @param predicate Function to test each element of the LiveList. Return a value that coerces to true to keep the element, or to false otherwise.
273
+ * @returns An array with the elements that pass the test.
274
+ */
275
+ filter(predicate) {
276
+ return this.toArray().filter(predicate);
277
+ }
278
+ /**
279
+ * Returns the first element that satisfies the provided testing function.
280
+ * @param predicate Function to execute on each value.
281
+ * @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
282
+ */
283
+ find(predicate) {
284
+ return this.toArray().find(predicate);
285
+ }
286
+ /**
287
+ * Returns the index of the first element in the LiveList that satisfies the provided testing function.
288
+ * @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
289
+ * @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
290
+ */
291
+ findIndex(predicate) {
292
+ return this.toArray().findIndex(predicate);
293
+ }
294
+ /**
295
+ * Executes a provided function once for each element.
296
+ * @param callbackfn Function to execute on each element.
297
+ */
298
+ forEach(callbackfn) {
299
+ return this.toArray().forEach(callbackfn);
300
+ }
301
+ /**
302
+ * Get the element at the specified index.
303
+ * @param index The index on the element to get.
304
+ * @returns The element at the specified index or undefined.
305
+ */
306
+ get(index) {
307
+ if (index < 0 || index >= __classPrivateFieldGet(this, _LiveList_items, "f").length) {
308
+ return undefined;
309
+ }
310
+ return selfOrRegisterValue(__classPrivateFieldGet(this, _LiveList_items, "f")[index][0]);
311
+ }
312
+ /**
313
+ * Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
314
+ * @param searchElement Element to locate.
315
+ * @param fromIndex The index to start the search at.
316
+ * @returns The first index of the element in the LiveList; -1 if not found.
317
+ */
318
+ indexOf(searchElement, fromIndex) {
319
+ return this.toArray().indexOf(searchElement, fromIndex);
320
+ }
321
+ /**
322
+ * Returns the last index at which a given element can be found in the LiveList, or -1 if it is not present. The LiveLsit is searched backwards, starting at fromIndex.
323
+ * @param searchElement Element to locate.
324
+ * @param fromIndex The index at which to start searching backwards.
325
+ * @returns
326
+ */
327
+ lastIndexOf(searchElement, fromIndex) {
328
+ return this.toArray().lastIndexOf(searchElement, fromIndex);
329
+ }
330
+ /**
331
+ * Creates an array populated with the results of calling a provided function on every element.
332
+ * @param callback Function that is called for every element.
333
+ * @returns An array with each element being the result of the callback function.
334
+ */
335
+ map(callback) {
336
+ return __classPrivateFieldGet(this, _LiveList_items, "f").map((entry, i) => callback(selfOrRegisterValue(entry[0]), i));
337
+ }
338
+ /**
339
+ * Tests whether at least one element in the LiveList passes the test implemented by the provided function.
340
+ * @param predicate Function to test for each element.
341
+ * @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
342
+ */
343
+ some(predicate) {
344
+ return this.toArray().some(predicate);
345
+ }
346
+ [(_LiveList_items = new WeakMap(), Symbol.iterator)]() {
347
+ return new LiveListIterator(__classPrivateFieldGet(this, _LiveList_items, "f"));
348
+ }
349
+ }
350
+ class LiveListIterator {
351
+ constructor(items) {
352
+ _LiveListIterator_innerIterator.set(this, void 0);
353
+ __classPrivateFieldSet(this, _LiveListIterator_innerIterator, items[Symbol.iterator](), "f");
354
+ }
355
+ [(_LiveListIterator_innerIterator = new WeakMap(), Symbol.iterator)]() {
356
+ return this;
357
+ }
358
+ next() {
359
+ const result = __classPrivateFieldGet(this, _LiveListIterator_innerIterator, "f").next();
360
+ if (result.done) {
361
+ return {
362
+ done: true,
363
+ value: undefined,
364
+ };
365
+ }
366
+ return {
367
+ value: selfOrRegisterValue(result.value[0]),
368
+ };
369
+ }
370
+ }
@@ -0,0 +1,83 @@
1
+ import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
+ import { Op, SerializedCrdtWithId } from "./live";
3
+ /**
4
+ * The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
5
+ * Keys should be a string, and values should be serializable to JSON.
6
+ * If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
7
+ */
8
+ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
9
+ #private;
10
+ constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
11
+ /**
12
+ * INTERNAL
13
+ */
14
+ _serialize(parentId?: string, parentKey?: string): Op[];
15
+ /**
16
+ * INTERNAL
17
+ */
18
+ static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveMap<string, unknown>;
19
+ /**
20
+ * INTERNAL
21
+ */
22
+ _attach(id: string, doc: Doc): void;
23
+ /**
24
+ * INTERNAL
25
+ */
26
+ _attachChild(id: string, key: TKey, child: AbstractCrdt): ApplyResult;
27
+ /**
28
+ * INTERNAL
29
+ */
30
+ _detach(): void;
31
+ /**
32
+ * INTERNAL
33
+ */
34
+ _detachChild(child: AbstractCrdt): void;
35
+ /**
36
+ * Returns a specified element from the LiveMap.
37
+ * @param key The key of the element to return.
38
+ * @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
39
+ */
40
+ get(key: TKey): TValue | undefined;
41
+ /**
42
+ * Adds or updates an element with a specified key and a value.
43
+ * @param key The key of the element to add. Should be a string.
44
+ * @param value The value of the element to add. Should be serializable to JSON.
45
+ */
46
+ set(key: TKey, value: TValue): void;
47
+ /**
48
+ * Returns the number of elements in the LiveMap.
49
+ */
50
+ get size(): number;
51
+ /**
52
+ * Returns a boolean indicating whether an element with the specified key exists or not.
53
+ * @param key The key of the element to test for presence.
54
+ */
55
+ has(key: TKey): boolean;
56
+ /**
57
+ * Removes the specified element by key.
58
+ * @param key The key of the element to remove.
59
+ * @returns true if an element existed and has been removed, or false if the element does not exist.
60
+ */
61
+ delete(key: TKey): boolean;
62
+ /**
63
+ * Returns a new Iterator object that contains the [key, value] pairs for each element.
64
+ */
65
+ entries(): IterableIterator<[string, TValue]>;
66
+ /**
67
+ * Same function object as the initial value of the entries method.
68
+ */
69
+ [Symbol.iterator](): IterableIterator<[string, TValue]>;
70
+ /**
71
+ * Returns a new Iterator object that contains the keys for each element.
72
+ */
73
+ keys(): IterableIterator<TKey>;
74
+ /**
75
+ * Returns a new Iterator object that contains the values for each element.
76
+ */
77
+ values(): IterableIterator<TValue>;
78
+ /**
79
+ * Executes a provided function once per each key/value pair in the Map object, in insertion order.
80
+ * @param callback Function to execute for each entry in the map.
81
+ */
82
+ forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
83
+ }