@liveblocks/core 1.5.0-test1 → 1.5.0-test2
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/dist/index.d.mts +46 -13
- package/dist/index.d.ts +46 -13
- package/dist/index.js +225 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __export = (target, all) => {
|
|
|
6
6
|
|
|
7
7
|
// src/version.ts
|
|
8
8
|
var PKG_NAME = "@liveblocks/core";
|
|
9
|
-
var PKG_VERSION = "1.5.0-
|
|
9
|
+
var PKG_VERSION = "1.5.0-test2";
|
|
10
10
|
var PKG_FORMAT = "cjs";
|
|
11
11
|
|
|
12
12
|
// src/dupe-detection.ts
|
|
@@ -585,8 +585,8 @@ function tryParseJson(rawMessage) {
|
|
|
585
585
|
return void 0;
|
|
586
586
|
}
|
|
587
587
|
}
|
|
588
|
-
function deepClone(
|
|
589
|
-
return JSON.parse(JSON.stringify(
|
|
588
|
+
function deepClone(value) {
|
|
589
|
+
return JSON.parse(JSON.stringify(value));
|
|
590
590
|
}
|
|
591
591
|
function b64decode(b64value) {
|
|
592
592
|
try {
|
|
@@ -673,6 +673,9 @@ function shouldRetryWithoutReauth(code) {
|
|
|
673
673
|
}
|
|
674
674
|
|
|
675
675
|
// src/connection.ts
|
|
676
|
+
function isIdle(status) {
|
|
677
|
+
return status === "initial" || status === "disconnected";
|
|
678
|
+
}
|
|
676
679
|
function newToLegacyStatus(status) {
|
|
677
680
|
switch (status) {
|
|
678
681
|
case "connecting":
|
|
@@ -701,6 +704,7 @@ function toNewConnectionStatus(machine) {
|
|
|
701
704
|
case "@auth.backoff":
|
|
702
705
|
case "@connecting.busy":
|
|
703
706
|
case "@connecting.backoff":
|
|
707
|
+
case "@idle.zombie":
|
|
704
708
|
return machine.context.successCount > 0 ? "reconnecting" : "connecting";
|
|
705
709
|
case "@idle.failed":
|
|
706
710
|
return "disconnected";
|
|
@@ -842,7 +846,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
842
846
|
socket: null,
|
|
843
847
|
backoffDelay: RESET_DELAY
|
|
844
848
|
};
|
|
845
|
-
const machine = new FSM(initialContext).addState("@idle.initial").addState("@idle.failed").addState("@auth.busy").addState("@auth.backoff").addState("@connecting.busy").addState("@connecting.backoff").addState("@ok.connected").addState("@ok.awaiting-pong");
|
|
849
|
+
const machine = new FSM(initialContext).addState("@idle.initial").addState("@idle.failed").addState("@idle.zombie").addState("@auth.busy").addState("@auth.backoff").addState("@connecting.busy").addState("@connecting.backoff").addState("@ok.connected").addState("@ok.awaiting-pong");
|
|
846
850
|
machine.addTransitions("*", {
|
|
847
851
|
RECONNECT: {
|
|
848
852
|
target: "@auth.backoff",
|
|
@@ -1052,11 +1056,20 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
1052
1056
|
_optionalChain([ctx, 'access', _14 => _14.socket, 'optionalAccess', _15 => _15.send, 'call', _16 => _16("ping")]);
|
|
1053
1057
|
}
|
|
1054
1058
|
};
|
|
1055
|
-
|
|
1056
|
-
|
|
1059
|
+
const maybeHeartbeat = () => {
|
|
1060
|
+
const doc = typeof document !== "undefined" ? document : void 0;
|
|
1061
|
+
const canZombie = _optionalChain([doc, 'optionalAccess', _17 => _17.visibilityState]) === "hidden" && delegates.canZombie();
|
|
1062
|
+
return canZombie ? "@idle.zombie" : sendHeartbeat;
|
|
1063
|
+
};
|
|
1064
|
+
machine.addTimedTransition("@ok.connected", HEARTBEAT_INTERVAL, maybeHeartbeat).addTransitions("@ok.connected", {
|
|
1065
|
+
NAVIGATOR_OFFLINE: maybeHeartbeat,
|
|
1057
1066
|
// Don't take the browser's word for it when it says it's offline. Do a ping/pong to make sure.
|
|
1058
1067
|
WINDOW_GOT_FOCUS: sendHeartbeat
|
|
1059
1068
|
});
|
|
1069
|
+
machine.addTransitions("@idle.zombie", {
|
|
1070
|
+
WINDOW_GOT_FOCUS: "@connecting.backoff"
|
|
1071
|
+
// When in zombie state, the client will try to wake up automatically when the window regains focus
|
|
1072
|
+
});
|
|
1060
1073
|
machine.onEnter("@ok.*", (ctx) => {
|
|
1061
1074
|
ctx.patch({ successCount: ctx.successCount + 1 });
|
|
1062
1075
|
const timerID = setTimeout(
|
|
@@ -1084,7 +1097,7 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
1084
1097
|
// socket, or not. So always check to see if the socket is still OPEN or
|
|
1085
1098
|
// not. When still OPEN, don't transition.
|
|
1086
1099
|
EXPLICIT_SOCKET_ERROR: (_, context) => {
|
|
1087
|
-
if (_optionalChain([context, 'access',
|
|
1100
|
+
if (_optionalChain([context, 'access', _18 => _18.socket, 'optionalAccess', _19 => _19.readyState]) === 1) {
|
|
1088
1101
|
return null;
|
|
1089
1102
|
}
|
|
1090
1103
|
return {
|
|
@@ -1136,17 +1149,17 @@ function createConnectionStateMachine(delegates, options) {
|
|
|
1136
1149
|
machine.send({ type: "NAVIGATOR_ONLINE" });
|
|
1137
1150
|
}
|
|
1138
1151
|
function onVisibilityChange() {
|
|
1139
|
-
if (_optionalChain([doc, 'optionalAccess',
|
|
1152
|
+
if (_optionalChain([doc, 'optionalAccess', _20 => _20.visibilityState]) === "visible") {
|
|
1140
1153
|
machine.send({ type: "WINDOW_GOT_FOCUS" });
|
|
1141
1154
|
}
|
|
1142
1155
|
}
|
|
1143
|
-
_optionalChain([win, 'optionalAccess',
|
|
1144
|
-
_optionalChain([win, 'optionalAccess',
|
|
1145
|
-
_optionalChain([root, 'optionalAccess',
|
|
1156
|
+
_optionalChain([win, 'optionalAccess', _21 => _21.addEventListener, 'call', _22 => _22("online", onNetworkBackOnline)]);
|
|
1157
|
+
_optionalChain([win, 'optionalAccess', _23 => _23.addEventListener, 'call', _24 => _24("offline", onNetworkOffline)]);
|
|
1158
|
+
_optionalChain([root, 'optionalAccess', _25 => _25.addEventListener, 'call', _26 => _26("visibilitychange", onVisibilityChange)]);
|
|
1146
1159
|
return () => {
|
|
1147
|
-
_optionalChain([root, 'optionalAccess',
|
|
1148
|
-
_optionalChain([win, 'optionalAccess',
|
|
1149
|
-
_optionalChain([win, 'optionalAccess',
|
|
1160
|
+
_optionalChain([root, 'optionalAccess', _27 => _27.removeEventListener, 'call', _28 => _28("visibilitychange", onVisibilityChange)]);
|
|
1161
|
+
_optionalChain([win, 'optionalAccess', _29 => _29.removeEventListener, 'call', _30 => _30("online", onNetworkBackOnline)]);
|
|
1162
|
+
_optionalChain([win, 'optionalAccess', _31 => _31.removeEventListener, 'call', _32 => _32("offline", onNetworkOffline)]);
|
|
1150
1163
|
teardownSocket(ctx.socket);
|
|
1151
1164
|
};
|
|
1152
1165
|
});
|
|
@@ -1235,7 +1248,7 @@ var ManagedSocket = class {
|
|
|
1235
1248
|
* message if this is somehow impossible.
|
|
1236
1249
|
*/
|
|
1237
1250
|
send(data) {
|
|
1238
|
-
const socket = _optionalChain([this, 'access',
|
|
1251
|
+
const socket = _optionalChain([this, 'access', _33 => _33.machine, 'access', _34 => _34.context, 'optionalAccess', _35 => _35.socket]);
|
|
1239
1252
|
if (socket === null) {
|
|
1240
1253
|
warn("Cannot send: not connected yet", data);
|
|
1241
1254
|
} else if (socket.readyState !== 1) {
|
|
@@ -1287,6 +1300,12 @@ function createAuthManager(authOptions) {
|
|
|
1287
1300
|
const tokens = [];
|
|
1288
1301
|
const expiryTimes = [];
|
|
1289
1302
|
const requestPromises = /* @__PURE__ */ new Map();
|
|
1303
|
+
function reset() {
|
|
1304
|
+
seenTokens.clear();
|
|
1305
|
+
tokens.length = 0;
|
|
1306
|
+
expiryTimes.length = 0;
|
|
1307
|
+
requestPromises.clear();
|
|
1308
|
+
}
|
|
1290
1309
|
function hasCorrespondingScopes(requestedScope, scopes) {
|
|
1291
1310
|
if (requestedScope === "comments:read") {
|
|
1292
1311
|
return scopes.includes("comments:read" /* CommentsRead */) || scopes.includes("comments:write" /* CommentsWrite */) || scopes.includes("room:read" /* Read */) || scopes.includes("room:write" /* Write */);
|
|
@@ -1318,11 +1337,11 @@ function createAuthManager(authOptions) {
|
|
|
1318
1337
|
return void 0;
|
|
1319
1338
|
}
|
|
1320
1339
|
async function makeAuthRequest(roomId) {
|
|
1321
|
-
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access',
|
|
1340
|
+
const fetcher = _nullishCoalesce(_optionalChain([authOptions, 'access', _36 => _36.polyfills, 'optionalAccess', _37 => _37.fetch]), () => ( (typeof window === "undefined" ? void 0 : window.fetch)));
|
|
1322
1341
|
if (authentication.type === "private") {
|
|
1323
1342
|
if (fetcher === void 0) {
|
|
1324
1343
|
throw new StopRetrying(
|
|
1325
|
-
"To use Liveblocks client in a non-
|
|
1344
|
+
"To use Liveblocks client in a non-DOM environment with a url as auth endpoint, you need to provide a fetch polyfill."
|
|
1326
1345
|
);
|
|
1327
1346
|
}
|
|
1328
1347
|
const response = await fetchAuthEndpoint(fetcher, authentication.url, {
|
|
@@ -1386,6 +1405,7 @@ function createAuthManager(authOptions) {
|
|
|
1386
1405
|
}
|
|
1387
1406
|
}
|
|
1388
1407
|
return {
|
|
1408
|
+
reset,
|
|
1389
1409
|
getAuthValue
|
|
1390
1410
|
};
|
|
1391
1411
|
}
|
|
@@ -1467,6 +1487,9 @@ async function fetchAuthEndpoint(fetch2, endpoint, body) {
|
|
|
1467
1487
|
return { token };
|
|
1468
1488
|
}
|
|
1469
1489
|
|
|
1490
|
+
// src/constants.ts
|
|
1491
|
+
var DEFAULT_BASE_URL = "https://api.liveblocks.io";
|
|
1492
|
+
|
|
1470
1493
|
// src/devtools/bridge.ts
|
|
1471
1494
|
var _bridgeActive = false;
|
|
1472
1495
|
function activateBridge(allowed) {
|
|
@@ -1480,7 +1503,7 @@ function sendToPanel(message, options) {
|
|
|
1480
1503
|
...message,
|
|
1481
1504
|
source: "liveblocks-devtools-client"
|
|
1482
1505
|
};
|
|
1483
|
-
if (!(_optionalChain([options, 'optionalAccess',
|
|
1506
|
+
if (!(_optionalChain([options, 'optionalAccess', _38 => _38.force]) || _bridgeActive)) {
|
|
1484
1507
|
return;
|
|
1485
1508
|
}
|
|
1486
1509
|
window.postMessage(fullMsg, "*");
|
|
@@ -1488,7 +1511,7 @@ function sendToPanel(message, options) {
|
|
|
1488
1511
|
var eventSource = makeEventSource();
|
|
1489
1512
|
if (process.env.NODE_ENV !== "production" && typeof window !== "undefined") {
|
|
1490
1513
|
window.addEventListener("message", (event) => {
|
|
1491
|
-
if (event.source === window && _optionalChain([event, 'access',
|
|
1514
|
+
if (event.source === window && _optionalChain([event, 'access', _39 => _39.data, 'optionalAccess', _40 => _40.source]) === "liveblocks-devtools-panel") {
|
|
1492
1515
|
eventSource.notify(event.data);
|
|
1493
1516
|
} else {
|
|
1494
1517
|
}
|
|
@@ -1624,7 +1647,7 @@ function fullSync(room) {
|
|
|
1624
1647
|
msg: "room::sync::full",
|
|
1625
1648
|
roomId: room.id,
|
|
1626
1649
|
status: room.getStatus(),
|
|
1627
|
-
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess',
|
|
1650
|
+
storage: _nullishCoalesce(_optionalChain([root, 'optionalAccess', _41 => _41.toTreeNode, 'call', _42 => _42("root"), 'access', _43 => _43.payload]), () => ( null)),
|
|
1628
1651
|
me,
|
|
1629
1652
|
others
|
|
1630
1653
|
});
|
|
@@ -1718,7 +1741,7 @@ function getAuthBearerHeaderFromAuthValue(authValue) {
|
|
|
1718
1741
|
return authValue.token.raw;
|
|
1719
1742
|
}
|
|
1720
1743
|
}
|
|
1721
|
-
function createCommentsApi(roomId, getAuthValue,
|
|
1744
|
+
function createCommentsApi(roomId, getAuthValue, config) {
|
|
1722
1745
|
async function fetchJson(endpoint, options) {
|
|
1723
1746
|
const response = await fetchApi(roomId, endpoint, options);
|
|
1724
1747
|
if (!response.ok) {
|
|
@@ -1745,13 +1768,14 @@ function createCommentsApi(roomId, getAuthValue, { serverEndpoint }) {
|
|
|
1745
1768
|
}
|
|
1746
1769
|
async function fetchApi(roomId2, endpoint, options) {
|
|
1747
1770
|
const authValue = await getAuthValue();
|
|
1748
|
-
const url =
|
|
1749
|
-
roomId2
|
|
1750
|
-
|
|
1771
|
+
const url = new URL(
|
|
1772
|
+
`/v2/c/rooms/${encodeURIComponent(roomId2)}${endpoint}`,
|
|
1773
|
+
config.baseUrl
|
|
1774
|
+
).toString();
|
|
1751
1775
|
return await fetch(url, {
|
|
1752
1776
|
...options,
|
|
1753
1777
|
headers: {
|
|
1754
|
-
..._optionalChain([options, 'optionalAccess',
|
|
1778
|
+
..._optionalChain([options, 'optionalAccess', _44 => _44.headers]),
|
|
1755
1779
|
Authorization: `Bearer ${getAuthBearerHeaderFromAuthValue(authValue)}`
|
|
1756
1780
|
}
|
|
1757
1781
|
});
|
|
@@ -2264,7 +2288,7 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2264
2288
|
return [
|
|
2265
2289
|
{
|
|
2266
2290
|
type: 8 /* CREATE_REGISTER */,
|
|
2267
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2291
|
+
opId: _optionalChain([pool, 'optionalAccess', _45 => _45.generateOpId, 'call', _46 => _46()]),
|
|
2268
2292
|
id: this._id,
|
|
2269
2293
|
parentId,
|
|
2270
2294
|
parentKey,
|
|
@@ -2309,6 +2333,9 @@ var LiveRegister = class _LiveRegister extends AbstractCrdt {
|
|
|
2309
2333
|
_toImmutable() {
|
|
2310
2334
|
return this._data;
|
|
2311
2335
|
}
|
|
2336
|
+
clone() {
|
|
2337
|
+
return deepClone(this.data);
|
|
2338
|
+
}
|
|
2312
2339
|
};
|
|
2313
2340
|
|
|
2314
2341
|
// src/crdts/LiveList.ts
|
|
@@ -2363,7 +2390,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2363
2390
|
const ops = [];
|
|
2364
2391
|
const op = {
|
|
2365
2392
|
id: this._id,
|
|
2366
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
2393
|
+
opId: _optionalChain([pool, 'optionalAccess', _47 => _47.generateOpId, 'call', _48 => _48()]),
|
|
2367
2394
|
type: 2 /* CREATE_LIST */,
|
|
2368
2395
|
parentId,
|
|
2369
2396
|
parentKey
|
|
@@ -2640,7 +2667,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2640
2667
|
_applyInsertUndoRedo(op) {
|
|
2641
2668
|
const { id, parentKey: key } = op;
|
|
2642
2669
|
const child = creationOpToLiveNode(op);
|
|
2643
|
-
if (_optionalChain([this, 'access',
|
|
2670
|
+
if (_optionalChain([this, 'access', _49 => _49._pool, 'optionalAccess', _50 => _50.getNode, 'call', _51 => _51(id)]) !== void 0) {
|
|
2644
2671
|
return { modified: false };
|
|
2645
2672
|
}
|
|
2646
2673
|
child._attach(id, nn(this._pool));
|
|
@@ -2648,8 +2675,8 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2648
2675
|
const existingItemIndex = this._indexOfPosition(key);
|
|
2649
2676
|
let newKey = key;
|
|
2650
2677
|
if (existingItemIndex !== -1) {
|
|
2651
|
-
const before2 = _optionalChain([this, 'access',
|
|
2652
|
-
const after2 = _optionalChain([this, 'access',
|
|
2678
|
+
const before2 = _optionalChain([this, 'access', _52 => _52._items, 'access', _53 => _53[existingItemIndex], 'optionalAccess', _54 => _54._parentPos]);
|
|
2679
|
+
const after2 = _optionalChain([this, 'access', _55 => _55._items, 'access', _56 => _56[existingItemIndex + 1], 'optionalAccess', _57 => _57._parentPos]);
|
|
2653
2680
|
newKey = makePosition(before2, after2);
|
|
2654
2681
|
child._setParentLink(this, newKey);
|
|
2655
2682
|
}
|
|
@@ -2664,7 +2691,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2664
2691
|
_applySetUndoRedo(op) {
|
|
2665
2692
|
const { id, parentKey: key } = op;
|
|
2666
2693
|
const child = creationOpToLiveNode(op);
|
|
2667
|
-
if (_optionalChain([this, 'access',
|
|
2694
|
+
if (_optionalChain([this, 'access', _58 => _58._pool, 'optionalAccess', _59 => _59.getNode, 'call', _60 => _60(id)]) !== void 0) {
|
|
2668
2695
|
return { modified: false };
|
|
2669
2696
|
}
|
|
2670
2697
|
this._unacknowledgedSets.set(key, nn(op.opId));
|
|
@@ -2786,7 +2813,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2786
2813
|
} else {
|
|
2787
2814
|
this._items[existingItemIndex]._setParentLink(
|
|
2788
2815
|
this,
|
|
2789
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2816
|
+
makePosition(newKey, _optionalChain([this, 'access', _61 => _61._items, 'access', _62 => _62[existingItemIndex + 1], 'optionalAccess', _63 => _63._parentPos]))
|
|
2790
2817
|
);
|
|
2791
2818
|
const previousIndex = this._items.indexOf(child);
|
|
2792
2819
|
child._setParentLink(this, newKey);
|
|
@@ -2812,7 +2839,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2812
2839
|
if (existingItemIndex !== -1) {
|
|
2813
2840
|
this._items[existingItemIndex]._setParentLink(
|
|
2814
2841
|
this,
|
|
2815
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2842
|
+
makePosition(newKey, _optionalChain([this, 'access', _64 => _64._items, 'access', _65 => _65[existingItemIndex + 1], 'optionalAccess', _66 => _66._parentPos]))
|
|
2816
2843
|
);
|
|
2817
2844
|
}
|
|
2818
2845
|
child._setParentLink(this, newKey);
|
|
@@ -2831,7 +2858,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2831
2858
|
if (existingItemIndex !== -1) {
|
|
2832
2859
|
this._items[existingItemIndex]._setParentLink(
|
|
2833
2860
|
this,
|
|
2834
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2861
|
+
makePosition(newKey, _optionalChain([this, 'access', _67 => _67._items, 'access', _68 => _68[existingItemIndex + 1], 'optionalAccess', _69 => _69._parentPos]))
|
|
2835
2862
|
);
|
|
2836
2863
|
}
|
|
2837
2864
|
child._setParentLink(this, newKey);
|
|
@@ -2859,7 +2886,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2859
2886
|
if (existingItemIndex !== -1) {
|
|
2860
2887
|
this._items[existingItemIndex]._setParentLink(
|
|
2861
2888
|
this,
|
|
2862
|
-
makePosition(newKey, _optionalChain([this, 'access',
|
|
2889
|
+
makePosition(newKey, _optionalChain([this, 'access', _70 => _70._items, 'access', _71 => _71[existingItemIndex + 1], 'optionalAccess', _72 => _72._parentPos]))
|
|
2863
2890
|
);
|
|
2864
2891
|
}
|
|
2865
2892
|
child._setParentLink(this, newKey);
|
|
@@ -2917,7 +2944,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2917
2944
|
* @param element The element to add to the end of the LiveList.
|
|
2918
2945
|
*/
|
|
2919
2946
|
push(element) {
|
|
2920
|
-
_optionalChain([this, 'access',
|
|
2947
|
+
_optionalChain([this, 'access', _73 => _73._pool, 'optionalAccess', _74 => _74.assertStorageIsWritable, 'call', _75 => _75()]);
|
|
2921
2948
|
return this.insert(element, this.length);
|
|
2922
2949
|
}
|
|
2923
2950
|
/**
|
|
@@ -2926,7 +2953,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2926
2953
|
* @param index The index at which you want to insert the element.
|
|
2927
2954
|
*/
|
|
2928
2955
|
insert(element, index) {
|
|
2929
|
-
_optionalChain([this, 'access',
|
|
2956
|
+
_optionalChain([this, 'access', _76 => _76._pool, 'optionalAccess', _77 => _77.assertStorageIsWritable, 'call', _78 => _78()]);
|
|
2930
2957
|
if (index < 0 || index > this._items.length) {
|
|
2931
2958
|
throw new Error(
|
|
2932
2959
|
`Cannot insert list item at index "${index}". index should be between 0 and ${this._items.length}`
|
|
@@ -2956,7 +2983,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
2956
2983
|
* @param targetIndex The index where the element should be after moving.
|
|
2957
2984
|
*/
|
|
2958
2985
|
move(index, targetIndex) {
|
|
2959
|
-
_optionalChain([this, 'access',
|
|
2986
|
+
_optionalChain([this, 'access', _79 => _79._pool, 'optionalAccess', _80 => _80.assertStorageIsWritable, 'call', _81 => _81()]);
|
|
2960
2987
|
if (targetIndex < 0) {
|
|
2961
2988
|
throw new Error("targetIndex cannot be less than 0");
|
|
2962
2989
|
}
|
|
@@ -3014,7 +3041,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3014
3041
|
* @param index The index of the element to delete
|
|
3015
3042
|
*/
|
|
3016
3043
|
delete(index) {
|
|
3017
|
-
_optionalChain([this, 'access',
|
|
3044
|
+
_optionalChain([this, 'access', _82 => _82._pool, 'optionalAccess', _83 => _83.assertStorageIsWritable, 'call', _84 => _84()]);
|
|
3018
3045
|
if (index < 0 || index >= this._items.length) {
|
|
3019
3046
|
throw new Error(
|
|
3020
3047
|
`Cannot delete list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -3047,7 +3074,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3047
3074
|
}
|
|
3048
3075
|
}
|
|
3049
3076
|
clear() {
|
|
3050
|
-
_optionalChain([this, 'access',
|
|
3077
|
+
_optionalChain([this, 'access', _85 => _85._pool, 'optionalAccess', _86 => _86.assertStorageIsWritable, 'call', _87 => _87()]);
|
|
3051
3078
|
if (this._pool) {
|
|
3052
3079
|
const ops = [];
|
|
3053
3080
|
const reverseOps = [];
|
|
@@ -3081,7 +3108,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3081
3108
|
}
|
|
3082
3109
|
}
|
|
3083
3110
|
set(index, item) {
|
|
3084
|
-
_optionalChain([this, 'access',
|
|
3111
|
+
_optionalChain([this, 'access', _88 => _88._pool, 'optionalAccess', _89 => _89.assertStorageIsWritable, 'call', _90 => _90()]);
|
|
3085
3112
|
if (index < 0 || index >= this._items.length) {
|
|
3086
3113
|
throw new Error(
|
|
3087
3114
|
`Cannot set list item at index "${index}". index should be between 0 and ${this._items.length - 1}`
|
|
@@ -3229,7 +3256,7 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3229
3256
|
_shiftItemPosition(index, key) {
|
|
3230
3257
|
const shiftedPosition = makePosition(
|
|
3231
3258
|
key,
|
|
3232
|
-
this._items.length > index + 1 ? _optionalChain([this, 'access',
|
|
3259
|
+
this._items.length > index + 1 ? _optionalChain([this, 'access', _91 => _91._items, 'access', _92 => _92[index + 1], 'optionalAccess', _93 => _93._parentPos]) : void 0
|
|
3233
3260
|
);
|
|
3234
3261
|
this._items[index]._setParentLink(this, shiftedPosition);
|
|
3235
3262
|
}
|
|
@@ -3252,6 +3279,9 @@ var LiveList = class _LiveList extends AbstractCrdt {
|
|
|
3252
3279
|
const result = this._items.map((node) => node.toImmutable());
|
|
3253
3280
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
3254
3281
|
}
|
|
3282
|
+
clone() {
|
|
3283
|
+
return new _LiveList(this._items.map((item) => item.clone()));
|
|
3284
|
+
}
|
|
3255
3285
|
};
|
|
3256
3286
|
var LiveListIterator = class {
|
|
3257
3287
|
constructor(items) {
|
|
@@ -3335,10 +3365,10 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3335
3365
|
this.unacknowledgedSet = /* @__PURE__ */ new Map();
|
|
3336
3366
|
if (entries2) {
|
|
3337
3367
|
const mappedEntries = [];
|
|
3338
|
-
for (const
|
|
3339
|
-
const
|
|
3340
|
-
|
|
3341
|
-
mappedEntries.push([
|
|
3368
|
+
for (const [key, value] of entries2) {
|
|
3369
|
+
const node = lsonToLiveNode(value);
|
|
3370
|
+
node._setParentLink(this, key);
|
|
3371
|
+
mappedEntries.push([key, node]);
|
|
3342
3372
|
}
|
|
3343
3373
|
this._map = new Map(mappedEntries);
|
|
3344
3374
|
} else {
|
|
@@ -3355,7 +3385,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3355
3385
|
const ops = [];
|
|
3356
3386
|
const op = {
|
|
3357
3387
|
id: this._id,
|
|
3358
|
-
opId: _optionalChain([pool, 'optionalAccess',
|
|
3388
|
+
opId: _optionalChain([pool, 'optionalAccess', _94 => _94.generateOpId, 'call', _95 => _95()]),
|
|
3359
3389
|
type: 7 /* CREATE_MAP */,
|
|
3360
3390
|
parentId,
|
|
3361
3391
|
parentKey
|
|
@@ -3502,7 +3532,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3502
3532
|
* @param value The value of the element to add. Should be serializable to JSON.
|
|
3503
3533
|
*/
|
|
3504
3534
|
set(key, value) {
|
|
3505
|
-
_optionalChain([this, 'access',
|
|
3535
|
+
_optionalChain([this, 'access', _96 => _96._pool, 'optionalAccess', _97 => _97.assertStorageIsWritable, 'call', _98 => _98()]);
|
|
3506
3536
|
const oldValue = this._map.get(key);
|
|
3507
3537
|
if (oldValue) {
|
|
3508
3538
|
oldValue._detach();
|
|
@@ -3548,7 +3578,7 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3548
3578
|
* @returns true if an element existed and has been removed, or false if the element does not exist.
|
|
3549
3579
|
*/
|
|
3550
3580
|
delete(key) {
|
|
3551
|
-
_optionalChain([this, 'access',
|
|
3581
|
+
_optionalChain([this, 'access', _99 => _99._pool, 'optionalAccess', _100 => _100.assertStorageIsWritable, 'call', _101 => _101()]);
|
|
3552
3582
|
const item = this._map.get(key);
|
|
3553
3583
|
if (item === void 0) {
|
|
3554
3584
|
return false;
|
|
@@ -3669,6 +3699,11 @@ var LiveMap = class _LiveMap extends AbstractCrdt {
|
|
|
3669
3699
|
}
|
|
3670
3700
|
return freeze(result);
|
|
3671
3701
|
}
|
|
3702
|
+
clone() {
|
|
3703
|
+
return new _LiveMap(
|
|
3704
|
+
Array.from(this._map).map(([key, node]) => [key, node.clone()])
|
|
3705
|
+
);
|
|
3706
|
+
}
|
|
3672
3707
|
};
|
|
3673
3708
|
|
|
3674
3709
|
// src/crdts/LiveObject.ts
|
|
@@ -3722,7 +3757,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
3722
3757
|
if (this._id === void 0) {
|
|
3723
3758
|
throw new Error("Cannot serialize item is not attached");
|
|
3724
3759
|
}
|
|
3725
|
-
const opId = _optionalChain([pool, 'optionalAccess',
|
|
3760
|
+
const opId = _optionalChain([pool, 'optionalAccess', _102 => _102.generateOpId, 'call', _103 => _103()]);
|
|
3726
3761
|
const ops = [];
|
|
3727
3762
|
const op = parentId !== void 0 && parentKey !== void 0 ? {
|
|
3728
3763
|
type: 4 /* CREATE_OBJECT */,
|
|
@@ -4003,7 +4038,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4003
4038
|
* @param value The value of the property to add
|
|
4004
4039
|
*/
|
|
4005
4040
|
set(key, value) {
|
|
4006
|
-
_optionalChain([this, 'access',
|
|
4041
|
+
_optionalChain([this, 'access', _104 => _104._pool, 'optionalAccess', _105 => _105.assertStorageIsWritable, 'call', _106 => _106()]);
|
|
4007
4042
|
this.update({ [key]: value });
|
|
4008
4043
|
}
|
|
4009
4044
|
/**
|
|
@@ -4018,7 +4053,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4018
4053
|
* @param key The key of the property to delete
|
|
4019
4054
|
*/
|
|
4020
4055
|
delete(key) {
|
|
4021
|
-
_optionalChain([this, 'access',
|
|
4056
|
+
_optionalChain([this, 'access', _107 => _107._pool, 'optionalAccess', _108 => _108.assertStorageIsWritable, 'call', _109 => _109()]);
|
|
4022
4057
|
const keyAsString = key;
|
|
4023
4058
|
const oldValue = this._map.get(keyAsString);
|
|
4024
4059
|
if (oldValue === void 0) {
|
|
@@ -4071,7 +4106,7 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4071
4106
|
* @param patch The object used to overrides properties
|
|
4072
4107
|
*/
|
|
4073
4108
|
update(patch) {
|
|
4074
|
-
_optionalChain([this, 'access',
|
|
4109
|
+
_optionalChain([this, 'access', _110 => _110._pool, 'optionalAccess', _111 => _111.assertStorageIsWritable, 'call', _112 => _112()]);
|
|
4075
4110
|
if (this._pool === void 0 || this._id === void 0) {
|
|
4076
4111
|
for (const key in patch) {
|
|
4077
4112
|
const newValue = patch[key];
|
|
@@ -4179,6 +4214,16 @@ var LiveObject = class _LiveObject extends AbstractCrdt {
|
|
|
4179
4214
|
}
|
|
4180
4215
|
return process.env.NODE_ENV === "production" ? result : Object.freeze(result);
|
|
4181
4216
|
}
|
|
4217
|
+
clone() {
|
|
4218
|
+
return new _LiveObject(
|
|
4219
|
+
Object.fromEntries(
|
|
4220
|
+
Array.from(this._map).map(([key, value]) => [
|
|
4221
|
+
key,
|
|
4222
|
+
isLiveStructure(value) ? value.clone() : deepClone(value)
|
|
4223
|
+
])
|
|
4224
|
+
)
|
|
4225
|
+
);
|
|
4226
|
+
}
|
|
4182
4227
|
};
|
|
4183
4228
|
|
|
4184
4229
|
// src/crdts/liveblocks-helpers.ts
|
|
@@ -4264,6 +4309,9 @@ function isLiveObject(value) {
|
|
|
4264
4309
|
function isLiveRegister(value) {
|
|
4265
4310
|
return value instanceof LiveRegister;
|
|
4266
4311
|
}
|
|
4312
|
+
function cloneLson(value) {
|
|
4313
|
+
return value === void 0 ? void 0 : isLiveStructure(value) ? value.clone() : deepClone(value);
|
|
4314
|
+
}
|
|
4267
4315
|
function liveNodeToLson(obj) {
|
|
4268
4316
|
if (obj instanceof LiveRegister) {
|
|
4269
4317
|
return obj.data;
|
|
@@ -4698,10 +4746,40 @@ function userToTreeNode(key, user) {
|
|
|
4698
4746
|
payload: user
|
|
4699
4747
|
};
|
|
4700
4748
|
}
|
|
4749
|
+
function installBackgroundTabSpy() {
|
|
4750
|
+
const doc = typeof document !== "undefined" ? document : void 0;
|
|
4751
|
+
const inBackgroundSince = { current: null };
|
|
4752
|
+
function onVisibilityChange() {
|
|
4753
|
+
if (_optionalChain([doc, 'optionalAccess', _113 => _113.visibilityState]) === "hidden") {
|
|
4754
|
+
inBackgroundSince.current = _nullishCoalesce(inBackgroundSince.current, () => ( Date.now()));
|
|
4755
|
+
} else {
|
|
4756
|
+
inBackgroundSince.current = null;
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
_optionalChain([doc, 'optionalAccess', _114 => _114.addEventListener, 'call', _115 => _115("visibilitychange", onVisibilityChange)]);
|
|
4760
|
+
const unsub = () => {
|
|
4761
|
+
_optionalChain([doc, 'optionalAccess', _116 => _116.removeEventListener, 'call', _117 => _117("visibilitychange", onVisibilityChange)]);
|
|
4762
|
+
};
|
|
4763
|
+
return [inBackgroundSince, unsub];
|
|
4764
|
+
}
|
|
4701
4765
|
function createRoom(options, config) {
|
|
4702
4766
|
const initialPresence = typeof options.initialPresence === "function" ? options.initialPresence(config.roomId) : options.initialPresence;
|
|
4703
4767
|
const initialStorage = typeof options.initialStorage === "function" ? options.initialStorage(config.roomId) : options.initialStorage;
|
|
4704
|
-
const
|
|
4768
|
+
const [inBackgroundSince, uninstallBgTabSpy] = installBackgroundTabSpy();
|
|
4769
|
+
const delegates = {
|
|
4770
|
+
...config.delegates,
|
|
4771
|
+
// A connection is allowed to go into "zombie state" only if all of the
|
|
4772
|
+
// following conditions apply:
|
|
4773
|
+
//
|
|
4774
|
+
// - The `backgroundKeepAliveTimeout` client option is configured
|
|
4775
|
+
// - The browser window has been in the background for at least
|
|
4776
|
+
// `backgroundKeepAliveTimeout` milliseconds
|
|
4777
|
+
// - There are no pending changes
|
|
4778
|
+
//
|
|
4779
|
+
canZombie() {
|
|
4780
|
+
return config.backgroundKeepAliveTimeout !== void 0 && inBackgroundSince.current !== null && Date.now() > inBackgroundSince.current + config.backgroundKeepAliveTimeout && getStorageStatus() !== "synchronizing";
|
|
4781
|
+
}
|
|
4782
|
+
};
|
|
4705
4783
|
const managedSocket = new ManagedSocket(
|
|
4706
4784
|
delegates,
|
|
4707
4785
|
config.enableDebugLogging
|
|
@@ -4870,7 +4948,7 @@ function createRoom(options, config) {
|
|
|
4870
4948
|
}
|
|
4871
4949
|
},
|
|
4872
4950
|
assertStorageIsWritable: () => {
|
|
4873
|
-
const scopes = _optionalChain([context, 'access',
|
|
4951
|
+
const scopes = _optionalChain([context, 'access', _118 => _118.dynamicSessionInfo, 'access', _119 => _119.current, 'optionalAccess', _120 => _120.scopes]);
|
|
4874
4952
|
if (scopes === void 0) {
|
|
4875
4953
|
return;
|
|
4876
4954
|
}
|
|
@@ -4901,15 +4979,13 @@ function createRoom(options, config) {
|
|
|
4901
4979
|
comments: makeEventSource()
|
|
4902
4980
|
};
|
|
4903
4981
|
async function httpSend(authTokenOrPublicApiKey, roomId, nonce, messages) {
|
|
4904
|
-
const baseUrl = new URL(config.liveblocksServer);
|
|
4905
|
-
baseUrl.protocol = "https";
|
|
4906
4982
|
const url = new URL(
|
|
4907
4983
|
`/v2/c/rooms/${encodeURIComponent(roomId)}/send-message`,
|
|
4908
|
-
baseUrl
|
|
4909
|
-
);
|
|
4910
|
-
const fetcher = _optionalChain([config, 'access',
|
|
4984
|
+
config.baseUrl
|
|
4985
|
+
).toString();
|
|
4986
|
+
const fetcher = _optionalChain([config, 'access', _121 => _121.polyfills, 'optionalAccess', _122 => _122.fetch]) || /* istanbul ignore next */
|
|
4911
4987
|
fetch;
|
|
4912
|
-
return fetcher(url
|
|
4988
|
+
return fetcher(url, {
|
|
4913
4989
|
method: "POST",
|
|
4914
4990
|
headers: {
|
|
4915
4991
|
"Content-Type": "application/json",
|
|
@@ -4920,7 +4996,7 @@ function createRoom(options, config) {
|
|
|
4920
4996
|
}
|
|
4921
4997
|
function sendMessages(messages) {
|
|
4922
4998
|
const serializedPayload = JSON.stringify(messages);
|
|
4923
|
-
const nonce = _optionalChain([context, 'access',
|
|
4999
|
+
const nonce = _optionalChain([context, 'access', _123 => _123.dynamicSessionInfo, 'access', _124 => _124.current, 'optionalAccess', _125 => _125.nonce]);
|
|
4924
5000
|
if (config.unstable_fallbackToHTTP && managedSocket.authValue && nonce) {
|
|
4925
5001
|
const size = new TextEncoder().encode(serializedPayload).length;
|
|
4926
5002
|
if (size > MAX_SOCKET_MESSAGE_SIZE) {
|
|
@@ -4990,7 +5066,7 @@ function createRoom(options, config) {
|
|
|
4990
5066
|
const stackSizeBefore = context.undoStack.length;
|
|
4991
5067
|
for (const key in context.initialStorage) {
|
|
4992
5068
|
if (context.root.get(key) === void 0) {
|
|
4993
|
-
context.root.set(key, context.initialStorage[key]);
|
|
5069
|
+
context.root.set(key, cloneLson(context.initialStorage[key]));
|
|
4994
5070
|
}
|
|
4995
5071
|
}
|
|
4996
5072
|
context.undoStack.length = stackSizeBefore;
|
|
@@ -5021,25 +5097,23 @@ function createRoom(options, config) {
|
|
|
5021
5097
|
_addToRealUndoStack(historyOps, batchedUpdatesWrapper);
|
|
5022
5098
|
}
|
|
5023
5099
|
}
|
|
5024
|
-
function notify({
|
|
5025
|
-
storageUpdates =
|
|
5026
|
-
|
|
5027
|
-
others: otherEvents = []
|
|
5028
|
-
}, batchedUpdatesWrapper) {
|
|
5100
|
+
function notify(updates, batchedUpdatesWrapper) {
|
|
5101
|
+
const storageUpdates = updates.storageUpdates;
|
|
5102
|
+
const othersUpdates = updates.others;
|
|
5029
5103
|
batchedUpdatesWrapper(() => {
|
|
5030
|
-
if (
|
|
5104
|
+
if (othersUpdates !== void 0 && othersUpdates.length > 0) {
|
|
5031
5105
|
const others = context.others.current;
|
|
5032
|
-
for (const event of
|
|
5033
|
-
eventHub.others.notify({
|
|
5106
|
+
for (const event of othersUpdates) {
|
|
5107
|
+
eventHub.others.notify({ ...event, others });
|
|
5034
5108
|
}
|
|
5035
5109
|
}
|
|
5036
|
-
if (presence) {
|
|
5110
|
+
if (_nullishCoalesce(updates.presence, () => ( false))) {
|
|
5037
5111
|
notifySelfChanged(doNotBatchUpdates);
|
|
5038
5112
|
eventHub.myPresence.notify(context.myPresence.current);
|
|
5039
5113
|
}
|
|
5040
|
-
if (storageUpdates.size > 0) {
|
|
5041
|
-
const
|
|
5042
|
-
eventHub.storage.notify(
|
|
5114
|
+
if (storageUpdates !== void 0 && storageUpdates.size > 0) {
|
|
5115
|
+
const updates2 = Array.from(storageUpdates.values());
|
|
5116
|
+
eventHub.storage.notify(updates2);
|
|
5043
5117
|
}
|
|
5044
5118
|
notifyStorageStatus();
|
|
5045
5119
|
});
|
|
@@ -5187,7 +5261,7 @@ function createRoom(options, config) {
|
|
|
5187
5261
|
}
|
|
5188
5262
|
context.myPresence.patch(patch);
|
|
5189
5263
|
if (context.activeBatch) {
|
|
5190
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5264
|
+
if (_optionalChain([options2, 'optionalAccess', _126 => _126.addToHistory])) {
|
|
5191
5265
|
context.activeBatch.reverseOps.unshift({
|
|
5192
5266
|
type: "presence",
|
|
5193
5267
|
data: oldValues
|
|
@@ -5197,7 +5271,7 @@ function createRoom(options, config) {
|
|
|
5197
5271
|
} else {
|
|
5198
5272
|
flushNowOrSoon();
|
|
5199
5273
|
batchUpdates(() => {
|
|
5200
|
-
if (_optionalChain([options2, 'optionalAccess',
|
|
5274
|
+
if (_optionalChain([options2, 'optionalAccess', _127 => _127.addToHistory])) {
|
|
5201
5275
|
addToUndoStack(
|
|
5202
5276
|
[{ type: "presence", data: oldValues }],
|
|
5203
5277
|
doNotBatchUpdates
|
|
@@ -5377,7 +5451,7 @@ function createRoom(options, config) {
|
|
|
5377
5451
|
const unacknowledgedOps = new Map(context.unacknowledgedOps);
|
|
5378
5452
|
createOrUpdateRootFromMessage(message, doNotBatchUpdates);
|
|
5379
5453
|
applyAndSendOps(unacknowledgedOps, doNotBatchUpdates);
|
|
5380
|
-
_optionalChain([_resolveStoragePromise, 'optionalCall',
|
|
5454
|
+
_optionalChain([_resolveStoragePromise, 'optionalCall', _128 => _128()]);
|
|
5381
5455
|
notifyStorageStatus();
|
|
5382
5456
|
eventHub.storageDidLoad.notify();
|
|
5383
5457
|
break;
|
|
@@ -5400,7 +5474,7 @@ function createRoom(options, config) {
|
|
|
5400
5474
|
if (process.env.NODE_ENV !== "production") {
|
|
5401
5475
|
const traces = /* @__PURE__ */ new Set();
|
|
5402
5476
|
for (const opId of message.opIds) {
|
|
5403
|
-
const trace = _optionalChain([context, 'access',
|
|
5477
|
+
const trace = _optionalChain([context, 'access', _129 => _129.opStackTraces, 'optionalAccess', _130 => _130.get, 'call', _131 => _131(opId)]);
|
|
5404
5478
|
if (trace) {
|
|
5405
5479
|
traces.add(trace);
|
|
5406
5480
|
}
|
|
@@ -5705,14 +5779,14 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5705
5779
|
comments: eventHub.comments.observable
|
|
5706
5780
|
};
|
|
5707
5781
|
const commentsApi = createCommentsApi(config.roomId, delegates.authenticate, {
|
|
5708
|
-
|
|
5782
|
+
baseUrl: config.baseUrl
|
|
5709
5783
|
});
|
|
5710
5784
|
return Object.defineProperty(
|
|
5711
5785
|
{
|
|
5712
5786
|
/* NOTE: Exposing __internal here only to allow testing implementation details in unit tests */
|
|
5713
5787
|
__internal: {
|
|
5714
5788
|
get presenceBuffer() {
|
|
5715
|
-
return deepClone(_nullishCoalesce(_optionalChain([context, 'access',
|
|
5789
|
+
return deepClone(_nullishCoalesce(_optionalChain([context, 'access', _132 => _132.buffer, 'access', _133 => _133.presenceUpdates, 'optionalAccess', _134 => _134.data]), () => ( null)));
|
|
5716
5790
|
},
|
|
5717
5791
|
// prettier-ignore
|
|
5718
5792
|
get undoStack() {
|
|
@@ -5738,7 +5812,10 @@ ${Array.from(traces).join("\n\n")}`
|
|
|
5738
5812
|
connect: () => managedSocket.connect(),
|
|
5739
5813
|
reconnect: () => managedSocket.reconnect(),
|
|
5740
5814
|
disconnect: () => managedSocket.disconnect(),
|
|
5741
|
-
destroy: () =>
|
|
5815
|
+
destroy: () => {
|
|
5816
|
+
uninstallBgTabSpy();
|
|
5817
|
+
managedSocket.destroy();
|
|
5818
|
+
},
|
|
5742
5819
|
// Presence
|
|
5743
5820
|
updatePresence,
|
|
5744
5821
|
updateYDoc,
|
|
@@ -5809,9 +5886,10 @@ function makeClassicSubscribeFn(events) {
|
|
|
5809
5886
|
return events.myPresence.subscribe(callback);
|
|
5810
5887
|
case "others": {
|
|
5811
5888
|
const cb = callback;
|
|
5812
|
-
return events.others.subscribe(
|
|
5813
|
-
|
|
5814
|
-
|
|
5889
|
+
return events.others.subscribe((event) => {
|
|
5890
|
+
const { others, ...internalEvent } = event;
|
|
5891
|
+
return cb(others, internalEvent);
|
|
5892
|
+
});
|
|
5815
5893
|
}
|
|
5816
5894
|
case "error":
|
|
5817
5895
|
return events.error.subscribe(callback);
|
|
@@ -5848,7 +5926,7 @@ function makeClassicSubscribeFn(events) {
|
|
|
5848
5926
|
}
|
|
5849
5927
|
if (isLiveNode(first)) {
|
|
5850
5928
|
const node = first;
|
|
5851
|
-
if (_optionalChain([options, 'optionalAccess',
|
|
5929
|
+
if (_optionalChain([options, 'optionalAccess', _135 => _135.isDeep])) {
|
|
5852
5930
|
const storageCallback = second;
|
|
5853
5931
|
return subscribeToLiveStructureDeeply(node, storageCallback);
|
|
5854
5932
|
} else {
|
|
@@ -5870,15 +5948,17 @@ function makeAuthDelegateForRoom(roomId, authManager) {
|
|
|
5870
5948
|
return authManager.getAuthValue("room:read", roomId);
|
|
5871
5949
|
};
|
|
5872
5950
|
}
|
|
5873
|
-
function makeCreateSocketDelegateForRoom(roomId,
|
|
5951
|
+
function makeCreateSocketDelegateForRoom(roomId, baseUrl, WebSocketPolyfill) {
|
|
5874
5952
|
return (authValue) => {
|
|
5875
5953
|
const ws = _nullishCoalesce(WebSocketPolyfill, () => ( (typeof WebSocket === "undefined" ? void 0 : WebSocket)));
|
|
5876
5954
|
if (ws === void 0) {
|
|
5877
5955
|
throw new StopRetrying(
|
|
5878
|
-
"To use Liveblocks client in a non-
|
|
5956
|
+
"To use Liveblocks client in a non-DOM environment, you need to provide a WebSocket polyfill."
|
|
5879
5957
|
);
|
|
5880
5958
|
}
|
|
5881
|
-
const url = new URL(
|
|
5959
|
+
const url = new URL(baseUrl);
|
|
5960
|
+
url.protocol = url.protocol === "http:" ? "ws" : "wss";
|
|
5961
|
+
url.pathname = "/v7";
|
|
5882
5962
|
url.searchParams.set("roomId", roomId);
|
|
5883
5963
|
if (authValue.type === "secret") {
|
|
5884
5964
|
url.searchParams.set("tok", authValue.token.raw);
|
|
@@ -5896,13 +5976,20 @@ function makeCreateSocketDelegateForRoom(roomId, liveblocksServer, WebSocketPoly
|
|
|
5896
5976
|
var MIN_THROTTLE = 16;
|
|
5897
5977
|
var MAX_THROTTLE = 1e3;
|
|
5898
5978
|
var DEFAULT_THROTTLE = 100;
|
|
5979
|
+
var MIN_BACKGROUND_KEEP_ALIVE_TIMEOUT = 6e4;
|
|
5899
5980
|
var MIN_LOST_CONNECTION_TIMEOUT = 200;
|
|
5900
5981
|
var RECOMMENDED_MIN_LOST_CONNECTION_TIMEOUT = 1e3;
|
|
5901
5982
|
var MAX_LOST_CONNECTION_TIMEOUT = 3e4;
|
|
5902
5983
|
var DEFAULT_LOST_CONNECTION_TIMEOUT = 5e3;
|
|
5903
|
-
function
|
|
5904
|
-
|
|
5905
|
-
|
|
5984
|
+
function getBaseUrlFromClientOptions(clientOptions) {
|
|
5985
|
+
if ("liveblocksServer" in clientOptions) {
|
|
5986
|
+
throw new Error("Client option no longer supported");
|
|
5987
|
+
}
|
|
5988
|
+
if (typeof clientOptions.baseUrl === "string" && clientOptions.baseUrl.startsWith("http")) {
|
|
5989
|
+
return clientOptions.baseUrl;
|
|
5990
|
+
} else {
|
|
5991
|
+
return DEFAULT_BASE_URL;
|
|
5992
|
+
}
|
|
5906
5993
|
}
|
|
5907
5994
|
function createClient(options) {
|
|
5908
5995
|
const clientOptions = options;
|
|
@@ -5910,6 +5997,9 @@ function createClient(options) {
|
|
|
5910
5997
|
const lostConnectionTimeout = getLostConnectionTimeout(
|
|
5911
5998
|
_nullishCoalesce(clientOptions.lostConnectionTimeout, () => ( DEFAULT_LOST_CONNECTION_TIMEOUT))
|
|
5912
5999
|
);
|
|
6000
|
+
const backgroundKeepAliveTimeout = getBackgroundKeepAliveTimeout(
|
|
6001
|
+
clientOptions.backgroundKeepAliveTimeout
|
|
6002
|
+
);
|
|
5913
6003
|
const authManager = createAuthManager(options);
|
|
5914
6004
|
const roomsById = /* @__PURE__ */ new Map();
|
|
5915
6005
|
function teardownRoom(room) {
|
|
@@ -5945,6 +6035,7 @@ function createClient(options) {
|
|
|
5945
6035
|
options2.initialPresence === null || options2.initialPresence === void 0,
|
|
5946
6036
|
"Please provide an initial presence value for the current user when entering the room."
|
|
5947
6037
|
);
|
|
6038
|
+
const baseUrl = getBaseUrlFromClientOptions(clientOptions);
|
|
5948
6039
|
const newRoom = createRoom(
|
|
5949
6040
|
{
|
|
5950
6041
|
initialPresence: _nullishCoalesce(options2.initialPresence, () => ( {})),
|
|
@@ -5954,18 +6045,19 @@ function createClient(options) {
|
|
|
5954
6045
|
roomId,
|
|
5955
6046
|
throttleDelay,
|
|
5956
6047
|
lostConnectionTimeout,
|
|
6048
|
+
backgroundKeepAliveTimeout,
|
|
5957
6049
|
polyfills: clientOptions.polyfills,
|
|
5958
6050
|
delegates: _nullishCoalesce(clientOptions.mockedDelegates, () => ( {
|
|
5959
6051
|
createSocket: makeCreateSocketDelegateForRoom(
|
|
5960
6052
|
roomId,
|
|
5961
|
-
|
|
5962
|
-
_optionalChain([clientOptions, 'access',
|
|
6053
|
+
baseUrl,
|
|
6054
|
+
_optionalChain([clientOptions, 'access', _136 => _136.polyfills, 'optionalAccess', _137 => _137.WebSocket])
|
|
5963
6055
|
),
|
|
5964
6056
|
authenticate: makeAuthDelegateForRoom(roomId, authManager)
|
|
5965
6057
|
})),
|
|
5966
6058
|
enableDebugLogging: clientOptions.enableDebugLogging,
|
|
5967
|
-
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess',
|
|
5968
|
-
|
|
6059
|
+
unstable_batchedUpdates: _optionalChain([options2, 'optionalAccess', _138 => _138.unstable_batchedUpdates]),
|
|
6060
|
+
baseUrl,
|
|
5969
6061
|
unstable_fallbackToHTTP: !!clientOptions.unstable_fallbackToHTTP
|
|
5970
6062
|
}
|
|
5971
6063
|
);
|
|
@@ -5979,7 +6071,7 @@ function createClient(options) {
|
|
|
5979
6071
|
const shouldConnect = _nullishCoalesce(_nullishCoalesce(options2.autoConnect, () => ( options2.shouldInitiallyConnect)), () => ( true));
|
|
5980
6072
|
if (shouldConnect) {
|
|
5981
6073
|
if (typeof atob === "undefined") {
|
|
5982
|
-
if (_optionalChain([clientOptions, 'access',
|
|
6074
|
+
if (_optionalChain([clientOptions, 'access', _139 => _139.polyfills, 'optionalAccess', _140 => _140.atob]) === void 0) {
|
|
5983
6075
|
throw new Error(
|
|
5984
6076
|
"You need to polyfill atob to use the client in your environment. Please follow the instructions at https://liveblocks.io/docs/errors/liveblocks-client/atob-polyfill"
|
|
5985
6077
|
);
|
|
@@ -5995,16 +6087,25 @@ function createClient(options) {
|
|
|
5995
6087
|
return room;
|
|
5996
6088
|
}
|
|
5997
6089
|
function getRoom(roomId) {
|
|
5998
|
-
const room = _optionalChain([roomsById, 'access',
|
|
6090
|
+
const room = _optionalChain([roomsById, 'access', _141 => _141.get, 'call', _142 => _142(roomId), 'optionalAccess', _143 => _143.room]);
|
|
5999
6091
|
return room ? room : null;
|
|
6000
6092
|
}
|
|
6001
6093
|
function forceLeave(roomId) {
|
|
6002
|
-
const unsubs = _nullishCoalesce(_optionalChain([roomsById, 'access',
|
|
6094
|
+
const unsubs = _nullishCoalesce(_optionalChain([roomsById, 'access', _144 => _144.get, 'call', _145 => _145(roomId), 'optionalAccess', _146 => _146.unsubs]), () => ( /* @__PURE__ */ new Set()));
|
|
6003
6095
|
for (const unsub of unsubs) {
|
|
6004
6096
|
unsub();
|
|
6005
6097
|
}
|
|
6006
6098
|
}
|
|
6099
|
+
function logout() {
|
|
6100
|
+
authManager.reset();
|
|
6101
|
+
for (const { room } of roomsById.values()) {
|
|
6102
|
+
if (!isIdle(room.getStatus())) {
|
|
6103
|
+
room.reconnect();
|
|
6104
|
+
}
|
|
6105
|
+
}
|
|
6106
|
+
}
|
|
6007
6107
|
return {
|
|
6108
|
+
logout,
|
|
6008
6109
|
// Old, deprecated APIs
|
|
6009
6110
|
enter,
|
|
6010
6111
|
getRoom,
|
|
@@ -6014,13 +6115,28 @@ function createClient(options) {
|
|
|
6014
6115
|
};
|
|
6015
6116
|
}
|
|
6016
6117
|
function checkBounds(option, value, min, max, recommendedMin) {
|
|
6017
|
-
if (typeof value !== "number" || value < min || value > max) {
|
|
6118
|
+
if (typeof value !== "number" || value < min || max === void 0 || value > max) {
|
|
6018
6119
|
throw new Error(
|
|
6019
|
-
`${option} should be
|
|
6120
|
+
max !== void 0 ? `${option} should be between ${_nullishCoalesce(recommendedMin, () => ( min))} and ${max}.` : `${option} should be at least ${_nullishCoalesce(recommendedMin, () => ( min))}.`
|
|
6020
6121
|
);
|
|
6021
6122
|
}
|
|
6022
6123
|
return value;
|
|
6023
6124
|
}
|
|
6125
|
+
function getBackgroundKeepAliveTimeout(value) {
|
|
6126
|
+
if (value === void 0)
|
|
6127
|
+
return void 0;
|
|
6128
|
+
if (typeof document === "undefined") {
|
|
6129
|
+
warn(
|
|
6130
|
+
"Setting backgroundKeepAliveTimeout won't have an effect in a non-DOM environment."
|
|
6131
|
+
);
|
|
6132
|
+
return void 0;
|
|
6133
|
+
}
|
|
6134
|
+
return checkBounds(
|
|
6135
|
+
"backgroundKeepAliveTimeout",
|
|
6136
|
+
value,
|
|
6137
|
+
MIN_BACKGROUND_KEEP_ALIVE_TIMEOUT
|
|
6138
|
+
);
|
|
6139
|
+
}
|
|
6024
6140
|
function getThrottle(value) {
|
|
6025
6141
|
return checkBounds("throttle", value, MIN_THROTTLE, MAX_THROTTLE);
|
|
6026
6142
|
}
|
|
@@ -6263,12 +6379,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6263
6379
|
}
|
|
6264
6380
|
const newState = Object.assign({}, state);
|
|
6265
6381
|
for (const key in update.updates) {
|
|
6266
|
-
if (_optionalChain([update, 'access',
|
|
6382
|
+
if (_optionalChain([update, 'access', _147 => _147.updates, 'access', _148 => _148[key], 'optionalAccess', _149 => _149.type]) === "update") {
|
|
6267
6383
|
const val = update.node.get(key);
|
|
6268
6384
|
if (val !== void 0) {
|
|
6269
6385
|
newState[key] = lsonToJson(val);
|
|
6270
6386
|
}
|
|
6271
|
-
} else if (_optionalChain([update, 'access',
|
|
6387
|
+
} else if (_optionalChain([update, 'access', _150 => _150.updates, 'access', _151 => _151[key], 'optionalAccess', _152 => _152.type]) === "delete") {
|
|
6272
6388
|
delete newState[key];
|
|
6273
6389
|
}
|
|
6274
6390
|
}
|
|
@@ -6329,12 +6445,12 @@ function legacy_patchImmutableNode(state, path, update) {
|
|
|
6329
6445
|
}
|
|
6330
6446
|
const newState = Object.assign({}, state);
|
|
6331
6447
|
for (const key in update.updates) {
|
|
6332
|
-
if (_optionalChain([update, 'access',
|
|
6448
|
+
if (_optionalChain([update, 'access', _153 => _153.updates, 'access', _154 => _154[key], 'optionalAccess', _155 => _155.type]) === "update") {
|
|
6333
6449
|
const value = update.node.get(key);
|
|
6334
6450
|
if (value !== void 0) {
|
|
6335
6451
|
newState[key] = lsonToJson(value);
|
|
6336
6452
|
}
|
|
6337
|
-
} else if (_optionalChain([update, 'access',
|
|
6453
|
+
} else if (_optionalChain([update, 'access', _156 => _156.updates, 'access', _157 => _157[key], 'optionalAccess', _158 => _158.type]) === "delete") {
|
|
6338
6454
|
delete newState[key];
|
|
6339
6455
|
}
|
|
6340
6456
|
}
|
|
@@ -6424,7 +6540,7 @@ function createCacheItem(key, asyncFunction, options) {
|
|
|
6424
6540
|
let previousState = { isLoading: false };
|
|
6425
6541
|
const eventSource2 = makeEventSource();
|
|
6426
6542
|
function notify() {
|
|
6427
|
-
const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
6543
|
+
const isEqual = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _159 => _159.isStateEqual]), () => ( isShallowEqual));
|
|
6428
6544
|
if (!isEqual(previousState, state)) {
|
|
6429
6545
|
previousState = state;
|
|
6430
6546
|
eventSource2.notify(state);
|
|
@@ -6492,7 +6608,7 @@ function createAsyncCache(asyncFunction, options) {
|
|
|
6492
6608
|
return create(key).get();
|
|
6493
6609
|
}
|
|
6494
6610
|
function getState(key) {
|
|
6495
|
-
return _optionalChain([cache, 'access',
|
|
6611
|
+
return _optionalChain([cache, 'access', _160 => _160.get, 'call', _161 => _161(key), 'optionalAccess', _162 => _162.getState, 'call', _163 => _163()]);
|
|
6496
6612
|
}
|
|
6497
6613
|
function revalidate(key) {
|
|
6498
6614
|
return create(key).revalidate();
|
|
@@ -6669,5 +6785,6 @@ detectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);
|
|
|
6669
6785
|
|
|
6670
6786
|
|
|
6671
6787
|
|
|
6672
|
-
|
|
6788
|
+
|
|
6789
|
+
exports.ClientMsgCode = ClientMsgCode; exports.CrdtType = CrdtType; exports.LiveList = LiveList; exports.LiveMap = LiveMap; exports.LiveObject = LiveObject; exports.OpCode = OpCode; exports.ServerMsgCode = ServerMsgCode; exports.WebsocketCloseCodes = WebsocketCloseCodes; exports.asPos = asPos; exports.assert = assert; exports.assertNever = assertNever; exports.b64decode = b64decode; exports.cloneLson = cloneLson; exports.console = fancy_console_exports; exports.createAsyncCache = createAsyncCache; exports.createClient = createClient; exports.createCommentsApi = createCommentsApi; exports.deprecate = deprecate; exports.deprecateIf = deprecateIf; exports.detectDupes = detectDupes; exports.errorIf = errorIf; exports.freeze = freeze; exports.isChildCrdt = isChildCrdt; exports.isJsonArray = isJsonArray; exports.isJsonObject = isJsonObject; exports.isJsonScalar = isJsonScalar; exports.isLiveNode = isLiveNode; exports.isPlainObject = isPlainObject; exports.isRootCrdt = isRootCrdt; exports.legacy_patchImmutableObject = legacy_patchImmutableObject; exports.lsonToJson = lsonToJson; exports.makeEventSource = makeEventSource; exports.makePoller = makePoller; exports.makePosition = makePosition; exports.nn = nn; exports.patchLiveObjectKey = patchLiveObjectKey; exports.shallow = shallow; exports.stringify = stringify; exports.throwUsageError = throwUsageError; exports.toPlainLson = toPlainLson; exports.tryParseJson = tryParseJson; exports.withTimeout = withTimeout;
|
|
6673
6790
|
//# sourceMappingURL=index.js.map
|