@liveblocks/react 2.7.1 → 2.8.0-beta1

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.7.1";
3
+ var PKG_VERSION = "2.8.0-beta1";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -899,7 +899,8 @@ function applyDeleteComment(thread, commentId, deletedAt) {
899
899
  (comment) => comment.id === commentId ? {
900
900
  ...comment,
901
901
  deletedAt,
902
- body: void 0
902
+ body: void 0,
903
+ attachments: []
903
904
  } : comment
904
905
  );
905
906
  if (!updatedComments.some((comment) => comment.deletedAt === void 0)) {
@@ -1911,6 +1912,7 @@ var UpdateNotificationSettingsError = class extends Error {
1911
1912
  // src/room.tsx
1912
1913
  import { shallow as shallow4 } from "@liveblocks/client";
1913
1914
  import {
1915
+ assert as assert2,
1914
1916
  CommentsApiError,
1915
1917
  console as console3,
1916
1918
  createCommentId,
@@ -2273,6 +2275,7 @@ function makeRoomContextBundle(client) {
2273
2275
  useRemoveReaction,
2274
2276
  useMarkThreadAsRead,
2275
2277
  useThreadSubscription,
2278
+ useAttachmentUrl,
2276
2279
  useHistoryVersions,
2277
2280
  useHistoryVersionData,
2278
2281
  useRoomNotificationSettings,
@@ -2318,6 +2321,7 @@ function makeRoomContextBundle(client) {
2318
2321
  useRemoveReaction,
2319
2322
  useMarkThreadAsRead,
2320
2323
  useThreadSubscription,
2324
+ useAttachmentUrl: useAttachmentUrlSuspense,
2321
2325
  // TODO: useHistoryVersionData: useHistoryVersionDataSuspense,
2322
2326
  useHistoryVersions: useHistoryVersionsSuspense,
2323
2327
  useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
@@ -2784,6 +2788,7 @@ function useCreateThread() {
2784
2788
  (options) => {
2785
2789
  const body = options.body;
2786
2790
  const metadata = options.metadata ?? {};
2791
+ const attachments = options.attachments;
2787
2792
  const threadId = createThreadId();
2788
2793
  const commentId = createCommentId();
2789
2794
  const createdAt = /* @__PURE__ */ new Date();
@@ -2795,7 +2800,8 @@ function useCreateThread() {
2795
2800
  type: "comment",
2796
2801
  userId: getCurrentUserId(room),
2797
2802
  body,
2798
- reactions: []
2803
+ reactions: [],
2804
+ attachments: attachments ?? []
2799
2805
  };
2800
2806
  const newThread = {
2801
2807
  id: threadId,
@@ -2813,7 +2819,8 @@ function useCreateThread() {
2813
2819
  thread: newThread,
2814
2820
  roomId: room.id
2815
2821
  });
2816
- room.createThread({ threadId, commentId, body, metadata }).then(
2822
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2823
+ room.createThread({ threadId, commentId, body, metadata, attachmentIds }).then(
2817
2824
  (thread) => {
2818
2825
  store.createThread(optimisticUpdateId, thread);
2819
2826
  },
@@ -2911,7 +2918,7 @@ function useCreateComment() {
2911
2918
  const client = useClient();
2912
2919
  const room = useRoom();
2913
2920
  return React5.useCallback(
2914
- ({ threadId, body }) => {
2921
+ ({ threadId, body, attachments }) => {
2915
2922
  const commentId = createCommentId();
2916
2923
  const createdAt = /* @__PURE__ */ new Date();
2917
2924
  const comment = {
@@ -2922,14 +2929,16 @@ function useCreateComment() {
2922
2929
  createdAt,
2923
2930
  userId: getCurrentUserId(room),
2924
2931
  body,
2925
- reactions: []
2932
+ reactions: [],
2933
+ attachments: attachments ?? []
2926
2934
  };
2927
2935
  const { store, onMutationFailure } = getExtrasForClient2(client);
2928
2936
  const optimisticUpdateId = store.addOptimisticUpdate({
2929
2937
  type: "create-comment",
2930
2938
  comment
2931
2939
  });
2932
- room.createComment({ threadId, commentId, body }).then(
2940
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2941
+ room.createComment({ threadId, commentId, body, attachmentIds }).then(
2933
2942
  (newComment) => {
2934
2943
  store.createComment(newComment, optimisticUpdateId);
2935
2944
  },
@@ -2953,7 +2962,7 @@ function useEditComment() {
2953
2962
  const client = useClient();
2954
2963
  const room = useRoom();
2955
2964
  return React5.useCallback(
2956
- ({ threadId, commentId, body }) => {
2965
+ ({ threadId, commentId, body, attachments }) => {
2957
2966
  const editedAt = /* @__PURE__ */ new Date();
2958
2967
  const { store, onMutationFailure } = getExtrasForClient2(client);
2959
2968
  const thread = store.getThreads().threadsById[threadId];
@@ -2977,10 +2986,12 @@ function useEditComment() {
2977
2986
  comment: {
2978
2987
  ...comment,
2979
2988
  editedAt,
2980
- body
2989
+ body,
2990
+ attachments: attachments ?? []
2981
2991
  }
2982
2992
  });
2983
- room.editComment({ threadId, commentId, body }).then(
2993
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2994
+ room.editComment({ threadId, commentId, body, attachmentIds }).then(
2984
2995
  (editedComment) => {
2985
2996
  store.editComment(threadId, optimisticUpdateId, editedComment);
2986
2997
  },
@@ -3486,6 +3497,65 @@ function useThreadsSuspense(options = {
3486
3497
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
3487
3498
  return state;
3488
3499
  }
3500
+ function selectorFor_useAttachmentUrl(state) {
3501
+ if (state === void 0 || state?.isLoading) {
3502
+ return state ?? { isLoading: true };
3503
+ }
3504
+ if (state.error) {
3505
+ return state;
3506
+ }
3507
+ assert2(state.data !== void 0, "Unexpected missing attachment URL");
3508
+ return {
3509
+ isLoading: false,
3510
+ url: state.data
3511
+ };
3512
+ }
3513
+ function useAttachmentUrl(attachmentId) {
3514
+ const room = useRoom();
3515
+ const { attachmentUrlsStore } = room[kInternal2];
3516
+ const getAttachmentUrlState = React5.useCallback(
3517
+ () => attachmentUrlsStore.getState(attachmentId),
3518
+ [attachmentUrlsStore, attachmentId]
3519
+ );
3520
+ React5.useEffect(() => {
3521
+ void attachmentUrlsStore.get(attachmentId);
3522
+ }, [attachmentUrlsStore, attachmentId]);
3523
+ return useSyncExternalStoreWithSelector2(
3524
+ attachmentUrlsStore.subscribe,
3525
+ getAttachmentUrlState,
3526
+ getAttachmentUrlState,
3527
+ selectorFor_useAttachmentUrl,
3528
+ shallow4
3529
+ );
3530
+ }
3531
+ function useAttachmentUrlSuspense(attachmentId) {
3532
+ const room = useRoom();
3533
+ const { attachmentUrlsStore } = room[kInternal2];
3534
+ const getAttachmentUrlState = React5.useCallback(
3535
+ () => attachmentUrlsStore.getState(attachmentId),
3536
+ [attachmentUrlsStore, attachmentId]
3537
+ );
3538
+ const attachmentUrlState = getAttachmentUrlState();
3539
+ if (!attachmentUrlState || attachmentUrlState.isLoading) {
3540
+ throw attachmentUrlsStore.get(attachmentId);
3541
+ }
3542
+ if (attachmentUrlState.error) {
3543
+ throw attachmentUrlState.error;
3544
+ }
3545
+ const state = useSyncExternalStore2(
3546
+ attachmentUrlsStore.subscribe,
3547
+ getAttachmentUrlState,
3548
+ getAttachmentUrlState
3549
+ );
3550
+ assert2(state !== void 0, "Unexpected missing state");
3551
+ assert2(!state.isLoading, "Unexpected loading state");
3552
+ assert2(!state.error, "Unexpected error state");
3553
+ return {
3554
+ isLoading: false,
3555
+ url: state.data,
3556
+ error: void 0
3557
+ };
3558
+ }
3489
3559
  function useHistoryVersionsSuspense() {
3490
3560
  const client = useClient();
3491
3561
  const room = useRoom();
@@ -3647,6 +3717,8 @@ export {
3647
3717
  useUpdateRoomNotificationSettings,
3648
3718
  useOthersConnectionIdsSuspense,
3649
3719
  useStorageStatusSuspense,
3720
+ useAttachmentUrl,
3721
+ useAttachmentUrlSuspense,
3650
3722
  createRoomContext,
3651
3723
  _RoomProvider,
3652
3724
  _useBroadcastEvent,
@@ -3677,4 +3749,4 @@ export {
3677
3749
  _useStorageRoot,
3678
3750
  _useUpdateMyPresence
3679
3751
  };
3680
- //# sourceMappingURL=chunk-XK5NTOJJ.mjs.map
3752
+ //# sourceMappingURL=chunk-WVLHQ6LC.mjs.map