@liveblocks/client 0.12.0-beta.13 → 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/lib/cjs/doc.d.ts CHANGED
@@ -9,8 +9,11 @@ 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(op: Op): void;
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;
16
19
  generateOpId(): string;
@@ -32,24 +35,49 @@ declare abstract class AbstractCrdt {
32
35
  /**
33
36
  * INTERNAL
34
37
  */
35
- _setParent(parent: AbstractCrdt): void;
38
+ get _parentKey(): string | undefined;
39
+ _apply(op: Op): Op[];
40
+ /**
41
+ * INTERNAL
42
+ */
43
+ _setParentLink(parent: AbstractCrdt, key: string): void;
36
44
  /**
37
45
  * INTERNAL
38
46
  */
39
47
  _attach(id: string, doc: Doc): void;
40
- abstract _attachChild(id: string, key: string, crdt: AbstractCrdt): void;
48
+ abstract _attachChild(id: string, key: string, crdt: AbstractCrdt): Op[];
41
49
  /**
42
50
  * INTERNAL
43
51
  */
44
52
  _detach(): void;
45
53
  abstract _detachChild(crdt: AbstractCrdt): void;
54
+ /**
55
+ * Subscribes to updates.
56
+ */
46
57
  subscribe(listener: () => void): void;
58
+ /**
59
+ * Subscribes to updates and children updates.
60
+ */
47
61
  subscribeDeep(listener: () => void): void;
62
+ /**
63
+ * Unsubscribes to updates.
64
+ */
48
65
  unsubscribe(listener: () => void): void;
66
+ /**
67
+ * Unsubscribes to updates and children updates.
68
+ */
49
69
  unsubscribeDeep(listener: () => void): void;
50
- notify(onlyDeep?: boolean): void;
70
+ /**
71
+ * INTERNAL
72
+ */
73
+ _notify(onlyDeep?: boolean): void;
51
74
  abstract _serialize(parentId: string, parentKey: string): Op[];
52
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
+ */
53
81
  export declare class LiveObject<T extends Record<string, any> = Record<string, any>> extends AbstractCrdt {
54
82
  #private;
55
83
  constructor(object?: T);
@@ -70,7 +98,7 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
70
98
  /**
71
99
  * INTERNAL
72
100
  */
73
- _attachChild(id: string, key: keyof T, child: AbstractCrdt): void;
101
+ _attachChild(id: string, key: keyof T, child: AbstractCrdt): Op[];
74
102
  /**
75
103
  * INTERNAL
76
104
  */
@@ -82,12 +110,33 @@ export declare class LiveObject<T extends Record<string, any> = Record<string, a
82
110
  /**
83
111
  * INTERNAL
84
112
  */
85
- _apply(op: Op): void;
113
+ _apply(op: Op): Op[];
114
+ /**
115
+ * Transform the LiveObject into a javascript object
116
+ */
86
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
+ */
87
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
+ */
88
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
+ */
89
133
  update(overrides: Partial<T>): void;
90
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
+ */
91
140
  export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
92
141
  #private;
93
142
  constructor(entries?: readonly (readonly [TKey, TValue])[] | null | undefined);
@@ -106,7 +155,7 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
106
155
  /**
107
156
  * INTERNAL
108
157
  */
109
- _attachChild(id: string, key: TKey, child: AbstractCrdt): void;
158
+ _attachChild(id: string, key: TKey, child: AbstractCrdt): Op[];
110
159
  /**
111
160
  * INTERNAL
112
161
  */
@@ -115,17 +164,58 @@ export declare class LiveMap<TKey extends string, TValue> extends AbstractCrdt {
115
164
  * INTERNAL
116
165
  */
117
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
+ */
118
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
+ */
119
178
  set(key: TKey, value: TValue): void;
179
+ /**
180
+ * Returns the number of elements in the LiveMap.
181
+ */
120
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
+ */
121
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
+ */
122
193
  delete(key: TKey): boolean;
194
+ /**
195
+ * Returns a new Iterator object that contains the [key, value] pairs for each element.
196
+ */
123
197
  entries(): IterableIterator<[string, TValue]>;
198
+ /**
199
+ * Same function object as the initial value of the entries method.
200
+ */
124
201
  [Symbol.iterator](): IterableIterator<[string, TValue]>;
202
+ /**
203
+ * Returns a new Iterator object that contains the keys for each element.
204
+ */
125
205
  keys(): IterableIterator<TKey>;
206
+ /**
207
+ * Returns a new Iterator object that contains the values for each element.
208
+ */
126
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
+ */
127
214
  forEach(callback: (value: TValue, key: TKey, map: LiveMap<TKey, TValue>) => void): void;
128
215
  }
216
+ /**
217
+ * The LiveList class represents an ordered collection of items that is synchorinized across clients.
218
+ */
129
219
  export declare class LiveList<T> extends AbstractCrdt {
130
220
  #private;
131
221
  constructor(items?: T[]);
@@ -148,7 +238,7 @@ export declare class LiveList<T> extends AbstractCrdt {
148
238
  /**
149
239
  * INTERNAL
150
240
  */
151
- _attachChild(id: string, key: string, child: AbstractCrdt): void;
241
+ _attachChild(id: string, key: string, child: AbstractCrdt): Op[];
152
242
  /**
153
243
  * INTERNAL
154
244
  */
@@ -157,21 +247,100 @@ export declare class LiveList<T> extends AbstractCrdt {
157
247
  * INTERNAL
158
248
  */
159
249
  _setChildKey(key: string, child: AbstractCrdt): void;
250
+ /**
251
+ * INTERNAL
252
+ */
253
+ _apply(op: Op): Op[];
254
+ /**
255
+ * Returns the number of elements.
256
+ */
160
257
  get length(): number;
161
- push(item: T): void;
162
- insert(item: T, index: number): void;
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
+ */
163
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
+ */
164
279
  delete(index: number): void;
280
+ /**
281
+ * Returns an Array of all the elements in the LiveList.
282
+ */
165
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
+ */
166
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
+ */
167
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
+ */
168
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
+ */
169
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
+ */
170
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
+ */
171
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
+ */
172
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
+ */
173
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
+ */
174
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
+ */
175
344
  some(predicate: (value: T, index: number) => unknown): boolean;
176
345
  [Symbol.iterator](): IterableIterator<T>;
177
346
  }