@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,21 @@
1
+ import { AbstractCrdt, Doc, ApplyResult } from "./AbstractCrdt";
2
+ import { SerializedCrdtWithId, Op } from "./live";
3
+ /**
4
+ * INTERNAL
5
+ */
6
+ export declare class LiveRegister<TValue = any> extends AbstractCrdt {
7
+ #private;
8
+ constructor(data: TValue);
9
+ get data(): TValue;
10
+ /**
11
+ * INTERNAL
12
+ */
13
+ static _deserialize([id, item]: SerializedCrdtWithId, parentToChildren: Map<string, SerializedCrdtWithId[]>, doc: Doc): LiveRegister<any>;
14
+ /**
15
+ * INTERNAL
16
+ */
17
+ _serialize(parentId: string, parentKey: string): Op[];
18
+ _attachChild(id: string, key: string, crdt: AbstractCrdt): ApplyResult;
19
+ _detachChild(crdt: AbstractCrdt): void;
20
+ _apply(op: Op): ApplyResult;
21
+ }
@@ -0,0 +1,65 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ 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");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ 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");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _LiveRegister_data;
13
+ import { AbstractCrdt } from "./AbstractCrdt";
14
+ import { CrdtType, OpType } from "./live";
15
+ /**
16
+ * INTERNAL
17
+ */
18
+ export class LiveRegister extends AbstractCrdt {
19
+ constructor(data) {
20
+ super();
21
+ _LiveRegister_data.set(this, void 0);
22
+ __classPrivateFieldSet(this, _LiveRegister_data, data, "f");
23
+ }
24
+ get data() {
25
+ return __classPrivateFieldGet(this, _LiveRegister_data, "f");
26
+ }
27
+ /**
28
+ * INTERNAL
29
+ */
30
+ static _deserialize([id, item], parentToChildren, doc) {
31
+ if (item.type !== CrdtType.Register) {
32
+ throw new Error(`Tried to deserialize a map but item type is "${item.type}"`);
33
+ }
34
+ const register = new LiveRegister(item.data);
35
+ register._attach(id, doc);
36
+ return register;
37
+ }
38
+ /**
39
+ * INTERNAL
40
+ */
41
+ _serialize(parentId, parentKey) {
42
+ if (this._id == null || parentId == null || parentKey == null) {
43
+ throw new Error("Cannot serialize register if parentId or parentKey is undefined");
44
+ }
45
+ return [
46
+ {
47
+ type: OpType.CreateRegister,
48
+ id: this._id,
49
+ parentId,
50
+ parentKey,
51
+ data: this.data,
52
+ },
53
+ ];
54
+ }
55
+ _attachChild(id, key, crdt) {
56
+ throw new Error("Method not implemented.");
57
+ }
58
+ _detachChild(crdt) {
59
+ throw new Error("Method not implemented.");
60
+ }
61
+ _apply(op) {
62
+ return super._apply(op);
63
+ }
64
+ }
65
+ _LiveRegister_data = new WeakMap();
@@ -1,3 +1,5 @@
1
- export { LiveObject, LiveList, LiveMap } from "./doc";
1
+ export { LiveObject } from "./LiveObject";
2
+ export { LiveMap } from "./LiveMap";
3
+ export { LiveList } from "./LiveList";
2
4
  export type { Others, Presence, Room, Client, User } from "./types";
3
5
  export { createClient } from "./client";
package/lib/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
- export { LiveObject, LiveList, LiveMap } from "./doc";
1
+ export { LiveObject } from "./LiveObject";
2
+ export { LiveMap } from "./LiveMap";
3
+ export { LiveList } from "./LiveList";
2
4
  export { createClient } from "./client";
package/lib/esm/room.d.ts CHANGED
@@ -1,11 +1,19 @@
1
- import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback } from "./types";
1
+ import { Others, Presence, ClientOptions, Room, MyPresenceCallback, OthersEventCallback, AuthEndpoint, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback, StorageCallback, StorageUpdate } from "./types";
2
2
  import { ClientMessage, Op } from "./live";
3
+ import { LiveMap } from "./LiveMap";
4
+ import { LiveObject } from "./LiveObject";
5
+ import { LiveList } from "./LiveList";
6
+ import { AbstractCrdt } from "./AbstractCrdt";
7
+ declare type HistoryItem = Array<Op | {
8
+ type: "presence";
9
+ data: Presence;
10
+ }>;
3
11
  declare type IdFactory = () => string;
4
12
  export declare type State = {
5
13
  connection: Connection;
6
14
  socket: WebSocket | null;
7
15
  lastFlushTime: number;
8
- flushData: {
16
+ buffer: {
9
17
  presence: Presence | null;
10
18
  messages: ClientMessage[];
11
19
  storageOperations: Op[];
@@ -24,6 +32,7 @@ export declare type State = {
24
32
  "my-presence": MyPresenceCallback[];
25
33
  error: ErrorCallback[];
26
34
  connection: ConnectionCallback[];
35
+ storage: StorageCallback[];
27
36
  };
28
37
  me: Presence;
29
38
  others: Others;
@@ -35,6 +44,24 @@ export declare type State = {
35
44
  defaultStorageRoot?: {
36
45
  [key: string]: any;
37
46
  };
47
+ clock: number;
48
+ opClock: number;
49
+ items: Map<string, AbstractCrdt>;
50
+ root: LiveObject | undefined;
51
+ undoStack: HistoryItem[];
52
+ redoStack: HistoryItem[];
53
+ isHistoryPaused: boolean;
54
+ pausedHistory: HistoryItem;
55
+ isBatching: boolean;
56
+ batch: {
57
+ ops: Op[];
58
+ reverseOps: HistoryItem;
59
+ updates: {
60
+ others: [];
61
+ presence: boolean;
62
+ nodes: Set<AbstractCrdt>;
63
+ };
64
+ };
38
65
  };
39
66
  export declare type Effects = {
40
67
  authenticate(): void;
@@ -63,14 +90,23 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
63
90
  heartbeat: () => void;
64
91
  onNavigatorOnline: () => void;
65
92
  onVisibilityChange: (visibilityState: VisibilityState) => void;
93
+ getUndoStack: () => HistoryItem[];
94
+ getItemsCount: () => number;
66
95
  connect: () => null | undefined;
67
96
  disconnect: () => void;
68
97
  subscribe: {
69
- <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): void;
70
- <T_1 extends Presence>(type: "others", listener: OthersEventCallback<T_1>): void;
71
- (type: "event", listener: EventCallback): void;
72
- (type: "error", listener: ErrorCallback): void;
73
- (type: "connection", listener: ConnectionCallback): void;
98
+ (callback: (updates: StorageUpdate) => void): () => void;
99
+ <TKey extends string, TValue>(liveMap: LiveMap<TKey, TValue>, callback: (liveMap: LiveMap<TKey, TValue>) => void): () => void;
100
+ <TData>(liveObject: LiveObject<TData>, callback: (liveObject: LiveObject<TData>) => void): () => void;
101
+ <TItem>(liveList: LiveList<TItem>, callback: (liveList: LiveList<TItem>) => void): () => void;
102
+ <TItem_1 extends AbstractCrdt>(node: TItem_1, callback: (updates: StorageUpdate[]) => void, options: {
103
+ isDeep: true;
104
+ }): () => void;
105
+ <T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): () => void;
106
+ <T_1 extends Presence>(type: "others", listener: OthersEventCallback<T_1>): () => void;
107
+ (type: "event", listener: EventCallback): () => void;
108
+ (type: "error", listener: ErrorCallback): () => void;
109
+ (type: "connection", listener: ConnectionCallback): () => void;
74
110
  };
75
111
  unsubscribe: {
76
112
  <T_2 extends Presence>(type: "my-presence", listener: MyPresenceCallback<T_2>): void;
@@ -79,12 +115,17 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
79
115
  (type: "error", listener: ErrorCallback): void;
80
116
  (type: "connection", listener: ConnectionCallback): void;
81
117
  };
82
- updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>) => void;
118
+ updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>, options?: {
119
+ addToHistory: boolean;
120
+ } | undefined) => void;
83
121
  broadcastEvent: (event: any) => void;
122
+ batch: (callback: () => void) => void;
84
123
  undo: () => void;
85
124
  redo: () => void;
125
+ pauseHistory: () => void;
126
+ resumeHistory: () => void;
86
127
  getStorage: <TRoot>() => Promise<{
87
- root: import("./doc").LiveObject<TRoot>;
128
+ root: LiveObject<TRoot>;
88
129
  }>;
89
130
  selectors: {
90
131
  getConnectionState: () => "failed" | "closed" | "connecting" | "open" | "authenticating" | "unavailable";