@liveblocks/react 1.10.0-beta1 → 1.10.0-beta2

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.
package/dist/index.d.mts CHANGED
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode, PropsWithChildren } from 'react';
2
2
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, BaseMetadata as BaseMetadata$1, Client } from '@liveblocks/client';
3
3
  export { Json, JsonObject, shallow } from '@liveblocks/client';
4
4
  import * as _liveblocks_core from '@liveblocks/core';
5
- import { BaseMetadata, GetThreadsOptions, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
5
+ import { BaseMetadata, GetThreadsOptions, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
6
6
 
7
7
  declare type Props = {
8
8
  fallback: NonNullable<ReactNode> | null;
@@ -1049,7 +1049,23 @@ declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUs
1049
1049
  * This is an internal API, use `createRoomContext` instead.
1050
1050
  */
1051
1051
  declare function useRoomContextBundle(): RoomContextBundle<JsonObject, LsonObject, BaseUserMeta, never, BaseMetadata>;
1052
- declare function createRoomContext<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never, TThreadMetadata extends BaseMetadata = never>(client: Client): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata>;
1052
+ declare type Options<TUserMeta extends BaseUserMeta> = {
1053
+ /**
1054
+ * @deprecated Define 'resolveUsers' in 'createClient' from '@liveblocks/client' instead.
1055
+ * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1056
+ *
1057
+ * A function that returns user info from user IDs.
1058
+ */
1059
+ resolveUsers?: (args: ResolveUsersArgs) => OptionalPromise<(TUserMeta["info"] | undefined)[] | undefined>;
1060
+ /**
1061
+ * @deprecated Define 'resolveMentionSuggestions' in 'createClient' from '@liveblocks/client' instead.
1062
+ * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1063
+ *
1064
+ * A function that returns a list of user IDs matching a string.
1065
+ */
1066
+ resolveMentionSuggestions?: (args: ResolveMentionSuggestionsArgs) => OptionalPromise<string[]>;
1067
+ };
1068
+ declare function createRoomContext<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never, TThreadMetadata extends BaseMetadata = never>(client: Client, options?: Options<TUserMeta>): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata>;
1053
1069
 
1054
1070
  /**
1055
1071
  * @private
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { ReactElement, ReactNode, PropsWithChildren } from 'react';
2
2
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, BaseMetadata as BaseMetadata$1, Client } from '@liveblocks/client';
3
3
  export { Json, JsonObject, shallow } from '@liveblocks/client';
4
4
  import * as _liveblocks_core from '@liveblocks/core';
5
- import { BaseMetadata, GetThreadsOptions, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
5
+ import { BaseMetadata, GetThreadsOptions, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
6
6
 
7
7
  declare type Props = {
8
8
  fallback: NonNullable<ReactNode> | null;
@@ -1049,7 +1049,23 @@ declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUs
1049
1049
  * This is an internal API, use `createRoomContext` instead.
1050
1050
  */
1051
1051
  declare function useRoomContextBundle(): RoomContextBundle<JsonObject, LsonObject, BaseUserMeta, never, BaseMetadata>;
1052
- declare function createRoomContext<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never, TThreadMetadata extends BaseMetadata = never>(client: Client): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata>;
1052
+ declare type Options<TUserMeta extends BaseUserMeta> = {
1053
+ /**
1054
+ * @deprecated Define 'resolveUsers' in 'createClient' from '@liveblocks/client' instead.
1055
+ * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1056
+ *
1057
+ * A function that returns user info from user IDs.
1058
+ */
1059
+ resolveUsers?: (args: ResolveUsersArgs) => OptionalPromise<(TUserMeta["info"] | undefined)[] | undefined>;
1060
+ /**
1061
+ * @deprecated Define 'resolveMentionSuggestions' in 'createClient' from '@liveblocks/client' instead.
1062
+ * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1063
+ *
1064
+ * A function that returns a list of user IDs matching a string.
1065
+ */
1066
+ resolveMentionSuggestions?: (args: ResolveMentionSuggestionsArgs) => OptionalPromise<string[]>;
1067
+ };
1068
+ declare function createRoomContext<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never, TThreadMetadata extends BaseMetadata = never>(client: Client, options?: Options<TUserMeta>): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata>;
1053
1069
 
1054
1070
  /**
1055
1071
  * @private
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var _core = require('@liveblocks/core');
5
5
 
6
6
  // src/version.ts
7
7
  var PKG_NAME = "@liveblocks/react";
8
- var PKG_VERSION = "1.10.0-beta1";
8
+ var PKG_VERSION = "1.10.0-beta2";
9
9
  var PKG_FORMAT = "cjs";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -164,7 +164,7 @@ function selectNotificationSettings(roomId, state) {
164
164
 
165
165
  function selectedThreads(roomId, state, options) {
166
166
  const result = _core.applyOptimisticUpdates.call(void 0, state);
167
- return Object.values(result.threads).filter((thread) => {
167
+ const threads = Object.values(result.threads).filter((thread) => {
168
168
  if (thread.roomId !== roomId)
169
169
  return false;
170
170
  const query = options.query;
@@ -177,6 +177,7 @@ function selectedThreads(roomId, state, options) {
177
177
  }
178
178
  return true;
179
179
  });
180
+ return threads.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime());
180
181
  }
181
182
 
182
183
  // src/comments/lib/upsert-comment.ts
@@ -299,7 +300,17 @@ function useRoomContextBundle() {
299
300
  }
300
301
  return bundle;
301
302
  }
302
- function createRoomContext(client) {
303
+ function createRoomContext(client, options) {
304
+ if (_optionalChain([options, 'optionalAccess', _2 => _2.resolveUsers])) {
305
+ throw new Error(
306
+ "The 'resolveUsers' option has moved to 'createClient' from '@liveblocks/client'. Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10."
307
+ );
308
+ }
309
+ if (_optionalChain([options, 'optionalAccess', _3 => _3.resolveMentionSuggestions])) {
310
+ throw new Error(
311
+ "The 'resolveMentionSuggestions' option has moved to 'createClient' from '@liveblocks/client'. Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10."
312
+ );
313
+ }
303
314
  const RoomContext = React2.createContext(null);
304
315
  const commentsErrorEventSource = _core.makeEventSource.call(void 0, );
305
316
  const shared = createSharedContext(client);
@@ -308,13 +319,13 @@ function createRoomContext(client) {
308
319
  () => /* @__PURE__ */ new Map()
309
320
  );
310
321
  const stableEnterRoom = React2.useCallback(
311
- (roomId, options) => {
322
+ (roomId, options2) => {
312
323
  const cached = cache.get(roomId);
313
324
  if (cached)
314
325
  return cached;
315
326
  const rv = client.enterRoom(
316
327
  roomId,
317
- options
328
+ options2
318
329
  );
319
330
  const origLeave = rv.leave;
320
331
  rv.leave = () => {
@@ -507,8 +518,8 @@ function createRoomContext(client) {
507
518
  function useBroadcastEvent() {
508
519
  const room = useRoom();
509
520
  return React2.useCallback(
510
- (event, options = { shouldQueueEventIfNotReady: false }) => {
511
- room.broadcastEvent(event, options);
521
+ (event, options2 = { shouldQueueEventIfNotReady: false }) => {
522
+ room.broadcastEvent(event, options2);
512
523
  },
513
524
  [room]
514
525
  );
@@ -618,7 +629,7 @@ function createRoomContext(client) {
618
629
  function onRootChange() {
619
630
  const newValue = root.get(key);
620
631
  if (newValue !== curr) {
621
- _optionalChain([unsubCurr, 'optionalCall', _2 => _2()]);
632
+ _optionalChain([unsubCurr, 'optionalCall', _4 => _4()]);
622
633
  curr = newValue;
623
634
  subscribeToCurr();
624
635
  rerender();
@@ -629,7 +640,7 @@ function createRoomContext(client) {
629
640
  const unsubscribeRoot = room.subscribe(root, onRootChange);
630
641
  return () => {
631
642
  unsubscribeRoot();
632
- _optionalChain([unsubCurr, 'optionalCall', _3 => _3()]);
643
+ _optionalChain([unsubCurr, 'optionalCall', _5 => _5()]);
633
644
  };
634
645
  }, [rootOrNull, room, key, rerender]);
635
646
  if (rootOrNull === null) {
@@ -839,7 +850,7 @@ function createRoomContext(client) {
839
850
  }
840
851
  poller.start(POLLING_INTERVAL);
841
852
  }
842
- async function getThreadsAndInboxNotifications(room, queryKey, options) {
853
+ async function getThreadsAndInboxNotifications(room, queryKey, options2) {
843
854
  const roomId = room.id;
844
855
  return getOrInitRequest(
845
856
  queryKey,
@@ -848,7 +859,7 @@ function createRoomContext(client) {
848
859
  if (room2 === null) {
849
860
  return;
850
861
  }
851
- return room2.getThreads(options);
862
+ return room2.getThreads(options2);
852
863
  },
853
864
  (result) => {
854
865
  if (result !== void 0) {
@@ -861,21 +872,18 @@ function createRoomContext(client) {
861
872
  }
862
873
  );
863
874
  }
864
- function useThreads(options = { query: { metadata: {} } }) {
875
+ function useThreads(options2 = { query: { metadata: {} } }) {
865
876
  const room = useRoom();
866
877
  const queryKey = React2.useMemo(
867
- () => generateQueryKey(room.id, options.query),
868
- [room, options]
878
+ () => generateQueryKey(room.id, options2.query),
879
+ [room, options2]
869
880
  );
870
881
  React2.useEffect(() => {
871
- void getThreadsAndInboxNotifications(room, queryKey, options);
882
+ void getThreadsAndInboxNotifications(room, queryKey, options2);
872
883
  incrementQuerySubscribers(queryKey);
873
884
  return () => decrementQuerySubscribers(queryKey);
874
885
  }, [room, queryKey]);
875
- return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
876
- store.subscribe,
877
- store.get,
878
- store.get,
886
+ const selector = React2.useCallback(
879
887
  (state) => {
880
888
  if (state.queries[queryKey] === void 0 || state.queries[queryKey].isLoading) {
881
889
  return {
@@ -883,26 +891,44 @@ function createRoomContext(client) {
883
891
  };
884
892
  }
885
893
  return {
886
- threads: selectedThreads(room.id, state, options),
894
+ threads: selectedThreads(room.id, state, options2),
887
895
  isLoading: false,
888
896
  error: state.queries[queryKey].error
889
897
  };
890
- }
898
+ },
899
+ [room, queryKey]
900
+ // eslint-disable-line react-hooks/exhaustive-deps
901
+ );
902
+ return _withselectorjs.useSyncExternalStoreWithSelector.call(void 0,
903
+ store.subscribe,
904
+ store.get,
905
+ store.get,
906
+ selector
891
907
  );
892
908
  }
893
- function useThreadsSuspense(options = { query: { metadata: {} } }) {
909
+ function useThreadsSuspense(options2 = { query: { metadata: {} } }) {
894
910
  const room = useRoom();
895
911
  const queryKey = React2.useMemo(
896
- () => generateQueryKey(room.id, _optionalChain([options, 'optionalAccess', _4 => _4.query])),
897
- [room, options]
912
+ () => generateQueryKey(room.id, _optionalChain([options2, 'optionalAccess', _6 => _6.query])),
913
+ [room, options2]
898
914
  );
899
915
  const query = store.get().queries[queryKey];
900
916
  if (query === void 0 || query.isLoading) {
901
- throw getThreadsAndInboxNotifications(room, queryKey, options);
917
+ throw getThreadsAndInboxNotifications(room, queryKey, options2);
902
918
  }
903
919
  if (query.error) {
904
920
  throw query.error;
905
921
  }
922
+ const selector = React2.useCallback(
923
+ (state) => {
924
+ return {
925
+ threads: selectedThreads(room.id, state, options2),
926
+ isLoading: false
927
+ };
928
+ },
929
+ [room, queryKey]
930
+ // eslint-disable-line react-hooks/exhaustive-deps
931
+ );
906
932
  React2.useEffect(() => {
907
933
  incrementQuerySubscribers(queryKey);
908
934
  return () => {
@@ -913,20 +939,15 @@ function createRoomContext(client) {
913
939
  store.subscribe,
914
940
  store.get,
915
941
  store.get,
916
- (state) => {
917
- return {
918
- threads: selectedThreads(room.id, state, options),
919
- isLoading: false
920
- };
921
- }
942
+ selector
922
943
  );
923
944
  }
924
945
  function useCreateThread() {
925
946
  const room = useRoom();
926
947
  return React2.useCallback(
927
- (options) => {
928
- const body = options.body;
929
- const metadata = "metadata" in options ? options.metadata : {};
948
+ (options2) => {
949
+ const body = options2.body;
950
+ const metadata = "metadata" in options2 ? options2.metadata : {};
930
951
  const threadId = createThreadId();
931
952
  const commentId = createCommentId();
932
953
  const now = /* @__PURE__ */ new Date();
@@ -987,12 +1008,12 @@ function createRoomContext(client) {
987
1008
  function useEditThreadMetadata() {
988
1009
  const room = useRoom();
989
1010
  return React2.useCallback(
990
- (options) => {
991
- if (!("metadata" in options)) {
1011
+ (options2) => {
1012
+ if (!("metadata" in options2)) {
992
1013
  return;
993
1014
  }
994
- const threadId = options.threadId;
995
- const metadata = options.metadata;
1015
+ const threadId = options2.threadId;
1016
+ const metadata = options2.metadata;
996
1017
  const optimisticUpdateId = _nanoid.nanoid.call(void 0, );
997
1018
  store.pushOptimisticUpdate({
998
1019
  type: "edit-thread-metadata",
@@ -1198,7 +1219,7 @@ function createRoomContext(client) {
1198
1219
  type: "create-comment",
1199
1220
  comment,
1200
1221
  id: optimisticUpdateId,
1201
- inboxNotificationId: _optionalChain([inboxNotification, 'optionalAccess', _5 => _5.id])
1222
+ inboxNotificationId: _optionalChain([inboxNotification, 'optionalAccess', _7 => _7.id])
1202
1223
  });
1203
1224
  room.createComment({ threadId, commentId, body }).then(
1204
1225
  (newComment) => {
@@ -1359,7 +1380,7 @@ function createRoomContext(client) {
1359
1380
  );
1360
1381
  }
1361
1382
  } catch (error) {
1362
- _core.console.error(_optionalChain([error, 'optionalAccess', _6 => _6.message]));
1383
+ _core.console.error(_optionalChain([error, 'optionalAccess', _8 => _8.message]));
1363
1384
  }
1364
1385
  };
1365
1386
  if (mentionSuggestionsCache.has(mentionSuggestionsCacheKey)) {
@@ -1686,7 +1707,7 @@ function getCurrentUserId(room) {
1686
1707
  }
1687
1708
  function handleApiError(err) {
1688
1709
  const message = `Request failed with status ${err.status}: ${err.message}`;
1689
- if (_optionalChain([err, 'access', _7 => _7.details, 'optionalAccess', _8 => _8.error]) === "FORBIDDEN") {
1710
+ if (_optionalChain([err, 'access', _9 => _9.details, 'optionalAccess', _10 => _10.error]) === "FORBIDDEN") {
1690
1711
  const detailedMessage = [message, err.details.suggestion, err.details.docs].filter(Boolean).join("\n");
1691
1712
  _core.console.error(detailedMessage);
1692
1713
  }
@@ -1750,7 +1771,7 @@ function createSharedContext(client) {
1750
1771
  );
1751
1772
  return {
1752
1773
  ...state,
1753
- user: _optionalChain([state, 'optionalAccess', _9 => _9.data])
1774
+ user: _optionalChain([state, 'optionalAccess', _11 => _11.data])
1754
1775
  };
1755
1776
  }
1756
1777
  function useRoomInfo(roomId) {
@@ -1790,7 +1811,7 @@ function createSharedContext(client) {
1790
1811
  );
1791
1812
  return {
1792
1813
  ...state,
1793
- info: _optionalChain([state, 'optionalAccess', _10 => _10.data])
1814
+ info: _optionalChain([state, 'optionalAccess', _12 => _12.data])
1794
1815
  };
1795
1816
  }
1796
1817
  const bundle = {