@liveblocks/client 0.12.3 → 0.13.2

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 (48) 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/immutable/index.d.ts +7 -0
  13. package/lib/cjs/immutable/index.js +214 -0
  14. package/lib/cjs/index.d.ts +3 -1
  15. package/lib/cjs/index.js +7 -5
  16. package/lib/cjs/room.d.ts +50 -9
  17. package/lib/cjs/room.js +477 -85
  18. package/lib/cjs/types.d.ts +220 -40
  19. package/lib/cjs/utils.d.ts +7 -0
  20. package/lib/cjs/utils.js +64 -1
  21. package/lib/esm/AbstractCrdt.d.ts +61 -0
  22. package/lib/esm/AbstractCrdt.js +94 -0
  23. package/lib/esm/LiveList.d.ts +133 -0
  24. package/lib/esm/LiveList.js +370 -0
  25. package/lib/esm/LiveMap.d.ts +83 -0
  26. package/lib/esm/LiveMap.js +268 -0
  27. package/lib/esm/LiveObject.d.ts +66 -0
  28. package/lib/esm/LiveObject.js +364 -0
  29. package/lib/esm/LiveRegister.d.ts +21 -0
  30. package/lib/esm/LiveRegister.js +65 -0
  31. package/lib/esm/immutable/index.d.ts +7 -0
  32. package/lib/esm/immutable/index.js +207 -0
  33. package/lib/esm/index.d.ts +3 -1
  34. package/lib/esm/index.js +3 -1
  35. package/lib/esm/room.d.ts +50 -9
  36. package/lib/esm/room.js +479 -84
  37. package/lib/esm/types.d.ts +220 -40
  38. package/lib/esm/utils.d.ts +7 -0
  39. package/lib/esm/utils.js +58 -0
  40. package/package.json +3 -3
  41. package/lib/cjs/doc.d.ts +0 -347
  42. package/lib/cjs/doc.js +0 -1349
  43. package/lib/cjs/storage.d.ts +0 -21
  44. package/lib/cjs/storage.js +0 -68
  45. package/lib/esm/doc.d.ts +0 -347
  46. package/lib/esm/doc.js +0 -1342
  47. package/lib/esm/storage.d.ts +0 -21
  48. package/lib/esm/storage.js +0 -65
package/lib/cjs/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createClient = exports.LiveMap = exports.LiveList = exports.LiveObject = void 0;
4
- var doc_1 = require("./doc");
5
- Object.defineProperty(exports, "LiveObject", { enumerable: true, get: function () { return doc_1.LiveObject; } });
6
- Object.defineProperty(exports, "LiveList", { enumerable: true, get: function () { return doc_1.LiveList; } });
7
- Object.defineProperty(exports, "LiveMap", { enumerable: true, get: function () { return doc_1.LiveMap; } });
3
+ exports.createClient = exports.LiveList = exports.LiveMap = exports.LiveObject = void 0;
4
+ var LiveObject_1 = require("./LiveObject");
5
+ Object.defineProperty(exports, "LiveObject", { enumerable: true, get: function () { return LiveObject_1.LiveObject; } });
6
+ var LiveMap_1 = require("./LiveMap");
7
+ Object.defineProperty(exports, "LiveMap", { enumerable: true, get: function () { return LiveMap_1.LiveMap; } });
8
+ var LiveList_1 = require("./LiveList");
9
+ Object.defineProperty(exports, "LiveList", { enumerable: true, get: function () { return LiveList_1.LiveList; } });
8
10
  var client_1 = require("./client");
9
11
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } });
package/lib/cjs/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";