@liveblocks/client 0.12.0-beta.8 → 0.12.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.
package/lib/esm/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: {
@@ -3,8 +3,4 @@ export declare const max = 126;
3
3
  export declare function makePosition(before?: string, after?: string): string;
4
4
  export declare function posCodes(str: string): number[];
5
5
  export declare function pos(codes: number[]): string;
6
- export declare function compare(itemA: {
7
- position: string;
8
- }, itemB: {
9
- position: string;
10
- }): number;
6
+ export declare function compare(posA: string, posB: string): number;
@@ -88,9 +88,9 @@ export function posCodes(str) {
88
88
  export function pos(codes) {
89
89
  return String.fromCharCode(...codes);
90
90
  }
91
- export function compare(itemA, itemB) {
92
- const aCodes = posCodes(itemA.position);
93
- const bCodes = posCodes(itemB.position);
91
+ export function compare(posA, posB) {
92
+ const aCodes = posCodes(posA);
93
+ const bCodes = posCodes(posB);
94
94
  const maxLength = Math.max(aCodes.length, bCodes.length);
95
95
  for (let i = 0; i < maxLength; i++) {
96
96
  const a = aCodes[i] == null ? min : aCodes[i];
@@ -102,5 +102,5 @@ export function compare(itemA, itemB) {
102
102
  return a - b;
103
103
  }
104
104
  }
105
- throw new Error(`Impossible to compare similar position "${itemA.position}" and "${itemB.position}"`);
105
+ throw new Error(`Impossible to compare similar position "${posA}" and "${posB}"`);
106
106
  }
package/lib/esm/room.d.ts CHANGED
@@ -49,6 +49,7 @@ declare type Context = {
49
49
  authEndpoint: AuthEndpoint;
50
50
  liveblocksServer: string;
51
51
  throttleDelay: number;
52
+ publicApiKey?: string;
52
53
  };
53
54
  export declare function makeStateMachine(state: State, context: Context, mockedEffects?: Effects): {
54
55
  onOpen: () => void;
@@ -80,6 +81,8 @@ export declare function makeStateMachine(state: State, context: Context, mockedE
80
81
  };
81
82
  updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>) => void;
82
83
  broadcastEvent: (event: any) => void;
84
+ undo: () => void;
85
+ redo: () => void;
83
86
  getStorage: <TRoot>() => Promise<{
84
87
  root: import("./doc").LiveObject<TRoot>;
85
88
  }>;
package/lib/esm/room.js CHANGED
@@ -49,7 +49,7 @@ export function makeStateMachine(state, context, mockedEffects) {
49
49
  authenticate() {
50
50
  return __awaiter(this, void 0, void 0, function* () {
51
51
  try {
52
- const token = yield auth(context.authEndpoint, context.room);
52
+ const token = yield auth(context.authEndpoint, context.room, context.publicApiKey);
53
53
  const parsedToken = parseToken(token);
54
54
  const socket = new WebSocket(`${context.liveblocksServer}/?token=${token}`);
55
55
  socket.addEventListener("message", onMessage);
@@ -475,6 +475,12 @@ export function makeStateMachine(state, context, mockedEffects) {
475
475
  };
476
476
  });
477
477
  }
478
+ function undo() {
479
+ storage.undo();
480
+ }
481
+ function redo() {
482
+ storage.redo();
483
+ }
478
484
  return {
479
485
  // Internal
480
486
  onOpen,
@@ -493,6 +499,8 @@ export function makeStateMachine(state, context, mockedEffects) {
493
499
  // Presence
494
500
  updatePresence,
495
501
  broadcastEvent,
502
+ undo,
503
+ redo,
496
504
  getStorage,
497
505
  selectors: {
498
506
  // Core
@@ -539,14 +547,23 @@ export function defaultState(me, defaultStorageRoot) {
539
547
  }
540
548
  export function createRoom(name, options) {
541
549
  const throttleDelay = options.throttle || 100;
542
- const liveblocksServer = options.liveblocksServer || "wss://liveblocks.net/v2";
543
- const authEndpoint = options.authEndpoint;
550
+ const liveblocksServer = options.liveblocksServer || "wss://liveblocks.net/v4";
551
+ let authEndpoint;
552
+ if (options.authEndpoint) {
553
+ authEndpoint = options.authEndpoint;
554
+ }
555
+ else {
556
+ const publicAuthorizeEndpoint = options.publicAuthorizeEndpoint ||
557
+ "https://liveblocks.io/api/public/authorize";
558
+ authEndpoint = publicAuthorizeEndpoint;
559
+ }
544
560
  const state = defaultState(options.defaultPresence, options.defaultStorageRoot);
545
561
  const machine = makeStateMachine(state, {
546
562
  throttleDelay,
547
563
  liveblocksServer,
548
564
  authEndpoint,
549
565
  room: name,
566
+ publicApiKey: options.publicApiKey,
550
567
  });
551
568
  const room = {
552
569
  /////////////
@@ -564,6 +581,8 @@ export function createRoom(name, options) {
564
581
  getOthers: machine.selectors.getOthers,
565
582
  broadcastEvent: machine.broadcastEvent,
566
583
  getStorage: machine.getStorage,
584
+ undo: machine.undo,
585
+ redo: machine.redo,
567
586
  };
568
587
  return {
569
588
  connect: machine.connect,
@@ -16,4 +16,6 @@ export default class Storage {
16
16
  private createDocFromMessage;
17
17
  getDocument<TRoot>(): Promise<Doc<TRoot>>;
18
18
  onMessage(message: ServerMessage): Promise<void>;
19
+ undo(): void;
20
+ redo(): void;
19
21
  }
@@ -18,11 +18,11 @@ export default class Storage {
18
18
  this._getInitialStateResolver = null;
19
19
  }
20
20
  createDocFromMessage(message) {
21
- if (message.items.length === 0) {
22
- this._doc = Doc.from(this.options.defaultRoot, this.options.getConnectionId(), this.options.dispatch);
23
- }
24
- else {
25
- this._doc = Doc.load(message.items, this.options.getConnectionId(), this.options.dispatch);
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
26
  }
27
27
  }
28
28
  getDocument() {
@@ -48,12 +48,18 @@ export default class Storage {
48
48
  break;
49
49
  }
50
50
  case ServerMessageType.UpdateStorage: {
51
- for (const op of message.ops) {
52
- (_b = this._doc) === null || _b === void 0 ? void 0 : _b.apply(op);
53
- }
51
+ (_b = this._doc) === null || _b === void 0 ? void 0 : _b.apply(message.ops);
54
52
  break;
55
53
  }
56
54
  }
57
55
  });
58
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
+ }
59
65
  }
@@ -87,14 +87,19 @@ declare type AuthEndpointCallback = (room: string) => Promise<{
87
87
  token: string;
88
88
  }>;
89
89
  export declare type AuthEndpoint = string | AuthEndpointCallback;
90
+ /**
91
+ * The authentication endpoint that is called to ensure that the current user has access to a room.
92
+ * Can be an url or a callback if you need to add additional headers.
93
+ */
90
94
  export declare type ClientOptions = {
91
- /**
92
- * The authentication endpoint that is called to ensure that the current user has access to a room.
93
- * Can be an url or a callback if you need to add additional headers.
94
- */
95
- authEndpoint: AuthEndpoint;
96
95
  throttle?: number;
97
- };
96
+ } & ({
97
+ publicApiKey: string;
98
+ authEndpoint?: never;
99
+ } | {
100
+ publicApiKey?: never;
101
+ authEndpoint: AuthEndpoint;
102
+ });
98
103
  export declare type AuthorizeResponse = {
99
104
  token: string;
100
105
  };
@@ -261,5 +266,7 @@ export declare type Room = {
261
266
  getStorage: <TRoot>() => Promise<{
262
267
  root: LiveObject<TRoot>;
263
268
  }>;
269
+ undo: () => void;
270
+ redo: () => void;
264
271
  };
265
272
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/client",
3
- "version": "0.12.0-beta.8",
3
+ "version": "0.12.2",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",