@liveblocks/react 2.0.4 → 2.1.0
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/{chunk-V4AOLMSL.mjs → chunk-D4UC2JLP.mjs} +101 -51
- package/dist/chunk-D4UC2JLP.mjs.map +1 -0
- package/dist/{chunk-KR6TDG2X.js → chunk-VE5TWD3X.js} +99 -49
- package/dist/chunk-VE5TWD3X.js.map +1 -0
- package/dist/index.d.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -5
- package/dist/index.mjs.map +1 -1
- package/dist/{suspense-AE6e9SjD.d.mts → suspense-qP2VFyHd.d.mts} +741 -49
- package/dist/{suspense-AE6e9SjD.d.ts → suspense-qP2VFyHd.d.ts} +741 -49
- package/dist/suspense.d.mts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +5 -3
- package/dist/suspense.js.map +1 -1
- package/dist/suspense.mjs +7 -5
- package/dist/suspense.mjs.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-KR6TDG2X.js.map +0 -1
- package/dist/chunk-V4AOLMSL.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/react";
|
|
3
|
-
var PKG_VERSION = "2.0
|
|
3
|
+
var PKG_VERSION = "2.1.0";
|
|
4
4
|
var PKG_FORMAT = "esm";
|
|
5
5
|
|
|
6
6
|
// src/ClientSideSuspense.tsx
|
|
@@ -79,12 +79,14 @@ function useInitialUnlessFunction(latestValue) {
|
|
|
79
79
|
|
|
80
80
|
// src/liveblocks.tsx
|
|
81
81
|
var ClientContext = createContext(null);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
function missingUserError(userId) {
|
|
83
|
+
return new Error(`resolveUsers didn't return anything for user '${userId}'`);
|
|
84
|
+
}
|
|
85
|
+
function missingRoomInfoError(roomId) {
|
|
86
|
+
return new Error(
|
|
87
|
+
`resolveRoomsInfo didn't return anything for room '${roomId}'`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
88
90
|
var _extras = /* @__PURE__ */ new WeakMap();
|
|
89
91
|
var _bundles = /* @__PURE__ */ new WeakMap();
|
|
90
92
|
var POLLING_INTERVAL = 60 * 1e3;
|
|
@@ -166,7 +168,7 @@ function makeExtrasForClient(client) {
|
|
|
166
168
|
const internals = client[kInternal];
|
|
167
169
|
const store = internals.cacheStore;
|
|
168
170
|
const notifications = internals.notifications;
|
|
169
|
-
let
|
|
171
|
+
let fetchInboxNotifications$ = null;
|
|
170
172
|
let lastRequestedAt;
|
|
171
173
|
const poller = makePoller(
|
|
172
174
|
() => notifications.getInboxNotifications({ since: lastRequestedAt }).then(
|
|
@@ -185,15 +187,15 @@ function makeExtrasForClient(client) {
|
|
|
185
187
|
)
|
|
186
188
|
);
|
|
187
189
|
async function fetchInboxNotifications({ retryCount } = { retryCount: 0 }) {
|
|
188
|
-
if (
|
|
189
|
-
return
|
|
190
|
+
if (fetchInboxNotifications$ !== null) {
|
|
191
|
+
return fetchInboxNotifications$;
|
|
190
192
|
}
|
|
191
193
|
store.setQueryState(INBOX_NOTIFICATIONS_QUERY, {
|
|
192
194
|
isLoading: true
|
|
193
195
|
});
|
|
194
196
|
try {
|
|
195
|
-
|
|
196
|
-
const result = await
|
|
197
|
+
fetchInboxNotifications$ = notifications.getInboxNotifications();
|
|
198
|
+
const result = await fetchInboxNotifications$;
|
|
197
199
|
store.updateThreadsAndNotifications(
|
|
198
200
|
result.threads,
|
|
199
201
|
result.inboxNotifications,
|
|
@@ -206,7 +208,7 @@ function makeExtrasForClient(client) {
|
|
|
206
208
|
}
|
|
207
209
|
poller.start(POLLING_INTERVAL);
|
|
208
210
|
} catch (er) {
|
|
209
|
-
|
|
211
|
+
fetchInboxNotifications$ = null;
|
|
210
212
|
retryError(() => {
|
|
211
213
|
void fetchInboxNotifications({
|
|
212
214
|
retryCount: retryCount + 1
|
|
@@ -469,7 +471,7 @@ function useUser_withClient(client, userId) {
|
|
|
469
471
|
isLoading: state.isLoading,
|
|
470
472
|
user: state.data,
|
|
471
473
|
// Return an error if `undefined` was returned by `resolveUsers` for this user ID
|
|
472
|
-
error: !state.isLoading && !state.data && !state.error ? missingUserError : state.error
|
|
474
|
+
error: !state.isLoading && !state.data && !state.error ? missingUserError(userId) : state.error
|
|
473
475
|
} : { isLoading: true };
|
|
474
476
|
}
|
|
475
477
|
function useUserSuspense_withClient(client, userId) {
|
|
@@ -486,7 +488,7 @@ function useUserSuspense_withClient(client, userId) {
|
|
|
486
488
|
throw userState.error;
|
|
487
489
|
}
|
|
488
490
|
if (!userState.data) {
|
|
489
|
-
throw missingUserError;
|
|
491
|
+
throw missingUserError(userId);
|
|
490
492
|
}
|
|
491
493
|
const state = useSyncExternalStore(
|
|
492
494
|
usersStore.subscribe,
|
|
@@ -517,7 +519,7 @@ function useRoomInfo_withClient(client, roomId) {
|
|
|
517
519
|
isLoading: state.isLoading,
|
|
518
520
|
info: state.data,
|
|
519
521
|
// Return an error if `undefined` was returned by `resolveRoomsInfo` for this room ID
|
|
520
|
-
error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError : state.error
|
|
522
|
+
error: !state.isLoading && !state.data && !state.error ? missingRoomInfoError(roomId) : state.error
|
|
521
523
|
} : { isLoading: true };
|
|
522
524
|
}
|
|
523
525
|
function useRoomInfoSuspense_withClient(client, roomId) {
|
|
@@ -534,7 +536,7 @@ function useRoomInfoSuspense_withClient(client, roomId) {
|
|
|
534
536
|
throw roomInfoState.error;
|
|
535
537
|
}
|
|
536
538
|
if (!roomInfoState.data) {
|
|
537
|
-
throw missingRoomInfoError;
|
|
539
|
+
throw missingRoomInfoError(roomId);
|
|
538
540
|
}
|
|
539
541
|
const state = useSyncExternalStore(
|
|
540
542
|
roomsInfoStore.subscribe,
|
|
@@ -646,9 +648,9 @@ function useRoomInfo(roomId) {
|
|
|
646
648
|
function useRoomInfoSuspense(roomId) {
|
|
647
649
|
return useRoomInfoSuspense_withClient(useClient(), roomId);
|
|
648
650
|
}
|
|
649
|
-
var
|
|
650
|
-
var
|
|
651
|
-
var
|
|
651
|
+
var _useInboxNotificationThread = useInboxNotificationThread;
|
|
652
|
+
var _useUser = useUser;
|
|
653
|
+
var _useUserSuspense = useUserSuspense;
|
|
652
654
|
|
|
653
655
|
// src/comments/errors.ts
|
|
654
656
|
var CreateThreadError = class extends Error {
|
|
@@ -820,6 +822,33 @@ function selectNotificationSettings(roomId, state) {
|
|
|
820
822
|
return nn(notificationSettings[roomId]);
|
|
821
823
|
}
|
|
822
824
|
|
|
825
|
+
// src/lib/use-polyfill.ts
|
|
826
|
+
var use = (
|
|
827
|
+
// React.use ||
|
|
828
|
+
(promise) => {
|
|
829
|
+
if (promise.status === "pending") {
|
|
830
|
+
throw promise;
|
|
831
|
+
} else if (promise.status === "fulfilled") {
|
|
832
|
+
return promise.value;
|
|
833
|
+
} else if (promise.status === "rejected") {
|
|
834
|
+
throw promise.reason;
|
|
835
|
+
} else {
|
|
836
|
+
promise.status = "pending";
|
|
837
|
+
promise.then(
|
|
838
|
+
(v) => {
|
|
839
|
+
promise.status = "fulfilled";
|
|
840
|
+
promise.value = v;
|
|
841
|
+
},
|
|
842
|
+
(e) => {
|
|
843
|
+
promise.status = "rejected";
|
|
844
|
+
promise.reason = e;
|
|
845
|
+
}
|
|
846
|
+
);
|
|
847
|
+
throw promise;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
);
|
|
851
|
+
|
|
823
852
|
// src/use-scroll-to-comment-on-load-effect.ts
|
|
824
853
|
import * as React3 from "react";
|
|
825
854
|
function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
|
|
@@ -1112,6 +1141,7 @@ function makeRoomContextBundle(client) {
|
|
|
1112
1141
|
RoomProvider: RoomProvider_withImplicitLiveblocksProvider,
|
|
1113
1142
|
useRoom,
|
|
1114
1143
|
useStatus,
|
|
1144
|
+
useStorageStatus,
|
|
1115
1145
|
useBatch,
|
|
1116
1146
|
useBroadcastEvent,
|
|
1117
1147
|
useOthersListener,
|
|
@@ -1152,6 +1182,7 @@ function makeRoomContextBundle(client) {
|
|
|
1152
1182
|
RoomProvider: RoomProvider_withImplicitLiveblocksProvider,
|
|
1153
1183
|
useRoom,
|
|
1154
1184
|
useStatus,
|
|
1185
|
+
useStorageStatus: useStorageStatusSuspense,
|
|
1155
1186
|
useBatch,
|
|
1156
1187
|
useBroadcastEvent,
|
|
1157
1188
|
useOthersListener,
|
|
@@ -1335,6 +1366,13 @@ function useStatus() {
|
|
|
1335
1366
|
const getServerSnapshot = room.getStatus;
|
|
1336
1367
|
return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
|
|
1337
1368
|
}
|
|
1369
|
+
function useStorageStatus() {
|
|
1370
|
+
const room = useRoom();
|
|
1371
|
+
const subscribe = room.events.storageStatus.subscribe;
|
|
1372
|
+
const getSnapshot = room.getStorageStatus;
|
|
1373
|
+
const getServerSnapshot = room.getStorageStatus;
|
|
1374
|
+
return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
|
|
1375
|
+
}
|
|
1338
1376
|
function useBatch() {
|
|
1339
1377
|
return useRoom().batch;
|
|
1340
1378
|
}
|
|
@@ -1677,6 +1715,11 @@ function useDeleteThread() {
|
|
|
1677
1715
|
(threadId) => {
|
|
1678
1716
|
const optimisticUpdateId = nanoid3();
|
|
1679
1717
|
const { store, onMutationFailure } = getExtrasForClient2(client);
|
|
1718
|
+
const thread = store.get().threads[threadId];
|
|
1719
|
+
const userId = getCurrentUserId(room);
|
|
1720
|
+
if (thread?.comments?.[0]?.userId !== userId) {
|
|
1721
|
+
throw new Error("Only the thread creator can delete the thread");
|
|
1722
|
+
}
|
|
1680
1723
|
store.pushOptimisticUpdate({
|
|
1681
1724
|
type: "delete-thread",
|
|
1682
1725
|
id: optimisticUpdateId,
|
|
@@ -2277,60 +2320,57 @@ function ensureNotServerSide() {
|
|
|
2277
2320
|
);
|
|
2278
2321
|
}
|
|
2279
2322
|
}
|
|
2280
|
-
function
|
|
2281
|
-
const room = useRoom();
|
|
2282
|
-
if (room.getSelf() !== null) {
|
|
2283
|
-
return;
|
|
2284
|
-
}
|
|
2323
|
+
function useSuspendUntilPresenceReady() {
|
|
2285
2324
|
ensureNotServerSide();
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
room.events.status.subscribeOnce(() => res());
|
|
2289
|
-
});
|
|
2325
|
+
const room = useRoom();
|
|
2326
|
+
use(room.waitUntilPresenceReady());
|
|
2290
2327
|
}
|
|
2291
2328
|
function useSelfSuspense(selector, isEqual) {
|
|
2292
|
-
|
|
2329
|
+
useSuspendUntilPresenceReady();
|
|
2293
2330
|
return useSelf(
|
|
2294
2331
|
selector,
|
|
2295
2332
|
isEqual
|
|
2296
2333
|
);
|
|
2297
2334
|
}
|
|
2298
2335
|
function useOthersSuspense(selector, isEqual) {
|
|
2299
|
-
|
|
2336
|
+
useSuspendUntilPresenceReady();
|
|
2300
2337
|
return useOthers(
|
|
2301
2338
|
selector,
|
|
2302
2339
|
isEqual
|
|
2303
2340
|
);
|
|
2304
2341
|
}
|
|
2305
2342
|
function useOthersConnectionIdsSuspense() {
|
|
2306
|
-
|
|
2343
|
+
useSuspendUntilPresenceReady();
|
|
2307
2344
|
return useOthersConnectionIds();
|
|
2308
2345
|
}
|
|
2309
2346
|
function useOthersMappedSuspense(itemSelector, itemIsEqual) {
|
|
2310
|
-
|
|
2347
|
+
useSuspendUntilPresenceReady();
|
|
2311
2348
|
return useOthersMapped(itemSelector, itemIsEqual);
|
|
2312
2349
|
}
|
|
2313
2350
|
function useOtherSuspense(connectionId, selector, isEqual) {
|
|
2314
|
-
|
|
2351
|
+
useSuspendUntilPresenceReady();
|
|
2315
2352
|
return useOther(connectionId, selector, isEqual);
|
|
2316
2353
|
}
|
|
2317
|
-
function
|
|
2318
|
-
const room = useRoom();
|
|
2319
|
-
if (room.getStorageSnapshot() !== null) {
|
|
2320
|
-
return;
|
|
2321
|
-
}
|
|
2354
|
+
function useSuspendUntilStorageReady() {
|
|
2322
2355
|
ensureNotServerSide();
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
});
|
|
2356
|
+
const room = useRoom();
|
|
2357
|
+
use(room.waitUntilStorageReady());
|
|
2326
2358
|
}
|
|
2327
2359
|
function useStorageSuspense(selector, isEqual) {
|
|
2328
|
-
|
|
2360
|
+
useSuspendUntilStorageReady();
|
|
2329
2361
|
return useStorage(
|
|
2330
2362
|
selector,
|
|
2331
2363
|
isEqual
|
|
2332
2364
|
);
|
|
2333
2365
|
}
|
|
2366
|
+
function useStorageStatusSuspense() {
|
|
2367
|
+
useSuspendUntilStorageReady();
|
|
2368
|
+
const room = useRoom();
|
|
2369
|
+
const subscribe = room.events.storageStatus.subscribe;
|
|
2370
|
+
const getSnapshot = room.getStorageStatus;
|
|
2371
|
+
const getServerSnapshot = room.getStorageStatus;
|
|
2372
|
+
return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
|
|
2373
|
+
}
|
|
2334
2374
|
function useThreadsSuspense(options = {
|
|
2335
2375
|
query: { metadata: {} }
|
|
2336
2376
|
}) {
|
|
@@ -2429,13 +2469,21 @@ var _useOthersMappedSuspense = useOthersMappedSuspense;
|
|
|
2429
2469
|
var _useThreads = useThreads;
|
|
2430
2470
|
var _useThreadsSuspense = useThreadsSuspense;
|
|
2431
2471
|
var _useOther = useOther;
|
|
2432
|
-
|
|
2472
|
+
function _useOthers(...args) {
|
|
2473
|
+
return useOthers(...args);
|
|
2474
|
+
}
|
|
2433
2475
|
var _useOtherSuspense = useOtherSuspense;
|
|
2434
|
-
|
|
2476
|
+
function _useOthersSuspense(...args) {
|
|
2477
|
+
return useOthersSuspense(...args);
|
|
2478
|
+
}
|
|
2435
2479
|
var _useStorage = useStorage;
|
|
2436
2480
|
var _useStorageSuspense = useStorageSuspense;
|
|
2437
|
-
|
|
2438
|
-
|
|
2481
|
+
function _useSelf(...args) {
|
|
2482
|
+
return useSelf(...args);
|
|
2483
|
+
}
|
|
2484
|
+
function _useSelfSuspense(...args) {
|
|
2485
|
+
return useSelfSuspense(...args);
|
|
2486
|
+
}
|
|
2439
2487
|
var _useStorageRoot = useStorageRoot;
|
|
2440
2488
|
var _useUpdateMyPresence = useUpdateMyPresence;
|
|
2441
2489
|
|
|
@@ -2456,13 +2504,14 @@ export {
|
|
|
2456
2504
|
useUnreadInboxNotificationsCountSuspense,
|
|
2457
2505
|
useRoomInfo,
|
|
2458
2506
|
useRoomInfoSuspense,
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2507
|
+
_useInboxNotificationThread,
|
|
2508
|
+
_useUser,
|
|
2509
|
+
_useUserSuspense,
|
|
2462
2510
|
CreateThreadError,
|
|
2463
2511
|
selectedThreads,
|
|
2464
2512
|
RoomContext,
|
|
2465
2513
|
useStatus,
|
|
2514
|
+
useStorageStatus,
|
|
2466
2515
|
useBatch,
|
|
2467
2516
|
useLostConnectionListener,
|
|
2468
2517
|
useErrorListener,
|
|
@@ -2482,6 +2531,7 @@ export {
|
|
|
2482
2531
|
useRoomNotificationSettings,
|
|
2483
2532
|
useUpdateRoomNotificationSettings,
|
|
2484
2533
|
useOthersConnectionIdsSuspense,
|
|
2534
|
+
useStorageStatusSuspense,
|
|
2485
2535
|
createRoomContext,
|
|
2486
2536
|
_RoomProvider,
|
|
2487
2537
|
_useBroadcastEvent,
|
|
@@ -2509,4 +2559,4 @@ export {
|
|
|
2509
2559
|
_useStorageRoot,
|
|
2510
2560
|
_useUpdateMyPresence
|
|
2511
2561
|
};
|
|
2512
|
-
//# sourceMappingURL=chunk-
|
|
2562
|
+
//# sourceMappingURL=chunk-D4UC2JLP.mjs.map
|