@liveblocks/react 2.1.1-test2 → 2.2.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.
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "2.1.1-test2";
3
+ var PKG_VERSION = "2.2.0";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -14,7 +14,13 @@ function ClientSideSuspense(props) {
14
14
  }
15
15
 
16
16
  // src/liveblocks.tsx
17
- import { createClient, kInternal, makePoller, raise } from "@liveblocks/core";
17
+ import {
18
+ createClient,
19
+ kInternal,
20
+ makePoller,
21
+ raise,
22
+ shallow
23
+ } from "@liveblocks/core";
18
24
  import { nanoid } from "nanoid";
19
25
  import React2, {
20
26
  createContext,
@@ -287,7 +293,8 @@ function useInboxNotifications_withClient(client) {
287
293
  store.subscribe,
288
294
  store.get,
289
295
  store.get,
290
- selectorFor_useInboxNotifications
296
+ selectorFor_useInboxNotifications,
297
+ shallow
291
298
  );
292
299
  }
293
300
  function useInboxNotificationsSuspense_withClient(client) {
@@ -308,7 +315,8 @@ function useInboxNotificationsSuspense_withClient(client) {
308
315
  store.subscribe,
309
316
  store.get,
310
317
  store.get,
311
- selectorFor_useInboxNotificationsSuspense
318
+ selectorFor_useInboxNotificationsSuspense,
319
+ shallow
312
320
  );
313
321
  }
314
322
  function useUnreadInboxNotificationsCount_withClient(client) {
@@ -318,7 +326,8 @@ function useUnreadInboxNotificationsCount_withClient(client) {
318
326
  store.subscribe,
319
327
  store.get,
320
328
  store.get,
321
- selectorFor_useUnreadInboxNotificationsCount
329
+ selectorFor_useUnreadInboxNotificationsCount,
330
+ shallow
322
331
  );
323
332
  }
324
333
  function useUnreadInboxNotificationsCountSuspense_withClient(client) {
@@ -336,7 +345,8 @@ function useUnreadInboxNotificationsCountSuspense_withClient(client) {
336
345
  store.subscribe,
337
346
  store.get,
338
347
  store.get,
339
- selectorFor_useUnreadInboxNotificationsCountSuspense
348
+ selectorFor_useUnreadInboxNotificationsCountSuspense,
349
+ shallow
340
350
  );
341
351
  }
342
352
  function useMarkInboxNotificationAsRead_withClient(client) {
@@ -550,12 +560,15 @@ function useRoomInfoSuspense_withClient(client, roomId) {
550
560
  };
551
561
  }
552
562
  function createSharedContext(client) {
563
+ const useClient2 = () => client;
553
564
  return {
554
565
  classic: {
566
+ useClient: useClient2,
555
567
  useUser: (userId) => useUser_withClient(client, userId),
556
568
  useRoomInfo: (roomId) => useRoomInfo_withClient(client, roomId)
557
569
  },
558
570
  suspense: {
571
+ useClient: useClient2,
559
572
  useUser: (userId) => useUserSuspense_withClient(client, userId),
560
573
  useRoomInfo: (roomId) => useRoomInfoSuspense_withClient(client, roomId)
561
574
  }
@@ -677,6 +690,22 @@ var EditThreadMetadataError = class extends Error {
677
690
  this.name = "EditThreadMetadataError";
678
691
  }
679
692
  };
693
+ var MarkThreadAsResolvedError = class extends Error {
694
+ constructor(cause, context) {
695
+ super("Mark thread as resolved failed.");
696
+ this.cause = cause;
697
+ this.context = context;
698
+ this.name = "MarkThreadAsResolvedError";
699
+ }
700
+ };
701
+ var MarkThreadAsUnresolvedError = class extends Error {
702
+ constructor(cause, context) {
703
+ super("Mark thread as unresolved failed.");
704
+ this.cause = cause;
705
+ this.context = context;
706
+ this.name = "MarkThreadAsUnresolvedError";
707
+ }
708
+ };
680
709
  var CreateCommentError = class extends Error {
681
710
  constructor(cause, context) {
682
711
  super("Create comment failed.");
@@ -777,7 +806,7 @@ var assertMetadataValueIsString = (value) => {
777
806
  };
778
807
 
779
808
  // src/room.tsx
780
- import { shallow } from "@liveblocks/client";
809
+ import { shallow as shallow2 } from "@liveblocks/client";
781
810
  import {
782
811
  addReaction,
783
812
  CommentsApiError,
@@ -879,6 +908,7 @@ function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
879
908
  }
880
909
 
881
910
  // src/room.tsx
911
+ var SMOOTH_DELAY = 1e3;
882
912
  var noop2 = () => {
883
913
  };
884
914
  var identity = (x) => x;
@@ -1167,6 +1197,8 @@ function makeRoomContextBundle(client) {
1167
1197
  useCreateThread,
1168
1198
  useDeleteThread,
1169
1199
  useEditThreadMetadata,
1200
+ useMarkThreadAsResolved,
1201
+ useMarkThreadAsUnresolved,
1170
1202
  useCreateComment,
1171
1203
  useEditComment,
1172
1204
  useDeleteComment,
@@ -1208,6 +1240,8 @@ function makeRoomContextBundle(client) {
1208
1240
  useCreateThread,
1209
1241
  useDeleteThread,
1210
1242
  useEditThreadMetadata,
1243
+ useMarkThreadAsResolved,
1244
+ useMarkThreadAsUnresolved,
1211
1245
  useCreateComment,
1212
1246
  useEditComment,
1213
1247
  useDeleteComment,
@@ -1308,6 +1342,7 @@ function RoomProviderInner(props) {
1308
1342
  switch (message.type) {
1309
1343
  case ServerMsgCode.COMMENT_EDITED:
1310
1344
  case ServerMsgCode.THREAD_METADATA_UPDATED:
1345
+ case ServerMsgCode.THREAD_UPDATED:
1311
1346
  case ServerMsgCode.COMMENT_REACTION_ADDED:
1312
1347
  case ServerMsgCode.COMMENT_REACTION_REMOVED:
1313
1348
  case ServerMsgCode.COMMENT_DELETED:
@@ -1366,13 +1401,42 @@ function useStatus() {
1366
1401
  const getServerSnapshot = room.getStatus;
1367
1402
  return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1368
1403
  }
1369
- function useStorageStatus() {
1404
+ function useStorageStatus(options) {
1405
+ const smooth = useInitial(options?.smooth ?? false);
1406
+ if (smooth) {
1407
+ return useStorageStatusSmooth();
1408
+ } else {
1409
+ return useStorageStatusImmediate();
1410
+ }
1411
+ }
1412
+ function useStorageStatusImmediate() {
1370
1413
  const room = useRoom();
1371
1414
  const subscribe = room.events.storageStatus.subscribe;
1372
1415
  const getSnapshot = room.getStorageStatus;
1373
1416
  const getServerSnapshot = room.getStorageStatus;
1374
1417
  return useSyncExternalStore2(subscribe, getSnapshot, getServerSnapshot);
1375
1418
  }
1419
+ function useStorageStatusSmooth() {
1420
+ const room = useRoom();
1421
+ const [status, setStatus] = React4.useState(room.getStorageStatus);
1422
+ const oldStatus = useLatest(room.getStorageStatus());
1423
+ React4.useEffect(() => {
1424
+ let timeoutId;
1425
+ const unsub = room.events.storageStatus.subscribe((newStatus) => {
1426
+ if (oldStatus.current === "synchronizing" && newStatus === "synchronized") {
1427
+ timeoutId = setTimeout(() => setStatus(newStatus), SMOOTH_DELAY);
1428
+ } else {
1429
+ clearTimeout(timeoutId);
1430
+ setStatus(newStatus);
1431
+ }
1432
+ });
1433
+ return () => {
1434
+ clearTimeout(timeoutId);
1435
+ unsub();
1436
+ };
1437
+ }, [room, oldStatus]);
1438
+ return status;
1439
+ }
1376
1440
  function useBatch() {
1377
1441
  return useRoom().batch;
1378
1442
  }
@@ -1502,7 +1566,7 @@ function useOthersMapped(itemSelector, itemIsEqual) {
1502
1566
  return useOthers(wrappedSelector, wrappedIsEqual);
1503
1567
  }
1504
1568
  function useOthersConnectionIds() {
1505
- return useOthers(selectorFor_useOthersConnectionIds, shallow);
1569
+ return useOthers(selectorFor_useOthersConnectionIds, shallow2);
1506
1570
  }
1507
1571
  var NOT_FOUND = Symbol();
1508
1572
  function useOther(connectionId, selector, isEqual) {
@@ -1667,7 +1731,8 @@ function useCreateThread() {
1667
1731
  updatedAt: createdAt,
1668
1732
  roomId: room.id,
1669
1733
  metadata,
1670
- comments: [newComment]
1734
+ comments: [newComment],
1735
+ resolved: false
1671
1736
  };
1672
1737
  const optimisticUpdateId = nanoid3();
1673
1738
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -2212,6 +2277,138 @@ function useMarkThreadAsRead() {
2212
2277
  [client, room]
2213
2278
  );
2214
2279
  }
2280
+ function useMarkThreadAsResolved() {
2281
+ const client = useClient();
2282
+ const room = useRoom();
2283
+ return React4.useCallback(
2284
+ (threadId) => {
2285
+ const optimisticUpdateId = nanoid3();
2286
+ const updatedAt = /* @__PURE__ */ new Date();
2287
+ const { store, onMutationFailure } = getExtrasForClient2(client);
2288
+ store.pushOptimisticUpdate({
2289
+ type: "mark-thread-as-resolved",
2290
+ id: optimisticUpdateId,
2291
+ threadId,
2292
+ updatedAt
2293
+ });
2294
+ const commentsAPI = room[kInternal2].comments;
2295
+ commentsAPI.markThreadAsResolved({ threadId }).then(
2296
+ () => {
2297
+ store.set((state) => {
2298
+ const existingThread = state.threads[threadId];
2299
+ const updatedOptimisticUpdates = state.optimisticUpdates.filter(
2300
+ (update) => update.id !== optimisticUpdateId
2301
+ );
2302
+ if (existingThread === void 0) {
2303
+ return {
2304
+ ...state,
2305
+ optimisticUpdates: updatedOptimisticUpdates
2306
+ };
2307
+ }
2308
+ if (existingThread.deletedAt !== void 0) {
2309
+ return {
2310
+ ...state,
2311
+ optimisticUpdates: updatedOptimisticUpdates
2312
+ };
2313
+ }
2314
+ if (existingThread.updatedAt && existingThread.updatedAt > updatedAt) {
2315
+ return {
2316
+ ...state,
2317
+ optimisticUpdates: updatedOptimisticUpdates
2318
+ };
2319
+ }
2320
+ return {
2321
+ ...state,
2322
+ threads: {
2323
+ ...state.threads,
2324
+ [threadId]: {
2325
+ ...existingThread,
2326
+ resolved: true
2327
+ }
2328
+ },
2329
+ optimisticUpdates: updatedOptimisticUpdates
2330
+ };
2331
+ });
2332
+ },
2333
+ (err) => onMutationFailure(
2334
+ err,
2335
+ optimisticUpdateId,
2336
+ (error) => new MarkThreadAsResolvedError(error, {
2337
+ roomId: room.id,
2338
+ threadId
2339
+ })
2340
+ )
2341
+ );
2342
+ },
2343
+ [client, room]
2344
+ );
2345
+ }
2346
+ function useMarkThreadAsUnresolved() {
2347
+ const client = useClient();
2348
+ const room = useRoom();
2349
+ return React4.useCallback(
2350
+ (threadId) => {
2351
+ const optimisticUpdateId = nanoid3();
2352
+ const updatedAt = /* @__PURE__ */ new Date();
2353
+ const { store, onMutationFailure } = getExtrasForClient2(client);
2354
+ store.pushOptimisticUpdate({
2355
+ type: "mark-thread-as-unresolved",
2356
+ id: optimisticUpdateId,
2357
+ threadId,
2358
+ updatedAt
2359
+ });
2360
+ const commentsAPI = room[kInternal2].comments;
2361
+ commentsAPI.markThreadAsUnresolved({ threadId }).then(
2362
+ () => {
2363
+ store.set((state) => {
2364
+ const existingThread = state.threads[threadId];
2365
+ const updatedOptimisticUpdates = state.optimisticUpdates.filter(
2366
+ (update) => update.id !== optimisticUpdateId
2367
+ );
2368
+ if (existingThread === void 0) {
2369
+ return {
2370
+ ...state,
2371
+ optimisticUpdates: updatedOptimisticUpdates
2372
+ };
2373
+ }
2374
+ if (existingThread.deletedAt !== void 0) {
2375
+ return {
2376
+ ...state,
2377
+ optimisticUpdates: updatedOptimisticUpdates
2378
+ };
2379
+ }
2380
+ if (existingThread.updatedAt && existingThread.updatedAt > updatedAt) {
2381
+ return {
2382
+ ...state,
2383
+ optimisticUpdates: updatedOptimisticUpdates
2384
+ };
2385
+ }
2386
+ return {
2387
+ ...state,
2388
+ threads: {
2389
+ ...state.threads,
2390
+ [threadId]: {
2391
+ ...existingThread,
2392
+ resolved: false
2393
+ }
2394
+ },
2395
+ optimisticUpdates: updatedOptimisticUpdates
2396
+ };
2397
+ });
2398
+ },
2399
+ (err) => onMutationFailure(
2400
+ err,
2401
+ optimisticUpdateId,
2402
+ (error) => new MarkThreadAsUnresolvedError(error, {
2403
+ roomId: room.id,
2404
+ threadId
2405
+ })
2406
+ )
2407
+ );
2408
+ },
2409
+ [client, room]
2410
+ );
2411
+ }
2215
2412
  function useThreadSubscription(threadId) {
2216
2413
  const client = useClient();
2217
2414
  const { store } = getExtrasForClient2(client);
@@ -2363,13 +2560,9 @@ function useStorageSuspense(selector, isEqual) {
2363
2560
  isEqual
2364
2561
  );
2365
2562
  }
2366
- function useStorageStatusSuspense() {
2563
+ function useStorageStatusSuspense(options) {
2367
2564
  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);
2565
+ return useStorageStatus(options);
2373
2566
  }
2374
2567
  function useThreadsSuspense(options = {
2375
2568
  query: { metadata: {} }
@@ -2527,6 +2720,8 @@ export {
2527
2720
  useDeleteComment,
2528
2721
  useRemoveReaction,
2529
2722
  useMarkThreadAsRead,
2723
+ useMarkThreadAsResolved,
2724
+ useMarkThreadAsUnresolved,
2530
2725
  useThreadSubscription,
2531
2726
  useRoomNotificationSettings,
2532
2727
  useUpdateRoomNotificationSettings,
@@ -2559,4 +2754,4 @@ export {
2559
2754
  _useStorageRoot,
2560
2755
  _useUpdateMyPresence
2561
2756
  };
2562
- //# sourceMappingURL=chunk-PAHCU5NM.mjs.map
2757
+ //# sourceMappingURL=chunk-SMD5PEIG.mjs.map