@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
  "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.5.1";
3
+ var PKG_VERSION = "2.7.0-beta1";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -191,6 +191,7 @@ var _client = require('@liveblocks/client');
191
191
 
192
192
 
193
193
 
194
+
194
195
 
195
196
  var _withselectorjs = require('use-sync-external-store/shim/with-selector.js');
196
197
 
@@ -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 = _nullishCoalesce(options.metadata, () => ( {}));
1973
+ const attachments = options.attachments;
1970
1974
  const threadId = _core.createThreadId.call(void 0, );
1971
1975
  const commentId = _core.createCommentId.call(void 0, );
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: _nullishCoalesce(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 = _optionalChain([attachments, 'optionalAccess', _8 => _8.map, 'call', _9 => _9((attachment) => attachment.id)]);
2007
+ room.createThread({ threadId, commentId, body, metadata, attachmentIds }).then(
2002
2008
  (thread) => {
2003
2009
  store.set((state) => ({
2004
2010
  ...state,
@@ -2037,7 +2043,7 @@ function useDeleteThread() {
2037
2043
  const { store, onMutationFailure } = getExtrasForClient2(client);
2038
2044
  const thread = store.get().threads[threadId];
2039
2045
  const userId = getCurrentUserId(room);
2040
- if (_optionalChain([thread, 'optionalAccess', _8 => _8.comments, 'optionalAccess', _9 => _9[0], 'optionalAccess', _10 => _10.userId]) !== userId) {
2046
+ if (_optionalChain([thread, 'optionalAccess', _10 => _10.comments, 'optionalAccess', _11 => _11[0], 'optionalAccess', _12 => _12.userId]) !== userId) {
2041
2047
  throw new Error("Only the thread creator can delete the thread");
2042
2048
  }
2043
2049
  store.pushOptimisticUpdate({
@@ -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 = _core.createCommentId.call(void 0, );
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: _nullishCoalesce(attachments, () => ( []))
2171
2178
  };
2172
2179
  const optimisticUpdateId = _core.nanoid.call(void 0, );
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 = _optionalChain([attachments, 'optionalAccess', _13 => _13.map, 'call', _14 => _14((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 = _core.nanoid.call(void 0, );
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: _nullishCoalesce(attachments, () => ( []))
2263
2272
  },
2264
2273
  id: optimisticUpdateId
2265
2274
  });
2266
- room.editComment({ threadId, commentId, body }).then(
2275
+ const attachmentIds = _optionalChain([attachments, 'optionalAccess', _15 => _15.map, 'call', _16 => _16((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 || _optionalChain([state, 'optionalAccess', _17 => _17.isLoading])) {
2871
+ return _nullishCoalesce(state, () => ( { isLoading: true }));
2872
+ }
2873
+ if (state.error) {
2874
+ return state;
2875
+ }
2876
+ _core.assert.call(void 0, 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[_core.kInternal];
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 _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
2893
+ attachmentUrlsStore.subscribe,
2894
+ getAttachmentUrlState,
2895
+ getAttachmentUrlState,
2896
+ selectorFor_useAttachmentUrl,
2897
+ _client.shallow
2898
+ );
2899
+ }
2900
+ function useAttachmentUrlSuspense(attachmentId) {
2901
+ const room = useRoom();
2902
+ const { attachmentUrlsStore } = room[_core.kInternal];
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
+ _core.assert.call(void 0, state !== void 0, "Unexpected missing state");
2920
+ _core.assert.call(void 0, !state.isLoading, "Unexpected loading state");
2921
+ _core.assert.call(void 0, !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();
@@ -3010,5 +3079,7 @@ var _useUpdateMyPresence = useUpdateMyPresence;
3010
3079
 
3011
3080
 
3012
3081
 
3013
- exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.selectedThreads = selectedThreads; exports.CreateThreadError = CreateThreadError; exports.RoomContext = RoomContext; 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.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._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; exports.ClientContext = ClientContext; 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;
3014
- //# sourceMappingURL=chunk-SZO2TEP6.js.map
3082
+
3083
+
3084
+ exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; exports.selectedThreads = selectedThreads; exports.CreateThreadError = CreateThreadError; exports.RoomContext = RoomContext; 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.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._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; exports.ClientContext = ClientContext; 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;
3085
+ //# sourceMappingURL=chunk-BOXIYIBG.js.map