@liveblocks/client 0.12.0-beta.10 → 0.12.0-beta.14
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 +2 -12
- package/lib/cjs/doc.d.ts +180 -10
- package/lib/cjs/doc.js +479 -184
- package/lib/cjs/live.d.ts +1 -0
- package/lib/cjs/room.d.ts +2 -0
- package/lib/cjs/room.js +10 -0
- package/lib/cjs/storage.d.ts +2 -0
- package/lib/cjs/storage.js +9 -3
- package/lib/cjs/types.d.ts +2 -0
- package/lib/esm/doc.d.ts +180 -10
- package/lib/esm/doc.js +479 -184
- package/lib/esm/live.d.ts +1 -0
- package/lib/esm/room.d.ts +2 -0
- package/lib/esm/room.js +10 -0
- package/lib/esm/storage.d.ts +2 -0
- package/lib/esm/storage.js +9 -3
- package/lib/esm/types.d.ts +2 -0
- package/package.json +1 -1
package/lib/cjs/live.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ export declare enum OpType {
|
|
|
114
114
|
}
|
|
115
115
|
export declare type Op = CreateObjectOp | UpdateObjectOp | DeleteCrdtOp | CreateListOp | SetParentKeyOp | DeleteObjectKeyOp | CreateMapOp | CreateRegisterOp;
|
|
116
116
|
export declare type UpdateObjectOp = {
|
|
117
|
+
opId?: string;
|
|
117
118
|
id: string;
|
|
118
119
|
type: OpType.UpdateObject;
|
|
119
120
|
data: {
|
package/lib/cjs/room.d.ts
CHANGED
|
@@ -81,6 +81,8 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
|
|
|
81
81
|
};
|
|
82
82
|
updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>) => void;
|
|
83
83
|
broadcastEvent: (event: any) => void;
|
|
84
|
+
undo: () => void;
|
|
85
|
+
redo: () => void;
|
|
84
86
|
getStorage: <TRoot>() => Promise<{
|
|
85
87
|
root: import("./doc").LiveObject<TRoot>;
|
|
86
88
|
}>;
|
package/lib/cjs/room.js
CHANGED
|
@@ -500,6 +500,12 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
500
500
|
};
|
|
501
501
|
});
|
|
502
502
|
}
|
|
503
|
+
function undo() {
|
|
504
|
+
storage.undo();
|
|
505
|
+
}
|
|
506
|
+
function redo() {
|
|
507
|
+
storage.redo();
|
|
508
|
+
}
|
|
503
509
|
return {
|
|
504
510
|
// Internal
|
|
505
511
|
onOpen,
|
|
@@ -518,6 +524,8 @@ function makeStateMachine(state, context, mockedEffects) {
|
|
|
518
524
|
// Presence
|
|
519
525
|
updatePresence,
|
|
520
526
|
broadcastEvent,
|
|
527
|
+
undo,
|
|
528
|
+
redo,
|
|
521
529
|
getStorage,
|
|
522
530
|
selectors: {
|
|
523
531
|
// Core
|
|
@@ -600,6 +608,8 @@ function createRoom(name, options) {
|
|
|
600
608
|
getOthers: machine.selectors.getOthers,
|
|
601
609
|
broadcastEvent: machine.broadcastEvent,
|
|
602
610
|
getStorage: machine.getStorage,
|
|
611
|
+
undo: machine.undo,
|
|
612
|
+
redo: machine.redo,
|
|
603
613
|
};
|
|
604
614
|
return {
|
|
605
615
|
connect: machine.connect,
|
package/lib/cjs/storage.d.ts
CHANGED
package/lib/cjs/storage.js
CHANGED
|
@@ -50,13 +50,19 @@ class Storage {
|
|
|
50
50
|
break;
|
|
51
51
|
}
|
|
52
52
|
case live_1.ServerMessageType.UpdateStorage: {
|
|
53
|
-
|
|
54
|
-
(_b = this._doc) === null || _b === void 0 ? void 0 : _b.apply(op);
|
|
55
|
-
}
|
|
53
|
+
(_b = this._doc) === null || _b === void 0 ? void 0 : _b.apply(message.ops);
|
|
56
54
|
break;
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
});
|
|
60
58
|
}
|
|
59
|
+
undo() {
|
|
60
|
+
var _a;
|
|
61
|
+
(_a = this._doc) === null || _a === void 0 ? void 0 : _a.undo();
|
|
62
|
+
}
|
|
63
|
+
redo() {
|
|
64
|
+
var _a;
|
|
65
|
+
(_a = this._doc) === null || _a === void 0 ? void 0 : _a.redo();
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
68
|
exports.default = Storage;
|
package/lib/cjs/types.d.ts
CHANGED
package/lib/esm/doc.d.ts
CHANGED
|
@@ -9,10 +9,14 @@ export declare class Doc<T extends Record<string, any> = Record<string, any>> {
|
|
|
9
9
|
addItem(id: string, item: AbstractCrdt): void;
|
|
10
10
|
deleteItem(id: string): void;
|
|
11
11
|
getItem(id: string): AbstractCrdt | undefined;
|
|
12
|
-
apply(
|
|
12
|
+
apply(ops: Op[]): Op[];
|
|
13
13
|
get root(): LiveObject<T>;
|
|
14
|
+
addToUndoStack(ops: Op[]): void;
|
|
15
|
+
undo(): void;
|
|
16
|
+
redo(): void;
|
|
14
17
|
count(): number;
|
|
15
18
|
generateId(): string;
|
|
19
|
+
generateOpId(): string;
|
|
16
20
|
}
|
|
17
21
|
declare abstract class AbstractCrdt {
|
|
18
22
|
#private;
|
|
@@ -31,24 +35,49 @@ declare abstract class AbstractCrdt {
|
|
|
31
35
|
/**
|
|
32
36
|
* INTERNAL
|
|
33
37
|
*/
|
|
34
|
-
|
|
38
|
+
get _parentKey(): string | undefined;
|
|
39
|
+
_apply(op: Op): Op[];
|
|
40
|
+
/**
|
|
41
|
+
* INTERNAL
|
|
42
|
+
*/
|
|
43
|
+
_setParentLink(parent: AbstractCrdt, key: string): void;
|
|
35
44
|
/**
|
|
36
45
|
* INTERNAL
|
|
37
46
|
*/
|
|
38
47
|
_attach(id: string, doc: Doc): void;
|
|
39
|
-
abstract _attachChild(id: string, key: string, crdt: AbstractCrdt):
|
|
48
|
+
abstract _attachChild(id: string, key: string, crdt: AbstractCrdt): Op[];
|
|
40
49
|
/**
|
|
41
50
|
* INTERNAL
|
|
42
51
|
*/
|
|
43
52
|
_detach(): void;
|
|
44
53
|
abstract _detachChild(crdt: AbstractCrdt): void;
|
|
54
|
+
/**
|
|
55
|
+
* Subscribes to updates.
|
|
56
|
+
*/
|
|
45
57
|
subscribe(listener: () => void): void;
|
|
58
|
+
/**
|
|
59
|
+
* Subscribes to updates and children updates.
|
|
60
|
+
*/
|
|
46
61
|
subscribeDeep(listener: () => void): void;
|
|
62
|
+
/**
|
|
63
|
+
* Unsubscribes to updates.
|
|
64
|
+
*/
|
|
47
65
|
unsubscribe(listener: () => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* Unsubscribes to updates and children updates.
|
|
68
|
+
*/
|
|
48
69
|
unsubscribeDeep(listener: () => void): void;
|
|
49
|
-
|
|
70
|
+
/**
|
|
71
|
+
* INTERNAL
|
|
72
|
+
*/
|
|
73
|
+
_notify(onlyDeep?: boolean): void;
|
|
50
74
|
abstract _serialize(parentId: string, parentKey: string): Op[];
|
|
51
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
|
+
*/
|
|
52
81
|
export declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
|
|
53
82
|
#private;
|
|
54
83
|
constructor(object?: T);
|
|
@@ -69,7 +98,7 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
69
98
|
/**
|
|
70
99
|
* INTERNAL
|
|
71
100
|
*/
|
|
72
|
-
_attachChild(id: string, key: keyof T, child: AbstractCrdt):
|
|
101
|
+
_attachChild(id: string, key: keyof T, child: AbstractCrdt): Op[];
|
|
73
102
|
/**
|
|
74
103
|
* INTERNAL
|
|
75
104
|
*/
|
|
@@ -81,12 +110,33 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
|
|
|
81
110
|
/**
|
|
82
111
|
* INTERNAL
|
|
83
112
|
*/
|
|
84
|
-
_apply(op: Op):
|
|
113
|
+
_apply(op: Op): Op[];
|
|
114
|
+
/**
|
|
115
|
+
* Transform the LiveObject into a javascript object
|
|
116
|
+
*/
|
|
85
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
|
+
*/
|
|
86
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
|
+
*/
|
|
87
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
|
+
*/
|
|
88
133
|
update(overrides: Partial<T>): void;
|
|
89
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
|
+
*/
|
|
90
140
|
export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
91
141
|
#private;
|
|
92
142
|
constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
|
|
@@ -105,7 +155,7 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
|
105
155
|
/**
|
|
106
156
|
* INTERNAL
|
|
107
157
|
*/
|
|
108
|
-
_attachChild(id: string, key: TKey, child: AbstractCrdt):
|
|
158
|
+
_attachChild(id: string, key: TKey, child: AbstractCrdt): Op[];
|
|
109
159
|
/**
|
|
110
160
|
* INTERNAL
|
|
111
161
|
*/
|
|
@@ -114,17 +164,58 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
|
|
|
114
164
|
* INTERNAL
|
|
115
165
|
*/
|
|
116
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
|
+
*/
|
|
117
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
|
+
*/
|
|
118
178
|
set(key: TKey, value: TValue): void;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the number of elements in the LiveMap.
|
|
181
|
+
*/
|
|
119
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
|
+
*/
|
|
120
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
|
+
*/
|
|
121
193
|
delete(key: TKey): boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Returns a new Iterator object that contains the [key, value] pairs for each element.
|
|
196
|
+
*/
|
|
122
197
|
entries(): IterableIterator<[string, TValue]>;
|
|
198
|
+
/**
|
|
199
|
+
* Same function object as the initial value of the entries method.
|
|
200
|
+
*/
|
|
123
201
|
[Symbol.iterator](): IterableIterator<[string, TValue]>;
|
|
202
|
+
/**
|
|
203
|
+
* Returns a new Iterator object that contains the keys for each element.
|
|
204
|
+
*/
|
|
124
205
|
keys(): IterableIterator<TKey>;
|
|
206
|
+
/**
|
|
207
|
+
* Returns a new Iterator object that contains the values for each element.
|
|
208
|
+
*/
|
|
125
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
|
+
*/
|
|
126
214
|
forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
|
|
127
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* The LiveList class represents an ordered collection of items that is synchorinized across clients.
|
|
218
|
+
*/
|
|
128
219
|
export declare class LiveList<T> extends AbstractCrdt {
|
|
129
220
|
#private;
|
|
130
221
|
constructor(items?: T[]);
|
|
@@ -147,7 +238,7 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
147
238
|
/**
|
|
148
239
|
* INTERNAL
|
|
149
240
|
*/
|
|
150
|
-
_attachChild(id: string, key: string, child: AbstractCrdt):
|
|
241
|
+
_attachChild(id: string, key: string, child: AbstractCrdt): Op[];
|
|
151
242
|
/**
|
|
152
243
|
* INTERNAL
|
|
153
244
|
*/
|
|
@@ -156,21 +247,100 @@ export declare class LiveList<T> extends AbstractCrdt {
|
|
|
156
247
|
* INTERNAL
|
|
157
248
|
*/
|
|
158
249
|
_setChildKey(key: string, child: AbstractCrdt): void;
|
|
250
|
+
/**
|
|
251
|
+
* INTERNAL
|
|
252
|
+
*/
|
|
253
|
+
_apply(op: Op): Op[];
|
|
254
|
+
/**
|
|
255
|
+
* Returns the number of elements.
|
|
256
|
+
*/
|
|
159
257
|
get length(): number;
|
|
160
|
-
|
|
161
|
-
|
|
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
|
+
*/
|
|
162
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
|
+
*/
|
|
163
279
|
delete(index: number): void;
|
|
280
|
+
/**
|
|
281
|
+
* Returns an Array of all the elements in the LiveList.
|
|
282
|
+
*/
|
|
164
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
|
+
*/
|
|
165
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
|
+
*/
|
|
166
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
|
+
*/
|
|
167
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
|
+
*/
|
|
168
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
|
+
*/
|
|
169
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
|
+
*/
|
|
170
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
|
+
*/
|
|
171
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
|
+
*/
|
|
172
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
|
+
*/
|
|
173
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
|
+
*/
|
|
174
344
|
some(predicate: (value: T, index: number) => unknown): boolean;
|
|
175
345
|
[Symbol.iterator](): IterableIterator<T>;
|
|
176
346
|
}
|