@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.
- package/README.md +34 -6
- package/lib/cjs/AbstractCrdt.d.ts +61 -0
- package/lib/cjs/AbstractCrdt.js +98 -0
- package/lib/cjs/LiveList.d.ts +133 -0
- package/lib/cjs/LiveList.js +374 -0
- package/lib/cjs/LiveMap.d.ts +83 -0
- package/lib/cjs/LiveMap.js +272 -0
- package/lib/cjs/LiveObject.d.ts +66 -0
- package/lib/cjs/LiveObject.js +368 -0
- package/lib/cjs/LiveRegister.d.ts +21 -0
- package/lib/cjs/LiveRegister.js +69 -0
- package/lib/cjs/index.d.ts +3 -1
- package/lib/cjs/index.js +7 -5
- package/lib/cjs/room.d.ts +50 -9
- package/lib/cjs/room.js +476 -85
- package/lib/cjs/types.d.ts +220 -40
- package/lib/cjs/utils.d.ts +7 -0
- package/lib/cjs/utils.js +64 -1
- package/lib/esm/AbstractCrdt.d.ts +61 -0
- package/lib/esm/AbstractCrdt.js +94 -0
- package/lib/esm/LiveList.d.ts +133 -0
- package/lib/esm/LiveList.js +370 -0
- package/lib/esm/LiveMap.d.ts +83 -0
- package/lib/esm/LiveMap.js +268 -0
- package/lib/esm/LiveObject.d.ts +66 -0
- package/lib/esm/LiveObject.js +364 -0
- package/lib/esm/LiveRegister.d.ts +21 -0
- package/lib/esm/LiveRegister.js +65 -0
- package/lib/esm/index.d.ts +3 -1
- package/lib/esm/index.js +3 -1
- package/lib/esm/room.d.ts +50 -9
- package/lib/esm/room.js +478 -84
- package/lib/esm/types.d.ts +220 -40
- package/lib/esm/utils.d.ts +7 -0
- package/lib/esm/utils.js +58 -0
- package/package.json +3 -3
- package/lib/cjs/doc.d.ts +0 -347
- package/lib/cjs/doc.js +0 -1349
- package/lib/cjs/storage.d.ts +0 -21
- package/lib/cjs/storage.js +0 -68
- package/lib/esm/doc.d.ts +0 -347
- package/lib/esm/doc.js +0 -1342
- package/lib/esm/storage.d.ts +0 -21
- package/lib/esm/storage.js +0 -65
package/lib/cjs/doc.d.ts
DELETED
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
import { Op, SerializedCrdtWithId, SerializedList } from "./live";
|
|
2
|
-
declare type Dispatch = (ops: Op[]) => void;
|
|
3
|
-
export declare class Doc<T extends Record<string, any> = Record<string, any>> {
|
|
4
|
-
#private;
|
|
5
|
-
private constructor();
|
|
6
|
-
static from<T>(root: T, actor?: number, dispatch?: Dispatch): Doc<T>;
|
|
7
|
-
static load<T>(items: SerializedCrdtWithId[], actor: number, dispatch?: Dispatch): Doc<T>;
|
|
8
|
-
dispatch(ops: Op[]): void;
|
|
9
|
-
addItem(id: string, item: AbstractCrdt): void;
|
|
10
|
-
deleteItem(id: string): void;
|
|
11
|
-
getItem(id: string): AbstractCrdt | undefined;
|
|
12
|
-
apply(ops: Op[]): Op[];
|
|
13
|
-
get root(): LiveObject<T>;
|
|
14
|
-
addToUndoStack(ops: Op[]): void;
|
|
15
|
-
undo(): void;
|
|
16
|
-
redo(): void;
|
|
17
|
-
count(): number;
|
|
18
|
-
generateId(): string;
|
|
19
|
-
generateOpId(): string;
|
|
20
|
-
}
|
|
21
|
-
declare abstract class AbstractCrdt {
|
|
22
|
-
#private;
|
|
23
|
-
/**
|
|
24
|
-
* INTERNAL
|
|
25
|
-
*/
|
|
26
|
-
protected get _doc(): Doc<Record<string, any>> | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* INTERNAL
|
|
29
|
-
*/
|
|
30
|
-
get _id(): string | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* INTERNAL
|
|
33
|
-
*/
|
|
34
|
-
get _parent(): AbstractCrdt | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* INTERNAL
|
|
37
|
-
*/
|
|
38
|
-
get _parentKey(): string | undefined;
|
|
39
|
-
_apply(op: Op): Op[];
|
|
40
|
-
/**
|
|
41
|
-
* INTERNAL
|
|
42
|
-
*/
|
|
43
|
-
_setParentLink(parent: AbstractCrdt, key: string): void;
|
|
44
|
-
/**
|
|
45
|
-
* INTERNAL
|
|
46
|
-
*/
|
|
47
|
-
_attach(id: string, doc: Doc): void;
|
|
48
|
-
abstract _attachChild(id: string, key: string, crdt: AbstractCrdt): Op[];
|
|
49
|
-
/**
|
|
50
|
-
* INTERNAL
|
|
51
|
-
*/
|
|
52
|
-
_detach(): void;
|
|
53
|
-
abstract _detachChild(crdt: AbstractCrdt): void;
|
|
54
|
-
/**
|
|
55
|
-
* Subscribes to updates.
|
|
56
|
-
*/
|
|
57
|
-
subscribe(listener: () => void): void;
|
|
58
|
-
/**
|
|
59
|
-
* Subscribes to updates and children updates.
|
|
60
|
-
*/
|
|
61
|
-
subscribeDeep(listener: () => void): void;
|
|
62
|
-
/**
|
|
63
|
-
* Unsubscribes to updates.
|
|
64
|
-
*/
|
|
65
|
-
unsubscribe(listener: () => void): void;
|
|
66
|
-
/**
|
|
67
|
-
* Unsubscribes to updates and children updates.
|
|
68
|
-
*/
|
|
69
|
-
unsubscribeDeep(listener: () => void): void;
|
|
70
|
-
/**
|
|
71
|
-
* INTERNAL
|
|
72
|
-
*/
|
|
73
|
-
_notify(onlyDeep?: boolean): void;
|
|
74
|
-
abstract _serialize(parentId: string, parentKey: string): Op[];
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* The LiveObject class is similar to a JavaScript object that is synchronized on all clients.
|
|
78
|
-
* Keys should be a string, and values should be serializable to JSON.
|
|
79
|
-
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
80
|
-
*/
|
|
81
|
-
export declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
|
|
82
|
-
#private;
|
|
83
|
-
constructor(object?: T);
|
|
84
|
-
/**
|
|
85
|
-
* INTERNAL
|
|
86
|
-
*/
|
|
87
|
-
_serialize(parentId?: string, parentKey?: string): Op[];
|
|
88
|
-
/**
|
|
89
|
-
* INTERNAL
|
|
90
|
-
*/
|
|
91
|
-
static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveObject<{
|
|
92
|
-
[key: string]: any;
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* INTERNAL
|
|
96
|
-
*/
|
|
97
|
-
_attach(id: string, doc: Doc): void;
|
|
98
|
-
/**
|
|
99
|
-
* INTERNAL
|
|
100
|
-
*/
|
|
101
|
-
_attachChild(id: string, key: keyof T, child: AbstractCrdt): Op[];
|
|
102
|
-
/**
|
|
103
|
-
* INTERNAL
|
|
104
|
-
*/
|
|
105
|
-
_detachChild(child: AbstractCrdt): void;
|
|
106
|
-
/**
|
|
107
|
-
* INTERNAL
|
|
108
|
-
*/
|
|
109
|
-
_detach(): void;
|
|
110
|
-
/**
|
|
111
|
-
* INTERNAL
|
|
112
|
-
*/
|
|
113
|
-
_apply(op: Op): Op[];
|
|
114
|
-
/**
|
|
115
|
-
* Transform the LiveObject into a javascript object
|
|
116
|
-
*/
|
|
117
|
-
toObject(): T;
|
|
118
|
-
/**
|
|
119
|
-
* Adds or updates a property with a specified key and a value.
|
|
120
|
-
* @param key The key of the property to add
|
|
121
|
-
* @param value The value of the property to add
|
|
122
|
-
*/
|
|
123
|
-
set<TKey extends keyof T>(key: TKey, value: T[TKey]): void;
|
|
124
|
-
/**
|
|
125
|
-
* Returns a specified property from the LiveObject.
|
|
126
|
-
* @param key The key of the property to get
|
|
127
|
-
*/
|
|
128
|
-
get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
129
|
-
/**
|
|
130
|
-
* Adds or updates multiple properties at once with an object.
|
|
131
|
-
* @param overrides The object used to overrides properties
|
|
132
|
-
*/
|
|
133
|
-
update(overrides: Partial<T>): void;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* The LiveMap class is similar to a JavaScript Map that is synchronized on all clients.
|
|
137
|
-
* Keys should be a string, and values should be serializable to JSON.
|
|
138
|
-
* If multiple clients update the same property simultaneously, the last modification received by the Liveblocks servers is the winner.
|
|
139
|
-
*/
|
|
140
|
-
export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
141
|
-
#private;
|
|
142
|
-
constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
|
|
143
|
-
/**
|
|
144
|
-
* INTERNAL
|
|
145
|
-
*/
|
|
146
|
-
_serialize(parentId?: string, parentKey?: string): Op[];
|
|
147
|
-
/**
|
|
148
|
-
* INTERNAL
|
|
149
|
-
*/
|
|
150
|
-
static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveMap<string, unknown>;
|
|
151
|
-
/**
|
|
152
|
-
* INTERNAL
|
|
153
|
-
*/
|
|
154
|
-
_attach(id: string, doc: Doc): void;
|
|
155
|
-
/**
|
|
156
|
-
* INTERNAL
|
|
157
|
-
*/
|
|
158
|
-
_attachChild(id: string, key: TKey, child: AbstractCrdt): Op[];
|
|
159
|
-
/**
|
|
160
|
-
* INTERNAL
|
|
161
|
-
*/
|
|
162
|
-
_detach(): void;
|
|
163
|
-
/**
|
|
164
|
-
* INTERNAL
|
|
165
|
-
*/
|
|
166
|
-
_detachChild(child: AbstractCrdt): void;
|
|
167
|
-
/**
|
|
168
|
-
* Returns a specified element from the LiveMap.
|
|
169
|
-
* @param key The key of the element to return.
|
|
170
|
-
* @returns The element associated with the specified key, or undefined if the key can't be found in the LiveMap.
|
|
171
|
-
*/
|
|
172
|
-
get(key: TKey): TValue | undefined;
|
|
173
|
-
/**
|
|
174
|
-
* Adds or updates an element with a specified key and a value.
|
|
175
|
-
* @param key The key of the element to add. Should be a string.
|
|
176
|
-
* @param value The value of the element to add. Should be serializable to JSON.
|
|
177
|
-
*/
|
|
178
|
-
set(key: TKey, value: TValue): void;
|
|
179
|
-
/**
|
|
180
|
-
* Returns the number of elements in the LiveMap.
|
|
181
|
-
*/
|
|
182
|
-
get size(): number;
|
|
183
|
-
/**
|
|
184
|
-
* Returns a boolean indicating whether an element with the specified key exists or not.
|
|
185
|
-
* @param key The key of the element to test for presence.
|
|
186
|
-
*/
|
|
187
|
-
has(key: TKey): boolean;
|
|
188
|
-
/**
|
|
189
|
-
* Removes the specified element by key.
|
|
190
|
-
* @param key The key of the element to remove.
|
|
191
|
-
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
192
|
-
*/
|
|
193
|
-
delete(key: TKey): boolean;
|
|
194
|
-
/**
|
|
195
|
-
* Returns a new Iterator object that contains the [key, value] pairs for each element.
|
|
196
|
-
*/
|
|
197
|
-
entries(): IterableIterator<[string, TValue]>;
|
|
198
|
-
/**
|
|
199
|
-
* Same function object as the initial value of the entries method.
|
|
200
|
-
*/
|
|
201
|
-
[Symbol.iterator](): IterableIterator<[string, TValue]>;
|
|
202
|
-
/**
|
|
203
|
-
* Returns a new Iterator object that contains the keys for each element.
|
|
204
|
-
*/
|
|
205
|
-
keys(): IterableIterator<TKey>;
|
|
206
|
-
/**
|
|
207
|
-
* Returns a new Iterator object that contains the values for each element.
|
|
208
|
-
*/
|
|
209
|
-
values(): IterableIterator<TValue>;
|
|
210
|
-
/**
|
|
211
|
-
* Executes a provided function once per each key/value pair in the Map object, in insertion order.
|
|
212
|
-
* @param callback Function to execute for each entry in the map.
|
|
213
|
-
*/
|
|
214
|
-
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* The LiveList class represents an ordered collection of items that is synchorinized across clients.
|
|
218
|
-
*/
|
|
219
|
-
export declare class LiveList<T> extends AbstractCrdt {
|
|
220
|
-
#private;
|
|
221
|
-
constructor(items?: T[]);
|
|
222
|
-
/**
|
|
223
|
-
* INTERNAL
|
|
224
|
-
*/
|
|
225
|
-
static _deserialize([id, item]: [id: string, item: SerializedList], parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveList<never>;
|
|
226
|
-
/**
|
|
227
|
-
* INTERNAL
|
|
228
|
-
*/
|
|
229
|
-
_serialize(parentId?: string, parentKey?: string): Op[];
|
|
230
|
-
/**
|
|
231
|
-
* INTERNAL
|
|
232
|
-
*/
|
|
233
|
-
_attach(id: string, doc: Doc): void;
|
|
234
|
-
/**
|
|
235
|
-
* INTERNAL
|
|
236
|
-
*/
|
|
237
|
-
_detach(): void;
|
|
238
|
-
/**
|
|
239
|
-
* INTERNAL
|
|
240
|
-
*/
|
|
241
|
-
_attachChild(id: string, key: string, child: AbstractCrdt): Op[];
|
|
242
|
-
/**
|
|
243
|
-
* INTERNAL
|
|
244
|
-
*/
|
|
245
|
-
_detachChild(child: AbstractCrdt): void;
|
|
246
|
-
/**
|
|
247
|
-
* INTERNAL
|
|
248
|
-
*/
|
|
249
|
-
_setChildKey(key: string, child: AbstractCrdt): void;
|
|
250
|
-
/**
|
|
251
|
-
* INTERNAL
|
|
252
|
-
*/
|
|
253
|
-
_apply(op: Op): Op[];
|
|
254
|
-
/**
|
|
255
|
-
* Returns the number of elements.
|
|
256
|
-
*/
|
|
257
|
-
get length(): number;
|
|
258
|
-
/**
|
|
259
|
-
* Adds one element to the end of the LiveList.
|
|
260
|
-
* @param element The element to add to the end of the LiveList.
|
|
261
|
-
*/
|
|
262
|
-
push(element: T): void;
|
|
263
|
-
/**
|
|
264
|
-
* Inserts one element at a specified index.
|
|
265
|
-
* @param element The element to insert.
|
|
266
|
-
* @param index The index at which you want to insert the element.
|
|
267
|
-
*/
|
|
268
|
-
insert(element: T, index: number): void;
|
|
269
|
-
/**
|
|
270
|
-
* Move one element from one index to another.
|
|
271
|
-
* @param index The index of the element to move
|
|
272
|
-
* @param targetIndex The index where the element should be after moving.
|
|
273
|
-
*/
|
|
274
|
-
move(index: number, targetIndex: number): void;
|
|
275
|
-
/**
|
|
276
|
-
* Deletes an element at the specified index
|
|
277
|
-
* @param index The index of the element to delete
|
|
278
|
-
*/
|
|
279
|
-
delete(index: number): void;
|
|
280
|
-
/**
|
|
281
|
-
* Returns an Array of all the elements in the LiveList.
|
|
282
|
-
*/
|
|
283
|
-
toArray(): T[];
|
|
284
|
-
/**
|
|
285
|
-
* Tests whether all elements pass the test implemented by the provided function.
|
|
286
|
-
* @param predicate Function to test for each element, taking two arguments (the element and its index).
|
|
287
|
-
* @returns true if the predicate function returns a truthy value for every element. Otherwise, false.
|
|
288
|
-
*/
|
|
289
|
-
every(predicate: (value: T, index: number) => unknown): boolean;
|
|
290
|
-
/**
|
|
291
|
-
* Creates an array with all elements that pass the test implemented by the provided function.
|
|
292
|
-
* @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.
|
|
293
|
-
* @returns An array with the elements that pass the test.
|
|
294
|
-
*/
|
|
295
|
-
filter(predicate: (value: T, index: number) => unknown): T[];
|
|
296
|
-
/**
|
|
297
|
-
* Returns the first element that satisfies the provided testing function.
|
|
298
|
-
* @param predicate Function to execute on each value.
|
|
299
|
-
* @returns The value of the first element in the LiveList that satisfies the provided testing function. Otherwise, undefined is returned.
|
|
300
|
-
*/
|
|
301
|
-
find(predicate: (value: T, index: number) => unknown): T | undefined;
|
|
302
|
-
/**
|
|
303
|
-
* Returns the index of the first element in the LiveList that satisfies the provided testing function.
|
|
304
|
-
* @param predicate Function to execute on each value until the function returns true, indicating that the satisfying element was found.
|
|
305
|
-
* @returns The index of the first element in the LiveList that passes the test. Otherwise, -1.
|
|
306
|
-
*/
|
|
307
|
-
findIndex(predicate: (value: T, index: number) => unknown): number;
|
|
308
|
-
/**
|
|
309
|
-
* Executes a provided function once for each element.
|
|
310
|
-
* @param callbackfn Function to execute on each element.
|
|
311
|
-
*/
|
|
312
|
-
forEach(callbackfn: (value: T, index: number) => void): void;
|
|
313
|
-
/**
|
|
314
|
-
* Get the element at the specified index.
|
|
315
|
-
* @param index The index on the element to get.
|
|
316
|
-
* @returns The element at the specified index or undefined.
|
|
317
|
-
*/
|
|
318
|
-
get(index: number): T | undefined;
|
|
319
|
-
/**
|
|
320
|
-
* Returns the first index at which a given element can be found in the LiveList, or -1 if it is not present.
|
|
321
|
-
* @param searchElement Element to locate.
|
|
322
|
-
* @param fromIndex The index to start the search at.
|
|
323
|
-
* @returns The first index of the element in the LiveList; -1 if not found.
|
|
324
|
-
*/
|
|
325
|
-
indexOf(searchElement: T, fromIndex?: number): number;
|
|
326
|
-
/**
|
|
327
|
-
* 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.
|
|
328
|
-
* @param searchElement Element to locate.
|
|
329
|
-
* @param fromIndex The index at which to start searching backwards.
|
|
330
|
-
* @returns
|
|
331
|
-
*/
|
|
332
|
-
lastIndexOf(searchElement: T, fromIndex?: number): number;
|
|
333
|
-
/**
|
|
334
|
-
* Creates an array populated with the results of calling a provided function on every element.
|
|
335
|
-
* @param callback Function that is called for every element.
|
|
336
|
-
* @returns An array with each element being the result of the callback function.
|
|
337
|
-
*/
|
|
338
|
-
map<U>(callback: (value: T, index: number) => U): U[];
|
|
339
|
-
/**
|
|
340
|
-
* Tests whether at least one element in the LiveList passes the test implemented by the provided function.
|
|
341
|
-
* @param predicate Function to test for each element.
|
|
342
|
-
* @returns true if the callback function returns a truthy value for at least one element. Otherwise, false.
|
|
343
|
-
*/
|
|
344
|
-
some(predicate: (value: T, index: number) => unknown): boolean;
|
|
345
|
-
[Symbol.iterator](): IterableIterator<T>;
|
|
346
|
-
}
|
|
347
|
-
export {};
|