@liveblocks/client 0.15.0-alpha.3 → 0.15.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.
- package/README.md +5 -10
- package/lib/esm/index.js +2991 -5
- package/lib/esm/index.mjs +2991 -0
- package/lib/esm/internal.js +149 -0
- package/lib/esm/internal.mjs +149 -0
- package/lib/{esm/types.d.ts → index.d.ts} +253 -61
- package/lib/index.js +4237 -0
- package/lib/{esm/live.d.ts → internal.d.ts} +46 -34
- package/lib/internal.js +193 -0
- package/package.json +32 -10
- package/lib/cjs/AbstractCrdt.d.ts +0 -68
- package/lib/cjs/AbstractCrdt.js +0 -95
- package/lib/cjs/LiveList.d.ts +0 -144
- package/lib/cjs/LiveList.js +0 -530
- package/lib/cjs/LiveMap.d.ts +0 -91
- package/lib/cjs/LiveMap.js +0 -325
- package/lib/cjs/LiveObject.d.ts +0 -80
- package/lib/cjs/LiveObject.js +0 -485
- package/lib/cjs/LiveRegister.d.ts +0 -29
- package/lib/cjs/LiveRegister.js +0 -88
- package/lib/cjs/client.d.ts +0 -27
- package/lib/cjs/client.js +0 -123
- package/lib/cjs/immutable.d.ts +0 -9
- package/lib/cjs/immutable.js +0 -299
- package/lib/cjs/index.d.ts +0 -6
- package/lib/cjs/index.js +0 -18
- package/lib/cjs/live.d.ts +0 -181
- package/lib/cjs/live.js +0 -49
- package/lib/cjs/position.d.ts +0 -6
- package/lib/cjs/position.js +0 -113
- package/lib/cjs/room.d.ts +0 -159
- package/lib/cjs/room.js +0 -1129
- package/lib/cjs/types.d.ts +0 -502
- package/lib/cjs/types.js +0 -2
- package/lib/cjs/utils.d.ts +0 -15
- package/lib/cjs/utils.js +0 -225
- package/lib/esm/AbstractCrdt.d.ts +0 -68
- package/lib/esm/AbstractCrdt.js +0 -91
- package/lib/esm/LiveList.d.ts +0 -144
- package/lib/esm/LiveList.js +0 -526
- package/lib/esm/LiveMap.d.ts +0 -91
- package/lib/esm/LiveMap.js +0 -321
- package/lib/esm/LiveObject.d.ts +0 -80
- package/lib/esm/LiveObject.js +0 -481
- package/lib/esm/LiveRegister.d.ts +0 -29
- package/lib/esm/LiveRegister.js +0 -84
- package/lib/esm/client.d.ts +0 -27
- package/lib/esm/client.js +0 -119
- package/lib/esm/immutable.d.ts +0 -9
- package/lib/esm/immutable.js +0 -290
- package/lib/esm/index.d.ts +0 -6
- package/lib/esm/live.js +0 -46
- package/lib/esm/position.d.ts +0 -6
- package/lib/esm/position.js +0 -106
- package/lib/esm/room.d.ts +0 -159
- package/lib/esm/room.js +0 -1123
- package/lib/esm/types.js +0 -1
- package/lib/esm/utils.d.ts +0 -15
- package/lib/esm/utils.js +0 -213
package/lib/cjs/position.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const min = 32;
|
|
2
|
-
export declare const max = 126;
|
|
3
|
-
export declare function makePosition(before?: string, after?: string): string;
|
|
4
|
-
export declare function posCodes(str: string): number[];
|
|
5
|
-
export declare function pos(codes: number[]): string;
|
|
6
|
-
export declare function compare(posA: string, posB: string): number;
|
package/lib/cjs/position.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compare = exports.pos = exports.posCodes = exports.makePosition = exports.max = exports.min = void 0;
|
|
4
|
-
exports.min = 32;
|
|
5
|
-
exports.max = 126;
|
|
6
|
-
function makePosition(before, after) {
|
|
7
|
-
// No children
|
|
8
|
-
if (before == null && after == null) {
|
|
9
|
-
return pos([exports.min + 1]);
|
|
10
|
-
}
|
|
11
|
-
// Insert at the end
|
|
12
|
-
if (before != null && after == null) {
|
|
13
|
-
return getNextPosition(before);
|
|
14
|
-
}
|
|
15
|
-
// Insert at the start
|
|
16
|
-
if (before == null && after != null) {
|
|
17
|
-
return getPreviousPosition(after);
|
|
18
|
-
}
|
|
19
|
-
return pos(makePositionFromCodes(posCodes(before), posCodes(after)));
|
|
20
|
-
}
|
|
21
|
-
exports.makePosition = makePosition;
|
|
22
|
-
function getPreviousPosition(after) {
|
|
23
|
-
const result = [];
|
|
24
|
-
const afterCodes = posCodes(after);
|
|
25
|
-
for (let i = 0; i < afterCodes.length; i++) {
|
|
26
|
-
const code = afterCodes[i];
|
|
27
|
-
if (code <= exports.min + 1) {
|
|
28
|
-
result.push(exports.min);
|
|
29
|
-
if (afterCodes.length - 1 === i) {
|
|
30
|
-
result.push(exports.max);
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
result.push(code - 1);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return pos(result);
|
|
40
|
-
}
|
|
41
|
-
function getNextPosition(before) {
|
|
42
|
-
const result = [];
|
|
43
|
-
const beforeCodes = posCodes(before);
|
|
44
|
-
for (let i = 0; i < beforeCodes.length; i++) {
|
|
45
|
-
const code = beforeCodes[i];
|
|
46
|
-
if (code === exports.max) {
|
|
47
|
-
result.push(code);
|
|
48
|
-
if (beforeCodes.length - 1 === i) {
|
|
49
|
-
result.push(exports.min + 1);
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
result.push(code + 1);
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return pos(result);
|
|
59
|
-
}
|
|
60
|
-
function makePositionFromCodes(before, after) {
|
|
61
|
-
let index = 0;
|
|
62
|
-
const result = [];
|
|
63
|
-
while (true) {
|
|
64
|
-
const beforeDigit = before[index] || exports.min;
|
|
65
|
-
const afterDigit = after[index] || exports.max;
|
|
66
|
-
if (beforeDigit > afterDigit) {
|
|
67
|
-
throw new Error(`Impossible to generate position between ${before} and ${after}`);
|
|
68
|
-
}
|
|
69
|
-
if (beforeDigit === afterDigit) {
|
|
70
|
-
result.push(beforeDigit);
|
|
71
|
-
index++;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (afterDigit - beforeDigit === 1) {
|
|
75
|
-
result.push(beforeDigit);
|
|
76
|
-
result.push(...makePositionFromCodes(before.slice(index + 1), []));
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
const mid = (afterDigit + beforeDigit) >> 1;
|
|
80
|
-
result.push(mid);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
return result;
|
|
84
|
-
}
|
|
85
|
-
function posCodes(str) {
|
|
86
|
-
const codes = [];
|
|
87
|
-
for (let i = 0; i < str.length; i++) {
|
|
88
|
-
codes.push(str.charCodeAt(i));
|
|
89
|
-
}
|
|
90
|
-
return codes;
|
|
91
|
-
}
|
|
92
|
-
exports.posCodes = posCodes;
|
|
93
|
-
function pos(codes) {
|
|
94
|
-
return String.fromCharCode(...codes);
|
|
95
|
-
}
|
|
96
|
-
exports.pos = pos;
|
|
97
|
-
function compare(posA, posB) {
|
|
98
|
-
const aCodes = posCodes(posA);
|
|
99
|
-
const bCodes = posCodes(posB);
|
|
100
|
-
const maxLength = Math.max(aCodes.length, bCodes.length);
|
|
101
|
-
for (let i = 0; i < maxLength; i++) {
|
|
102
|
-
const a = aCodes[i] == null ? exports.min : aCodes[i];
|
|
103
|
-
const b = bCodes[i] == null ? exports.min : bCodes[i];
|
|
104
|
-
if (a === b) {
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return a - b;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
throw new Error(`Impossible to compare similar position "${posA}" and "${posB}"`);
|
|
112
|
-
}
|
|
113
|
-
exports.compare = compare;
|
package/lib/cjs/room.d.ts
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { Others, Presence, Room, MyPresenceCallback, OthersEventCallback, EventCallback, User, Connection, ErrorCallback, AuthenticationToken, ConnectionCallback, StorageCallback, StorageUpdate, BroadcastOptions, AuthorizeResponse, Authentication } from "./types";
|
|
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
|
-
}>;
|
|
11
|
-
declare type IdFactory = () => string;
|
|
12
|
-
export declare type State = {
|
|
13
|
-
connection: Connection;
|
|
14
|
-
lastConnectionId: number | null;
|
|
15
|
-
socket: WebSocket | null;
|
|
16
|
-
lastFlushTime: number;
|
|
17
|
-
buffer: {
|
|
18
|
-
presence: Presence | null;
|
|
19
|
-
messages: ClientMessage[];
|
|
20
|
-
storageOperations: Op[];
|
|
21
|
-
};
|
|
22
|
-
timeoutHandles: {
|
|
23
|
-
flush: number | null;
|
|
24
|
-
reconnect: number;
|
|
25
|
-
pongTimeout: number;
|
|
26
|
-
};
|
|
27
|
-
intervalHandles: {
|
|
28
|
-
heartbeat: number;
|
|
29
|
-
};
|
|
30
|
-
listeners: {
|
|
31
|
-
event: EventCallback[];
|
|
32
|
-
others: OthersEventCallback[];
|
|
33
|
-
"my-presence": MyPresenceCallback[];
|
|
34
|
-
error: ErrorCallback[];
|
|
35
|
-
connection: ConnectionCallback[];
|
|
36
|
-
storage: StorageCallback[];
|
|
37
|
-
};
|
|
38
|
-
me: Presence;
|
|
39
|
-
others: Others;
|
|
40
|
-
users: {
|
|
41
|
-
[connectionId: number]: User;
|
|
42
|
-
};
|
|
43
|
-
idFactory: IdFactory | null;
|
|
44
|
-
numberOfRetry: number;
|
|
45
|
-
defaultStorageRoot?: {
|
|
46
|
-
[key: string]: any;
|
|
47
|
-
};
|
|
48
|
-
clock: number;
|
|
49
|
-
opClock: number;
|
|
50
|
-
items: Map<string, AbstractCrdt>;
|
|
51
|
-
root: LiveObject | undefined;
|
|
52
|
-
undoStack: HistoryItem[];
|
|
53
|
-
redoStack: HistoryItem[];
|
|
54
|
-
isHistoryPaused: boolean;
|
|
55
|
-
pausedHistory: HistoryItem;
|
|
56
|
-
isBatching: boolean;
|
|
57
|
-
batch: {
|
|
58
|
-
ops: Op[];
|
|
59
|
-
reverseOps: HistoryItem;
|
|
60
|
-
updates: {
|
|
61
|
-
others: [];
|
|
62
|
-
presence: boolean;
|
|
63
|
-
storageUpdates: Map<string, StorageUpdate>;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
offlineOperations: Map<string, Op>;
|
|
67
|
-
};
|
|
68
|
-
export declare type Effects = {
|
|
69
|
-
authenticate(auth: (room: string) => Promise<AuthorizeResponse>, createWebSocket: (token: string) => WebSocket): void;
|
|
70
|
-
send(messages: ClientMessage[]): void;
|
|
71
|
-
delayFlush(delay: number): number;
|
|
72
|
-
startHeartbeatInterval(): number;
|
|
73
|
-
schedulePongTimeout(): number;
|
|
74
|
-
scheduleReconnect(delay: number): number;
|
|
75
|
-
};
|
|
76
|
-
declare type Context = {
|
|
77
|
-
room: string;
|
|
78
|
-
throttleDelay: number;
|
|
79
|
-
fetchPolyfill?: typeof fetch;
|
|
80
|
-
WebSocketPolyfill?: typeof WebSocket;
|
|
81
|
-
authentication: Authentication;
|
|
82
|
-
liveblocksServer: string;
|
|
83
|
-
};
|
|
84
|
-
export declare function makeStateMachine(state: State, context: Context, mockedEffects?: Effects): {
|
|
85
|
-
onClose: (event: {
|
|
86
|
-
code: number;
|
|
87
|
-
wasClean: boolean;
|
|
88
|
-
reason: any;
|
|
89
|
-
}) => void;
|
|
90
|
-
onMessage: (event: MessageEvent) => void;
|
|
91
|
-
authenticationSuccess: (token: AuthenticationToken, socket: WebSocket) => void;
|
|
92
|
-
heartbeat: () => void;
|
|
93
|
-
onNavigatorOnline: () => void;
|
|
94
|
-
simulateSocketClose: () => void;
|
|
95
|
-
simulateSendCloseEvent: (event: {
|
|
96
|
-
code: number;
|
|
97
|
-
wasClean: boolean;
|
|
98
|
-
reason: any;
|
|
99
|
-
}) => void;
|
|
100
|
-
onVisibilityChange: (visibilityState: VisibilityState) => void;
|
|
101
|
-
getUndoStack: () => HistoryItem[];
|
|
102
|
-
getItemsCount: () => number;
|
|
103
|
-
connect: () => null | undefined;
|
|
104
|
-
disconnect: () => void;
|
|
105
|
-
subscribe: {
|
|
106
|
-
(callback: (updates: StorageUpdate) => void): () => void;
|
|
107
|
-
<TKey extends string, TValue>(liveMap: LiveMap<TKey, TValue>, callback: (liveMap: LiveMap<TKey, TValue>) => void): () => void;
|
|
108
|
-
<TData>(liveObject: LiveObject<TData>, callback: (liveObject: LiveObject<TData>) => void): () => void;
|
|
109
|
-
<TItem>(liveList: LiveList<TItem>, callback: (liveList: LiveList<TItem>) => void): () => void;
|
|
110
|
-
<TItem_1 extends AbstractCrdt>(node: TItem_1, callback: (updates: StorageUpdate[]) => void, options: {
|
|
111
|
-
isDeep: true;
|
|
112
|
-
}): () => void;
|
|
113
|
-
<T extends Presence>(type: "my-presence", listener: MyPresenceCallback<T>): () => void;
|
|
114
|
-
<T_1 extends Presence>(type: "others", listener: OthersEventCallback<T_1>): () => void;
|
|
115
|
-
(type: "event", listener: EventCallback): () => void;
|
|
116
|
-
(type: "error", listener: ErrorCallback): () => void;
|
|
117
|
-
(type: "connection", listener: ConnectionCallback): () => void;
|
|
118
|
-
};
|
|
119
|
-
unsubscribe: {
|
|
120
|
-
<T_2 extends Presence>(type: "my-presence", listener: MyPresenceCallback<T_2>): void;
|
|
121
|
-
<T_3 extends Presence>(type: "others", listener: OthersEventCallback<T_3>): void;
|
|
122
|
-
(type: "event", listener: EventCallback): void;
|
|
123
|
-
(type: "error", listener: ErrorCallback): void;
|
|
124
|
-
(type: "connection", listener: ConnectionCallback): void;
|
|
125
|
-
};
|
|
126
|
-
updatePresence: <T_4 extends Presence>(overrides: Partial<T_4>, options?: {
|
|
127
|
-
addToHistory: boolean;
|
|
128
|
-
} | undefined) => void;
|
|
129
|
-
broadcastEvent: (event: any, options?: BroadcastOptions) => void;
|
|
130
|
-
batch: (callback: () => void) => void;
|
|
131
|
-
undo: () => void;
|
|
132
|
-
redo: () => void;
|
|
133
|
-
pauseHistory: () => void;
|
|
134
|
-
resumeHistory: () => void;
|
|
135
|
-
getStorage: <TRoot>() => Promise<{
|
|
136
|
-
root: LiveObject<TRoot>;
|
|
137
|
-
}>;
|
|
138
|
-
selectors: {
|
|
139
|
-
getConnectionState: () => "failed" | "closed" | "connecting" | "open" | "authenticating" | "unavailable";
|
|
140
|
-
getSelf: <TPresence extends Presence = Presence>() => User<TPresence> | null;
|
|
141
|
-
getPresence: <T_5 extends Presence>() => T_5;
|
|
142
|
-
getOthers: <T_6 extends Presence>() => Others<T_6>;
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
export declare function defaultState(me?: Presence, defaultStorageRoot?: {
|
|
146
|
-
[key: string]: any;
|
|
147
|
-
}): State;
|
|
148
|
-
export declare type InternalRoom = {
|
|
149
|
-
room: Room;
|
|
150
|
-
connect: () => void;
|
|
151
|
-
disconnect: () => void;
|
|
152
|
-
onNavigatorOnline: () => void;
|
|
153
|
-
onVisibilityChange: (visibilityState: VisibilityState) => void;
|
|
154
|
-
};
|
|
155
|
-
export declare function createRoom(options: {
|
|
156
|
-
defaultPresence?: Presence;
|
|
157
|
-
defaultStorageRoot?: Record<string, any>;
|
|
158
|
-
}, context: Context): InternalRoom;
|
|
159
|
-
export {};
|