@liveblocks/react 2.0.0-alpha1 → 2.0.0-alpha2
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/{chunk-HLKYTK7G.mjs → chunk-HZXXTIZ4.mjs} +87 -90
- package/dist/chunk-HZXXTIZ4.mjs.map +1 -0
- package/dist/{chunk-RCQYZVO3.js → chunk-OKKDBZH4.js} +86 -89
- package/dist/chunk-OKKDBZH4.js.map +1 -0
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +9 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{suspense-9ZocWu4y.d.mts → suspense-YGpKbqvY.d.mts} +115 -10
- package/dist/{suspense-9ZocWu4y.d.ts → suspense-YGpKbqvY.d.ts} +115 -10
- package/dist/suspense.d.mts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +3 -3
- package/dist/suspense.mjs +1 -1
- package/package.json +5 -5
- package/dist/chunk-HLKYTK7G.mjs.map +0 -1
- package/dist/chunk-RCQYZVO3.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/react";
|
|
3
|
-
var PKG_VERSION = "2.0.0-
|
|
3
|
+
var PKG_VERSION = "2.0.0-alpha2";
|
|
4
4
|
var PKG_FORMAT = "esm";
|
|
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
|
|
13
|
+
return /* @__PURE__ */ React.createElement(React.Suspense, { fallback: props.fallback }, mounted ? 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
|
-
import { shallow } from "@liveblocks/client";
|
|
646
|
-
import {
|
|
647
|
-
addReaction,
|
|
648
|
-
CommentsApiError,
|
|
649
|
-
console as console2,
|
|
650
|
-
deleteComment,
|
|
651
|
-
deprecateIf,
|
|
652
|
-
errorIf,
|
|
653
|
-
kInternal as kInternal2,
|
|
654
|
-
makeEventSource,
|
|
655
|
-
makePoller as makePoller2,
|
|
656
|
-
NotificationsApiError,
|
|
657
|
-
removeReaction,
|
|
658
|
-
ServerMsgCode,
|
|
659
|
-
stringify,
|
|
660
|
-
upsertComment
|
|
661
|
-
} from "@liveblocks/core";
|
|
662
|
-
import { nanoid as nanoid3 } from "nanoid";
|
|
663
|
-
import * as React4 from "react";
|
|
664
|
-
import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/shim/with-selector.js";
|
|
665
|
-
|
|
666
643
|
// src/comments/errors.ts
|
|
667
644
|
var CreateThreadError = class extends Error {
|
|
668
645
|
constructor(cause, context) {
|
|
@@ -737,46 +714,20 @@ var UpdateNotificationSettingsError = class extends Error {
|
|
|
737
714
|
}
|
|
738
715
|
};
|
|
739
716
|
|
|
740
|
-
// src/comments/lib/createIds.ts
|
|
741
|
-
import { nanoid as nanoid2 } from "nanoid";
|
|
742
|
-
var THREAD_ID_PREFIX = "th";
|
|
743
|
-
var COMMENT_ID_PREFIX = "cm";
|
|
744
|
-
function createOptimisticId(prefix) {
|
|
745
|
-
return `${prefix}_${nanoid2()}`;
|
|
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
|
-
import {
|
|
756
|
-
applyOptimisticUpdates as applyOptimisticUpdates2,
|
|
757
|
-
nn
|
|
758
|
-
} from "@liveblocks/core";
|
|
759
|
-
function selectNotificationSettings(roomId, state) {
|
|
760
|
-
const { notificationSettings } = applyOptimisticUpdates2(state);
|
|
761
|
-
return nn(notificationSettings[roomId]);
|
|
762
|
-
}
|
|
763
|
-
|
|
764
717
|
// src/comments/lib/selected-threads.ts
|
|
765
718
|
import {
|
|
766
|
-
applyOptimisticUpdates as
|
|
719
|
+
applyOptimisticUpdates as applyOptimisticUpdates2
|
|
767
720
|
} from "@liveblocks/core";
|
|
768
721
|
function selectedThreads(roomId, state, options) {
|
|
769
|
-
const result =
|
|
722
|
+
const result = applyOptimisticUpdates2(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
|
+
import { shallow } from "@liveblocks/client";
|
|
761
|
+
import {
|
|
762
|
+
addReaction,
|
|
763
|
+
CommentsApiError,
|
|
764
|
+
console as console2,
|
|
765
|
+
deleteComment,
|
|
766
|
+
deprecateIf,
|
|
767
|
+
errorIf,
|
|
768
|
+
kInternal as kInternal2,
|
|
769
|
+
makeEventSource,
|
|
770
|
+
makePoller as makePoller2,
|
|
771
|
+
NotificationsApiError,
|
|
772
|
+
removeReaction,
|
|
773
|
+
ServerMsgCode,
|
|
774
|
+
stringify,
|
|
775
|
+
upsertComment
|
|
776
|
+
} from "@liveblocks/core";
|
|
777
|
+
import { nanoid as nanoid3 } from "nanoid";
|
|
778
|
+
import * as React4 from "react";
|
|
779
|
+
import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/shim/with-selector.js";
|
|
780
|
+
|
|
781
|
+
// src/comments/lib/createIds.ts
|
|
782
|
+
import { nanoid as nanoid2 } from "nanoid";
|
|
783
|
+
var THREAD_ID_PREFIX = "th";
|
|
784
|
+
var COMMENT_ID_PREFIX = "cm";
|
|
785
|
+
function createOptimisticId(prefix) {
|
|
786
|
+
return `${prefix}_${nanoid2()}`;
|
|
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
|
+
import {
|
|
797
|
+
applyOptimisticUpdates as applyOptimisticUpdates3,
|
|
798
|
+
nn
|
|
799
|
+
} from "@liveblocks/core";
|
|
800
|
+
function selectNotificationSettings(roomId, state) {
|
|
801
|
+
const { notificationSettings } = applyOptimisticUpdates3(state);
|
|
802
|
+
return nn(notificationSettings[roomId]);
|
|
803
|
+
}
|
|
804
|
+
|
|
808
805
|
// src/use-scroll-to-comment-on-load-effect.ts
|
|
809
806
|
import * as React3 from "react";
|
|
810
807
|
function handleScrollToCommentOnLoad(shouldScrollOnLoad, state) {
|
|
811
|
-
if (shouldScrollOnLoad === false)
|
|
812
|
-
|
|
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[kInternal2].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 = 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[kInternal2].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[kInternal2].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[kInternal2].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, kInternal2, {
|
|
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 ServerMsgCode.COMMENT_REACTION_ADDED:
|
|
1265
1251
|
case ServerMsgCode.COMMENT_REACTION_REMOVED:
|
|
1266
1252
|
case ServerMsgCode.COMMENT_DELETED:
|
|
1267
|
-
if (!existingThread)
|
|
1268
|
-
break;
|
|
1253
|
+
if (!existingThread) break;
|
|
1269
1254
|
store.updateThreadAndNotification(thread, inboxNotification);
|
|
1270
1255
|
break;
|
|
1271
1256
|
case 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[kInternal2].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[kInternal2].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 = nanoid3();
|
|
2062
2056
|
const now = /* @__PURE__ */ new Date();
|
|
2063
2057
|
store.pushOptimisticUpdate({
|
|
@@ -2386,6 +2380,8 @@ export {
|
|
|
2386
2380
|
__1,
|
|
2387
2381
|
__2,
|
|
2388
2382
|
__3,
|
|
2383
|
+
CreateThreadError,
|
|
2384
|
+
selectedThreads,
|
|
2389
2385
|
RoomContext,
|
|
2390
2386
|
useStatus,
|
|
2391
2387
|
useBatch,
|
|
@@ -2397,6 +2393,7 @@ export {
|
|
|
2397
2393
|
useCanUndo,
|
|
2398
2394
|
useCanRedo,
|
|
2399
2395
|
useOthersConnectionIds,
|
|
2396
|
+
useCommentsErrorListener,
|
|
2400
2397
|
useCreateComment,
|
|
2401
2398
|
useEditComment,
|
|
2402
2399
|
useDeleteComment,
|
|
@@ -2432,4 +2429,4 @@ export {
|
|
|
2432
2429
|
_useStorageRoot,
|
|
2433
2430
|
_useUpdateMyPresence
|
|
2434
2431
|
};
|
|
2435
|
-
//# sourceMappingURL=chunk-
|
|
2432
|
+
//# sourceMappingURL=chunk-HZXXTIZ4.mjs.map
|