@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/README.md +2 -12
- package/lib/cjs/authentication.d.ts +1 -1
- package/lib/cjs/authentication.js +4 -3
- package/lib/cjs/doc.d.ts +182 -11
- package/lib/cjs/doc.js +513 -198
- package/lib/cjs/live.d.ts +1 -0
- package/lib/cjs/position.d.ts +1 -5
- package/lib/cjs/position.js +4 -4
- package/lib/cjs/room.d.ts +3 -0
- package/lib/cjs/room.js +22 -3
- package/lib/cjs/storage.d.ts +2 -0
- package/lib/cjs/storage.js +14 -8
- package/lib/cjs/types.d.ts +13 -6
- package/lib/esm/authentication.d.ts +1 -1
- package/lib/esm/authentication.js +4 -3
- package/lib/esm/doc.d.ts +182 -11
- package/lib/esm/doc.js +513 -198
- package/lib/esm/live.d.ts +1 -0
- package/lib/esm/position.d.ts +1 -5
- package/lib/esm/position.js +4 -4
- package/lib/esm/room.d.ts +3 -0
- package/lib/esm/room.js +22 -3
- package/lib/esm/storage.d.ts +2 -0
- package/lib/esm/storage.js +14 -8
- package/lib/esm/types.d.ts +13 -6
- package/package.json +1 -1
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: {
|
package/lib/esm/position.d.ts
CHANGED
|
@@ -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(
|
|
7
|
-
position: string;
|
|
8
|
-
}, itemB: {
|
|
9
|
-
position: string;
|
|
10
|
-
}): number;
|
|
6
|
+
export declare function compare(posA: string, posB: string): number;
|
package/lib/esm/position.js
CHANGED
|
@@ -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(
|
|
92
|
-
const aCodes = posCodes(
|
|
93
|
-
const bCodes = posCodes(
|
|
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 "${
|
|
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/
|
|
543
|
-
|
|
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,
|
package/lib/esm/storage.d.ts
CHANGED
package/lib/esm/storage.js
CHANGED
|
@@ -18,11 +18,11 @@ export default class Storage {
|
|
|
18
18
|
this._getInitialStateResolver = null;
|
|
19
19
|
}
|
|
20
20
|
createDocFromMessage(message) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -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 {};
|