@liveblocks/react 2.0.0-alpha1 → 2.0.0-alpha3

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.0.0-alpha1";
3
+ var PKG_VERSION = "2.0.0-alpha3";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -10,7 +10,7 @@ function ClientSideSuspense(props) {
10
10
  React.useEffect(() => {
11
11
  setMounted(true);
12
12
  }, []);
13
- return /* @__PURE__ */ React.createElement(React.Suspense, { fallback: props.fallback }, mounted ? props.children() : props.fallback);
13
+ return /* @__PURE__ */ React.createElement(React.Suspense, { fallback: props.fallback }, mounted ? typeof props.children === "function" ? props.children() : props.children : props.fallback);
14
14
  }
15
15
 
16
16
  // src/liveblocks.tsx
@@ -40,8 +40,7 @@ function selectedInboxNotifications(state) {
40
40
  var MAX_ERROR_RETRY_COUNT = 5;
41
41
  var ERROR_RETRY_INTERVAL = 5e3;
42
42
  function retryError(action, retryCount) {
43
- if (retryCount >= MAX_ERROR_RETRY_COUNT)
44
- return;
43
+ if (retryCount >= MAX_ERROR_RETRY_COUNT) return;
45
44
  const timeout = Math.pow(2, retryCount) * ERROR_RETRY_INTERVAL;
46
45
  setTimeout(() => {
47
46
  void action();
@@ -641,28 +640,6 @@ var __1 = useInboxNotificationThread;
641
640
  var __2 = useUser;
642
641
  var __3 = useUserSuspense;
643
642
 
644
- // src/room.tsx
645
- var _client = require('@liveblocks/client');
646
-
647
-
648
-
649
-
650
-
651
-
652
-
653
-
654
-
655
-
656
-
657
-
658
-
659
-
660
-
661
-
662
-
663
-
664
-
665
-
666
643
  // src/comments/errors.ts
667
644
  var CreateThreadError = class extends Error {
668
645
  constructor(cause, context) {
@@ -737,30 +714,6 @@ var UpdateNotificationSettingsError = class extends Error {
737
714
  }
738
715
  };
739
716
 
740
- // src/comments/lib/createIds.ts
741
-
742
- var THREAD_ID_PREFIX = "th";
743
- var COMMENT_ID_PREFIX = "cm";
744
- function createOptimisticId(prefix) {
745
- return `${prefix}_${_nanoid.nanoid.call(void 0, )}`;
746
- }
747
- function createThreadId() {
748
- return createOptimisticId(THREAD_ID_PREFIX);
749
- }
750
- function createCommentId() {
751
- return createOptimisticId(COMMENT_ID_PREFIX);
752
- }
753
-
754
- // src/comments/lib/select-notification-settings.ts
755
-
756
-
757
-
758
-
759
- function selectNotificationSettings(roomId, state) {
760
- const { notificationSettings } = _core.applyOptimisticUpdates.call(void 0, state);
761
- return _core.nn.call(void 0, notificationSettings[roomId]);
762
- }
763
-
764
717
  // src/comments/lib/selected-threads.ts
765
718
 
766
719
 
@@ -769,14 +722,12 @@ function selectedThreads(roomId, state, options) {
769
722
  const result = _core.applyOptimisticUpdates.call(void 0, state);
770
723
  const threads = Object.values(result.threads).filter(
771
724
  (thread) => {
772
- if (thread.roomId !== roomId)
773
- return false;
725
+ if (thread.roomId !== roomId) return false;
774
726
  if (thread.deletedAt !== void 0) {
775
727
  return false;
776
728
  }
777
729
  const query = options.query;
778
- if (!query)
779
- return true;
730
+ if (!query) return true;
780
731
  for (const key in query.metadata) {
781
732
  const metadataValue = thread.metadata[key];
782
733
  const filterValue = query.metadata[key];
@@ -805,29 +756,69 @@ var assertMetadataValueIsString = (value) => {
805
756
  return typeof value === "string";
806
757
  };
807
758
 
759
+ // src/room.tsx
760
+ var _client = require('@liveblocks/client');
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+ // src/comments/lib/createIds.ts
782
+
783
+ var THREAD_ID_PREFIX = "th";
784
+ var COMMENT_ID_PREFIX = "cm";
785
+ function createOptimisticId(prefix) {
786
+ return `${prefix}_${_nanoid.nanoid.call(void 0, )}`;
787
+ }
788
+ function createThreadId() {
789
+ return createOptimisticId(THREAD_ID_PREFIX);
790
+ }
791
+ function createCommentId() {
792
+ return createOptimisticId(COMMENT_ID_PREFIX);
793
+ }
794
+
795
+ // src/comments/lib/select-notification-settings.ts
796
+
797
+
798
+
799
+
800
+ function selectNotificationSettings(roomId, state) {
801
+ const { notificationSettings } = _core.applyOptimisticUpdates.call(void 0, state);
802
+ return _core.nn.call(void 0, notificationSettings[roomId]);
803
+ }
804
+
808
805
  // src/use-scroll-to-comment-on-load-effect.ts
809
806
 
810
807
  function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
811
- if (shouldScrollOnLoad === false)
812
- return;
813
- if (state.isLoading)
814
- return;
808
+ if (shouldScrollOnLoad === false) return;
809
+ if (state.isLoading) return;
815
810
  const isWindowDefined = typeof window !== "undefined";
816
- if (!isWindowDefined)
817
- return;
811
+ if (!isWindowDefined) return;
818
812
  const hash = window.location.hash;
819
813
  const commentId = hash.slice(1);
820
- if (!commentId.startsWith("cm_"))
821
- return;
814
+ if (!commentId.startsWith("cm_")) return;
822
815
  const comment = document.getElementById(commentId);
823
- if (comment === null)
824
- return;
816
+ if (comment === null) return;
825
817
  const comments = state.threads.flatMap((thread) => thread.comments);
826
818
  const isCommentInThreads = comments.some(
827
819
  (comment2) => comment2.id === commentId
828
820
  );
829
- if (!isCommentInThreads)
830
- return;
821
+ if (!isCommentInThreads) return;
831
822
  comment.scrollIntoView();
832
823
  }
833
824
  function useScrollToCommentOnLoadEffect(shouldScrollOnLoad, state) {
@@ -948,8 +939,7 @@ function makeExtrasForClient2(client) {
948
939
  const requests = [];
949
940
  client[_core.kInternal].getRoomIds().map((roomId) => {
950
941
  const room = client.getRoom(roomId);
951
- if (room === null)
952
- return;
942
+ if (room === null) return;
953
943
  requests.push(getThreadsUpdates(room.id));
954
944
  });
955
945
  await Promise.allSettled(requests);
@@ -978,14 +968,11 @@ function makeExtrasForClient2(client) {
978
968
  }
979
969
  async function getThreadsUpdates(roomId) {
980
970
  const room = client.getRoom(roomId);
981
- if (room === null)
982
- return;
971
+ if (room === null) return;
983
972
  const since = lastRequestedAtByRoom.get(room.id);
984
- if (since === void 0)
985
- return;
973
+ if (since === void 0) return;
986
974
  const isFetchingThreadsUpdates = _nullishCoalesce(requestStatusByRoom.get(room.id), () => ( false));
987
- if (isFetchingThreadsUpdates === true)
988
- return;
975
+ if (isFetchingThreadsUpdates === true) return;
989
976
  try {
990
977
  requestStatusByRoom.set(room.id, true);
991
978
  const commentsAPI = room[_core.kInternal].comments;
@@ -1007,8 +994,7 @@ function makeExtrasForClient2(client) {
1007
994
  }
1008
995
  async function getThreadsAndInboxNotifications(room, queryKey, options, { retryCount } = { retryCount: 0 }) {
1009
996
  const existingRequest = requestsByQuery.get(queryKey);
1010
- if (existingRequest !== void 0)
1011
- return existingRequest;
997
+ if (existingRequest !== void 0) return existingRequest;
1012
998
  const commentsAPI = room[_core.kInternal].comments;
1013
999
  const request = commentsAPI.getThreads(options);
1014
1000
  requestsByQuery.set(queryKey, request);
@@ -1045,8 +1031,7 @@ function makeExtrasForClient2(client) {
1045
1031
  }
1046
1032
  async function getInboxNotificationSettings(room, queryKey, { retryCount } = { retryCount: 0 }) {
1047
1033
  const existingRequest = requestsByQuery.get(queryKey);
1048
- if (existingRequest !== void 0)
1049
- return existingRequest;
1034
+ if (existingRequest !== void 0) return existingRequest;
1050
1035
  try {
1051
1036
  const request = room[_core.kInternal].notifications.getRoomNotificationSettings();
1052
1037
  requestsByQuery.set(queryKey, request);
@@ -1091,6 +1076,7 @@ function makeExtrasForClient2(client) {
1091
1076
  return {
1092
1077
  store,
1093
1078
  incrementQuerySubscribers,
1079
+ commentsErrorEventSource,
1094
1080
  getThreadsUpdates,
1095
1081
  getThreadsAndInboxNotifications,
1096
1082
  getInboxNotificationSettings,
@@ -1181,7 +1167,8 @@ function makeRoomContextBundle(client) {
1181
1167
  useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
1182
1168
  useUpdateRoomNotificationSettings,
1183
1169
  ...shared.suspense
1184
- }
1170
+ },
1171
+ useCommentsErrorListener
1185
1172
  };
1186
1173
  return Object.defineProperty(bundle, _core.kInternal, {
1187
1174
  enumerable: false
@@ -1195,8 +1182,7 @@ function RoomProvider(props) {
1195
1182
  const stableEnterRoom = React4.useCallback(
1196
1183
  (roomId, options) => {
1197
1184
  const cached = cache.get(roomId);
1198
- if (cached)
1199
- return cached;
1185
+ if (cached) return cached;
1200
1186
  const rv = client.enterRoom(roomId, options);
1201
1187
  const origLeave = rv.leave;
1202
1188
  rv.leave = () => {
@@ -1264,8 +1250,7 @@ function RoomProviderInner(props) {
1264
1250
  case _core.ServerMsgCode.COMMENT_REACTION_ADDED:
1265
1251
  case _core.ServerMsgCode.COMMENT_REACTION_REMOVED:
1266
1252
  case _core.ServerMsgCode.COMMENT_DELETED:
1267
- if (!existingThread)
1268
- break;
1253
+ if (!existingThread) break;
1269
1254
  store.updateThreadAndNotification(thread, inboxNotification);
1270
1255
  break;
1271
1256
  case _core.ServerMsgCode.COMMENT_CREATED:
@@ -1579,6 +1564,14 @@ function useThreads(options = {
1579
1564
  useScrollToCommentOnLoadEffect(scrollOnLoad, state);
1580
1565
  return state;
1581
1566
  }
1567
+ function useCommentsErrorListener(callback) {
1568
+ const client = useClient();
1569
+ const savedCallback = useLatest(callback);
1570
+ const { commentsErrorEventSource } = getExtrasForClient2(client);
1571
+ React4.useEffect(() => {
1572
+ return commentsErrorEventSource.subscribe(savedCallback.current);
1573
+ }, [savedCallback, commentsErrorEventSource]);
1574
+ }
1582
1575
  function useCreateThread() {
1583
1576
  const client = useClient();
1584
1577
  const room = useRoom();
@@ -1613,7 +1606,8 @@ function useCreateThread() {
1613
1606
  store.pushOptimisticUpdate({
1614
1607
  type: "create-thread",
1615
1608
  thread: newThread,
1616
- id: optimisticUpdateId
1609
+ id: optimisticUpdateId,
1610
+ roomId: room.id
1617
1611
  });
1618
1612
  const commentsAPI = room[_core.kInternal].comments;
1619
1613
  commentsAPI.createThread({ threadId, commentId, body, metadata }).then(
@@ -1882,7 +1876,8 @@ function useDeleteComment() {
1882
1876
  threadId,
1883
1877
  commentId,
1884
1878
  deletedAt,
1885
- id: optimisticUpdateId
1879
+ id: optimisticUpdateId,
1880
+ roomId: room.id
1886
1881
  });
1887
1882
  room[_core.kInternal].comments.deleteComment({ threadId, commentId }).then(
1888
1883
  () => {
@@ -2056,8 +2051,7 @@ function useMarkThreadAsRead() {
2056
2051
  ).find(
2057
2052
  (inboxNotification2) => inboxNotification2.kind === "thread" && inboxNotification2.threadId === threadId
2058
2053
  );
2059
- if (!inboxNotification)
2060
- return;
2054
+ if (!inboxNotification) return;
2061
2055
  const optimisticUpdateId = _nanoid.nanoid.call(void 0, );
2062
2056
  const now = /* @__PURE__ */ new Date();
2063
2057
  store.pushOptimisticUpdate({
@@ -2431,5 +2425,8 @@ var _useUpdateMyPresence = useUpdateMyPresence;
2431
2425
 
2432
2426
 
2433
2427
 
2434
- exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; 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.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports.__1 = __1; exports.__2 = __2; exports.__3 = __3; exports.RoomContext = RoomContext; exports.useStatus = useStatus; 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.useCreateComment = useCreateComment; exports.useEditComment = useEditComment; exports.useDeleteComment = useDeleteComment; exports.useRemoveReaction = useRemoveReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; 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;
2435
- //# sourceMappingURL=chunk-RCQYZVO3.js.map
2428
+
2429
+
2430
+
2431
+ exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense; 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.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports.__1 = __1; exports.__2 = __2; exports.__3 = __3; exports.CreateThreadError = CreateThreadError; exports.selectedThreads = selectedThreads; exports.RoomContext = RoomContext; exports.useStatus = useStatus; 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.useThreadSubscription = useThreadSubscription; exports.useRoomNotificationSettings = useRoomNotificationSettings; exports.useUpdateRoomNotificationSettings = useUpdateRoomNotificationSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; 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;
2432
+ //# sourceMappingURL=chunk-ZUMWKFSY.js.map