@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
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// 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 = "cjs";
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)) {
@@ -1928,6 +1929,7 @@ var _client = require('@liveblocks/client');
1928
1929
 
1929
1930
 
1930
1931
 
1932
+
1931
1933
  // src/use-scroll-to-comment-on-load-effect.ts
1932
1934
 
1933
1935
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
@@ -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 = _nullishCoalesce(options.metadata, () => ( {}));
2791
+ const attachments = options.attachments;
2787
2792
  const threadId = _core.createThreadId.call(void 0, );
2788
2793
  const commentId = _core.createCommentId.call(void 0, );
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: _nullishCoalesce(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 = _optionalChain([attachments, 'optionalAccess', _23 => _23.map, 'call', _24 => _24((attachment) => attachment.id)]);
2823
+ room.createThread({ threadId, commentId, body, metadata, attachmentIds }).then(
2817
2824
  (thread) => {
2818
2825
  store.createThread(optimisticUpdateId, thread);
2819
2826
  },
@@ -2842,7 +2849,7 @@ function useDeleteThread() {
2842
2849
  const { store, onMutationFailure } = getExtrasForClient2(client);
2843
2850
  const thread = store.getThreads().threadsById[threadId];
2844
2851
  const userId = getCurrentUserId(room);
2845
- if (_optionalChain([thread, 'optionalAccess', _23 => _23.comments, 'optionalAccess', _24 => _24[0], 'optionalAccess', _25 => _25.userId]) !== userId) {
2852
+ if (_optionalChain([thread, 'optionalAccess', _25 => _25.comments, 'optionalAccess', _26 => _26[0], 'optionalAccess', _27 => _27.userId]) !== userId) {
2846
2853
  throw new Error("Only the thread creator can delete the thread");
2847
2854
  }
2848
2855
  const optimisticUpdateId = store.addOptimisticUpdate({
@@ -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 = _core.createCommentId.call(void 0, );
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: _nullishCoalesce(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 = _optionalChain([attachments, 'optionalAccess', _28 => _28.map, 'call', _29 => _29((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: _nullishCoalesce(attachments, () => ( []))
2981
2991
  }
2982
2992
  });
2983
- room.editComment({ threadId, commentId, body }).then(
2993
+ const attachmentIds = _optionalChain([attachments, 'optionalAccess', _30 => _30.map, 'call', _31 => _31((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 || _optionalChain([state, 'optionalAccess', _32 => _32.isLoading])) {
3502
+ return _nullishCoalesce(state, () => ( { isLoading: true }));
3503
+ }
3504
+ if (state.error) {
3505
+ return state;
3506
+ }
3507
+ _core.assert.call(void 0, 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[_core.kInternal];
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 _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
3524
+ attachmentUrlsStore.subscribe,
3525
+ getAttachmentUrlState,
3526
+ getAttachmentUrlState,
3527
+ selectorFor_useAttachmentUrl,
3528
+ _client.shallow
3529
+ );
3530
+ }
3531
+ function useAttachmentUrlSuspense(attachmentId) {
3532
+ const room = useRoom();
3533
+ const { attachmentUrlsStore } = room[_core.kInternal];
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
+ _core.assert.call(void 0, state !== void 0, "Unexpected missing state");
3551
+ _core.assert.call(void 0, !state.isLoading, "Unexpected loading state");
3552
+ _core.assert.call(void 0, !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();
@@ -3676,5 +3746,7 @@ var _useUpdateMyPresence = useUpdateMyPresence;
3676
3746
 
3677
3747
 
3678
3748
 
3679
- exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.RoomContext = RoomContext; exports.ClientContext = ClientContext; exports.selectThreads = selectThreads; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports.CreateThreadError = CreateThreadError; exports.useStatus = useStatus; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateComment = useCreateComment; exports.useEditComment = useEditComment; exports.useDeleteComment = useDeleteComment; exports.useRemoveReaction = useRemoveReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
3680
- //# sourceMappingURL=chunk-TNEGW2UU.js.map
3749
+
3750
+
3751
+ exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.RoomContext = RoomContext; exports.ClientContext = ClientContext; exports.selectThreads = selectThreads; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useClient = useClient; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports.CreateThreadError = CreateThreadError; exports.useStatus = useStatus; exports.useStorageStatus = useStorageStatus; exports.useBatch = useBatch; exports.useLostConnectionListener = useLostConnectionListener; exports.useErrorListener = useErrorListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCommentsErrorListener = useCommentsErrorListener; exports.useCreateComment = useCreateComment; exports.useEditComment = useEditComment; exports.useDeleteComment = useDeleteComment; exports.useRemoveReaction = useRemoveReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useStorageStatusSuspense = useStorageStatusSuspense; exports.useAttachmentUrl = useAttachmentUrl; exports.useAttachmentUrlSuspense = useAttachmentUrlSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useThreadsSuspense = _useThreadsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
3752
+ //# sourceMappingURL=chunk-BYZWUB6M.js.map