@liveblocks/react 2.5.1 → 2.7.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.5.1";
3
+ var PKG_VERSION = "2.7.0-beta1";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -174,6 +174,7 @@ var UpdateNotificationSettingsError = class extends Error {
174
174
  import { shallow as shallow2 } from "@liveblocks/client";
175
175
  import {
176
176
  addReaction,
177
+ assert as assert2,
177
178
  CommentsApiError,
178
179
  console as console2,
179
180
  createCommentId,
@@ -1460,6 +1461,7 @@ function makeRoomContextBundle(client) {
1460
1461
  useRemoveReaction,
1461
1462
  useMarkThreadAsRead,
1462
1463
  useThreadSubscription,
1464
+ useAttachmentUrl,
1463
1465
  useRoomNotificationSettings,
1464
1466
  useUpdateRoomNotificationSettings,
1465
1467
  ...shared.classic,
@@ -1503,6 +1505,7 @@ function makeRoomContextBundle(client) {
1503
1505
  useRemoveReaction,
1504
1506
  useMarkThreadAsRead,
1505
1507
  useThreadSubscription,
1508
+ useAttachmentUrl: useAttachmentUrlSuspense,
1506
1509
  useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
1507
1510
  useUpdateRoomNotificationSettings,
1508
1511
  ...shared.suspense
@@ -1967,6 +1970,7 @@ function useCreateThread() {
1967
1970
  (options) => {
1968
1971
  const body = options.body;
1969
1972
  const metadata = options.metadata ?? {};
1973
+ const attachments = options.attachments;
1970
1974
  const threadId = createThreadId();
1971
1975
  const commentId = createCommentId();
1972
1976
  const createdAt = /* @__PURE__ */ new Date();
@@ -1978,7 +1982,8 @@ function useCreateThread() {
1978
1982
  type: "comment",
1979
1983
  userId: getCurrentUserId(room),
1980
1984
  body,
1981
- reactions: []
1985
+ reactions: [],
1986
+ attachments: attachments ?? []
1982
1987
  };
1983
1988
  const newThread = {
1984
1989
  id: threadId,
@@ -1998,7 +2003,8 @@ function useCreateThread() {
1998
2003
  id: optimisticUpdateId,
1999
2004
  roomId: room.id
2000
2005
  });
2001
- room.createThread({ threadId, commentId, body, metadata }).then(
2006
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2007
+ room.createThread({ threadId, commentId, body, metadata, attachmentIds }).then(
2002
2008
  (thread) => {
2003
2009
  store.set((state) => ({
2004
2010
  ...state,
@@ -2156,7 +2162,7 @@ function useCreateComment() {
2156
2162
  const client = useClient();
2157
2163
  const room = useRoom();
2158
2164
  return React4.useCallback(
2159
- ({ threadId, body }) => {
2165
+ ({ threadId, body, attachments }) => {
2160
2166
  const commentId = createCommentId();
2161
2167
  const createdAt = /* @__PURE__ */ new Date();
2162
2168
  const comment = {
@@ -2167,7 +2173,8 @@ function useCreateComment() {
2167
2173
  createdAt,
2168
2174
  userId: getCurrentUserId(room),
2169
2175
  body,
2170
- reactions: []
2176
+ reactions: [],
2177
+ attachments: attachments ?? []
2171
2178
  };
2172
2179
  const optimisticUpdateId = nanoid2();
2173
2180
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -2176,7 +2183,8 @@ function useCreateComment() {
2176
2183
  comment,
2177
2184
  id: optimisticUpdateId
2178
2185
  });
2179
- room.createComment({ threadId, commentId, body }).then(
2186
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2187
+ room.createComment({ threadId, commentId, body, attachmentIds }).then(
2180
2188
  (newComment) => {
2181
2189
  store.set((state) => {
2182
2190
  const existingThread = state.threads[threadId];
@@ -2234,7 +2242,7 @@ function useEditComment() {
2234
2242
  const client = useClient();
2235
2243
  const room = useRoom();
2236
2244
  return React4.useCallback(
2237
- ({ threadId, commentId, body }) => {
2245
+ ({ threadId, commentId, body, attachments }) => {
2238
2246
  const editedAt = /* @__PURE__ */ new Date();
2239
2247
  const optimisticUpdateId = nanoid2();
2240
2248
  const { store, onMutationFailure } = getExtrasForClient2(client);
@@ -2259,11 +2267,13 @@ function useEditComment() {
2259
2267
  comment: {
2260
2268
  ...comment,
2261
2269
  editedAt,
2262
- body
2270
+ body,
2271
+ attachments: attachments ?? []
2263
2272
  },
2264
2273
  id: optimisticUpdateId
2265
2274
  });
2266
- room.editComment({ threadId, commentId, body }).then(
2275
+ const attachmentIds = attachments?.map((attachment) => attachment.id);
2276
+ room.editComment({ threadId, commentId, body, attachmentIds }).then(
2267
2277
  (editedComment) => {
2268
2278
  store.set((state) => {
2269
2279
  const existingThread = state.threads[threadId];
@@ -2856,6 +2866,65 @@ function useThreadsSuspense(options = {
2856
2866
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
2857
2867
  return state;
2858
2868
  }
2869
+ function selectorFor_useAttachmentUrl(state) {
2870
+ if (state === void 0 || state?.isLoading) {
2871
+ return state ?? { isLoading: true };
2872
+ }
2873
+ if (state.error) {
2874
+ return state;
2875
+ }
2876
+ assert2(state.data !== void 0, "Unexpected missing attachment URL");
2877
+ return {
2878
+ isLoading: false,
2879
+ url: state.data
2880
+ };
2881
+ }
2882
+ function useAttachmentUrl(attachmentId) {
2883
+ const room = useRoom();
2884
+ const { attachmentUrlsStore } = room[kInternal2];
2885
+ const getAttachmentUrlState = React4.useCallback(
2886
+ () => attachmentUrlsStore.getState(attachmentId),
2887
+ [attachmentUrlsStore, attachmentId]
2888
+ );
2889
+ React4.useEffect(() => {
2890
+ void attachmentUrlsStore.get(attachmentId);
2891
+ }, [attachmentUrlsStore, attachmentId]);
2892
+ return useSyncExternalStoreWithSelector2(
2893
+ attachmentUrlsStore.subscribe,
2894
+ getAttachmentUrlState,
2895
+ getAttachmentUrlState,
2896
+ selectorFor_useAttachmentUrl,
2897
+ shallow2
2898
+ );
2899
+ }
2900
+ function useAttachmentUrlSuspense(attachmentId) {
2901
+ const room = useRoom();
2902
+ const { attachmentUrlsStore } = room[kInternal2];
2903
+ const getAttachmentUrlState = React4.useCallback(
2904
+ () => attachmentUrlsStore.getState(attachmentId),
2905
+ [attachmentUrlsStore, attachmentId]
2906
+ );
2907
+ const attachmentUrlState = getAttachmentUrlState();
2908
+ if (!attachmentUrlState || attachmentUrlState.isLoading) {
2909
+ throw attachmentUrlsStore.get(attachmentId);
2910
+ }
2911
+ if (attachmentUrlState.error) {
2912
+ throw attachmentUrlState.error;
2913
+ }
2914
+ const state = useSyncExternalStore2(
2915
+ attachmentUrlsStore.subscribe,
2916
+ getAttachmentUrlState,
2917
+ getAttachmentUrlState
2918
+ );
2919
+ assert2(state !== void 0, "Unexpected missing state");
2920
+ assert2(!state.isLoading, "Unexpected loading state");
2921
+ assert2(!state.error, "Unexpected error state");
2922
+ return {
2923
+ isLoading: false,
2924
+ url: state.data,
2925
+ error: void 0
2926
+ };
2927
+ }
2859
2928
  function useRoomNotificationSettingsSuspense() {
2860
2929
  const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
2861
2930
  const client = useClient();
@@ -2964,6 +3033,8 @@ export {
2964
3033
  useUpdateRoomNotificationSettings,
2965
3034
  useOthersConnectionIdsSuspense,
2966
3035
  useStorageStatusSuspense,
3036
+ useAttachmentUrl,
3037
+ useAttachmentUrlSuspense,
2967
3038
  createRoomContext,
2968
3039
  _RoomProvider,
2969
3040
  _useBroadcastEvent,
@@ -3011,4 +3082,4 @@ export {
3011
3082
  _useUserThreads_experimental,
3012
3083
  _useUserThreadsSuspense_experimental
3013
3084
  };
3014
- //# sourceMappingURL=chunk-WI2VR5XA.mjs.map
3085
+ //# sourceMappingURL=chunk-YO5QDPOD.mjs.map