@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
@@ -1,21 +0,0 @@
1
- import { Doc as Doc } from "./doc";
2
- import { Op, ServerMessage } from "./live";
3
- export default class Storage {
4
- private options;
5
- private _doc;
6
- private _getInitialStatePromise;
7
- private _getInitialStateResolver;
8
- constructor(options: {
9
- fetchStorage: () => void;
10
- getConnectionId: () => number;
11
- defaultRoot: {
12
- [key: string]: any;
13
- };
14
- dispatch: (ops: Op[]) => void;
15
- });
16
- private createDocFromMessage;
17
- getDocument<TRoot>(): Promise<Doc<TRoot>>;
18
- onMessage(message: ServerMessage): Promise<void>;
19
- undo(): void;
20
- redo(): void;
21
- }
@@ -1,65 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Doc as Doc } from "./doc";
11
- import { ServerMessageType, } from "./live";
12
- // Internal dependency mess between room and storage. Still need to figure out if room has a storage or if the Storage is going to use a room
13
- export default class Storage {
14
- constructor(options) {
15
- this.options = options;
16
- this._doc = null;
17
- this._getInitialStatePromise = null;
18
- this._getInitialStateResolver = null;
19
- }
20
- createDocFromMessage(message) {
21
- this._doc = Doc.load(message.items, this.options.getConnectionId(), this.options.dispatch);
22
- for (const key in this.options.defaultRoot) {
23
- if (this._doc.root.get(key) == null) {
24
- this._doc.root.set(key, this.options.defaultRoot[key]);
25
- }
26
- }
27
- }
28
- getDocument() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- if (this._doc) {
31
- return this._doc;
32
- }
33
- if (this._getInitialStatePromise == null) {
34
- this.options.fetchStorage();
35
- this._getInitialStatePromise = new Promise((resolve) => (this._getInitialStateResolver = resolve));
36
- }
37
- yield this._getInitialStatePromise;
38
- return this._doc;
39
- });
40
- }
41
- onMessage(message) {
42
- var _a, _b;
43
- return __awaiter(this, void 0, void 0, function* () {
44
- switch (message.type) {
45
- case ServerMessageType.InitialStorageState: {
46
- this.createDocFromMessage(message);
47
- (_a = this._getInitialStateResolver) === null || _a === void 0 ? void 0 : _a.call(this);
48
- break;
49
- }
50
- case ServerMessageType.UpdateStorage: {
51
- (_b = this._doc) === null || _b === void 0 ? void 0 : _b.apply(message.ops);
52
- break;
53
- }
54
- }
55
- });
56
- }
57
- undo() {
58
- var _a;
59
- (_a = this._doc) === null || _a === void 0 ? void 0 : _a.undo();
60
- }
61
- redo() {
62
- var _a;
63
- (_a = this._doc) === null || _a === void 0 ? void 0 : _a.redo();
64
- }
65
- }