@liveblocks/react 2.7.0-beta1 → 2.7.0-versions
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-YO5QDPOD.mjs → chunk-EDJS5J5R.mjs} +145 -76
- package/dist/chunk-EDJS5J5R.mjs.map +1 -0
- package/dist/{chunk-BOXIYIBG.js → chunk-GN5SQAIY.js} +145 -76
- package/dist/chunk-GN5SQAIY.js.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/dist/{suspense-JsIIJujn.d.mts → suspense-2UL0jBvg.d.mts} +66 -38
- package/dist/{suspense-JsIIJujn.d.ts → suspense-2UL0jBvg.d.ts} +66 -38
- package/dist/suspense.d.mts +1 -1
- package/dist/suspense.d.ts +1 -1
- package/dist/suspense.js +3 -3
- package/dist/suspense.js.map +1 -1
- package/dist/suspense.mjs +3 -3
- package/dist/suspense.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-BOXIYIBG.js.map +0 -1
- package/dist/chunk-YO5QDPOD.mjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
2
|
var PKG_NAME = "@liveblocks/react";
|
|
3
|
-
var PKG_VERSION = "2.7.0-
|
|
3
|
+
var PKG_VERSION = "2.7.0-versions";
|
|
4
4
|
var PKG_FORMAT = "esm";
|
|
5
5
|
|
|
6
6
|
// src/ClientSideSuspense.tsx
|
|
@@ -174,7 +174,6 @@ var UpdateNotificationSettingsError = class extends Error {
|
|
|
174
174
|
import { shallow as shallow2 } from "@liveblocks/client";
|
|
175
175
|
import {
|
|
176
176
|
addReaction,
|
|
177
|
-
assert as assert2,
|
|
178
177
|
CommentsApiError,
|
|
179
178
|
console as console2,
|
|
180
179
|
createCommentId,
|
|
@@ -1324,6 +1323,41 @@ function makeExtrasForClient2(client) {
|
|
|
1324
1323
|
return;
|
|
1325
1324
|
}
|
|
1326
1325
|
}
|
|
1326
|
+
async function getRoomVersions(room, { retryCount } = { retryCount: 0 }) {
|
|
1327
|
+
const queryKey = getVersionsQueryKey(room.id);
|
|
1328
|
+
const existingRequest = requestsByQuery.get(queryKey);
|
|
1329
|
+
console2.warn("existing request", existingRequest);
|
|
1330
|
+
if (existingRequest !== void 0) return existingRequest;
|
|
1331
|
+
const request = room[kInternal2].listTextVersions();
|
|
1332
|
+
requestsByQuery.set(queryKey, request);
|
|
1333
|
+
store.setQueryState(queryKey, {
|
|
1334
|
+
isLoading: true
|
|
1335
|
+
});
|
|
1336
|
+
try {
|
|
1337
|
+
const result = await request;
|
|
1338
|
+
const data = await result.json();
|
|
1339
|
+
const versions = data.versions.map(({ createdAt, ...version2 }) => {
|
|
1340
|
+
return {
|
|
1341
|
+
createdAt: new Date(createdAt),
|
|
1342
|
+
...version2
|
|
1343
|
+
};
|
|
1344
|
+
});
|
|
1345
|
+
store.updateRoomVersions(room.id, versions, queryKey);
|
|
1346
|
+
requestsByQuery.delete(queryKey);
|
|
1347
|
+
} catch (err) {
|
|
1348
|
+
requestsByQuery.delete(queryKey);
|
|
1349
|
+
retryError(() => {
|
|
1350
|
+
void getRoomVersions(room, {
|
|
1351
|
+
retryCount: retryCount + 1
|
|
1352
|
+
});
|
|
1353
|
+
}, retryCount);
|
|
1354
|
+
store.setQueryState(queryKey, {
|
|
1355
|
+
isLoading: false,
|
|
1356
|
+
error: err
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1327
1361
|
async function getThreadsAndInboxNotifications(room, queryKey, options, { retryCount } = { retryCount: 0 }) {
|
|
1328
1362
|
const existingRequest = requestsByQuery.get(queryKey);
|
|
1329
1363
|
if (existingRequest !== void 0) return existingRequest;
|
|
@@ -1412,6 +1446,7 @@ function makeExtrasForClient2(client) {
|
|
|
1412
1446
|
getThreadsUpdates,
|
|
1413
1447
|
getThreadsAndInboxNotifications,
|
|
1414
1448
|
getInboxNotificationSettings,
|
|
1449
|
+
getRoomVersions,
|
|
1415
1450
|
onMutationFailure
|
|
1416
1451
|
};
|
|
1417
1452
|
}
|
|
@@ -1461,7 +1496,8 @@ function makeRoomContextBundle(client) {
|
|
|
1461
1496
|
useRemoveReaction,
|
|
1462
1497
|
useMarkThreadAsRead,
|
|
1463
1498
|
useThreadSubscription,
|
|
1464
|
-
|
|
1499
|
+
useHistoryVersions,
|
|
1500
|
+
useHistoryVersionData,
|
|
1465
1501
|
useRoomNotificationSettings,
|
|
1466
1502
|
useUpdateRoomNotificationSettings,
|
|
1467
1503
|
...shared.classic,
|
|
@@ -1505,7 +1541,8 @@ function makeRoomContextBundle(client) {
|
|
|
1505
1541
|
useRemoveReaction,
|
|
1506
1542
|
useMarkThreadAsRead,
|
|
1507
1543
|
useThreadSubscription,
|
|
1508
|
-
|
|
1544
|
+
// TODO: useHistoryVersionData: useHistoryVersionDataSuspense,
|
|
1545
|
+
useHistoryVersions: useHistoryVersionsSuspense,
|
|
1509
1546
|
useRoomNotificationSettings: useRoomNotificationSettingsSuspense,
|
|
1510
1547
|
useUpdateRoomNotificationSettings,
|
|
1511
1548
|
...shared.suspense
|
|
@@ -1970,7 +2007,6 @@ function useCreateThread() {
|
|
|
1970
2007
|
(options) => {
|
|
1971
2008
|
const body = options.body;
|
|
1972
2009
|
const metadata = options.metadata ?? {};
|
|
1973
|
-
const attachments = options.attachments;
|
|
1974
2010
|
const threadId = createThreadId();
|
|
1975
2011
|
const commentId = createCommentId();
|
|
1976
2012
|
const createdAt = /* @__PURE__ */ new Date();
|
|
@@ -1982,8 +2018,7 @@ function useCreateThread() {
|
|
|
1982
2018
|
type: "comment",
|
|
1983
2019
|
userId: getCurrentUserId(room),
|
|
1984
2020
|
body,
|
|
1985
|
-
reactions: []
|
|
1986
|
-
attachments: attachments ?? []
|
|
2021
|
+
reactions: []
|
|
1987
2022
|
};
|
|
1988
2023
|
const newThread = {
|
|
1989
2024
|
id: threadId,
|
|
@@ -2003,8 +2038,7 @@ function useCreateThread() {
|
|
|
2003
2038
|
id: optimisticUpdateId,
|
|
2004
2039
|
roomId: room.id
|
|
2005
2040
|
});
|
|
2006
|
-
|
|
2007
|
-
room.createThread({ threadId, commentId, body, metadata, attachmentIds }).then(
|
|
2041
|
+
room.createThread({ threadId, commentId, body, metadata }).then(
|
|
2008
2042
|
(thread) => {
|
|
2009
2043
|
store.set((state) => ({
|
|
2010
2044
|
...state,
|
|
@@ -2162,7 +2196,7 @@ function useCreateComment() {
|
|
|
2162
2196
|
const client = useClient();
|
|
2163
2197
|
const room = useRoom();
|
|
2164
2198
|
return React4.useCallback(
|
|
2165
|
-
({ threadId, body
|
|
2199
|
+
({ threadId, body }) => {
|
|
2166
2200
|
const commentId = createCommentId();
|
|
2167
2201
|
const createdAt = /* @__PURE__ */ new Date();
|
|
2168
2202
|
const comment = {
|
|
@@ -2173,8 +2207,7 @@ function useCreateComment() {
|
|
|
2173
2207
|
createdAt,
|
|
2174
2208
|
userId: getCurrentUserId(room),
|
|
2175
2209
|
body,
|
|
2176
|
-
reactions: []
|
|
2177
|
-
attachments: attachments ?? []
|
|
2210
|
+
reactions: []
|
|
2178
2211
|
};
|
|
2179
2212
|
const optimisticUpdateId = nanoid2();
|
|
2180
2213
|
const { store, onMutationFailure } = getExtrasForClient2(client);
|
|
@@ -2183,8 +2216,7 @@ function useCreateComment() {
|
|
|
2183
2216
|
comment,
|
|
2184
2217
|
id: optimisticUpdateId
|
|
2185
2218
|
});
|
|
2186
|
-
|
|
2187
|
-
room.createComment({ threadId, commentId, body, attachmentIds }).then(
|
|
2219
|
+
room.createComment({ threadId, commentId, body }).then(
|
|
2188
2220
|
(newComment) => {
|
|
2189
2221
|
store.set((state) => {
|
|
2190
2222
|
const existingThread = state.threads[threadId];
|
|
@@ -2242,7 +2274,7 @@ function useEditComment() {
|
|
|
2242
2274
|
const client = useClient();
|
|
2243
2275
|
const room = useRoom();
|
|
2244
2276
|
return React4.useCallback(
|
|
2245
|
-
({ threadId, commentId, body
|
|
2277
|
+
({ threadId, commentId, body }) => {
|
|
2246
2278
|
const editedAt = /* @__PURE__ */ new Date();
|
|
2247
2279
|
const optimisticUpdateId = nanoid2();
|
|
2248
2280
|
const { store, onMutationFailure } = getExtrasForClient2(client);
|
|
@@ -2267,13 +2299,11 @@ function useEditComment() {
|
|
|
2267
2299
|
comment: {
|
|
2268
2300
|
...comment,
|
|
2269
2301
|
editedAt,
|
|
2270
|
-
body
|
|
2271
|
-
attachments: attachments ?? []
|
|
2302
|
+
body
|
|
2272
2303
|
},
|
|
2273
2304
|
id: optimisticUpdateId
|
|
2274
2305
|
});
|
|
2275
|
-
|
|
2276
|
-
room.editComment({ threadId, commentId, body, attachmentIds }).then(
|
|
2306
|
+
room.editComment({ threadId, commentId, body }).then(
|
|
2277
2307
|
(editedComment) => {
|
|
2278
2308
|
store.set((state) => {
|
|
2279
2309
|
const existingThread = state.threads[threadId];
|
|
@@ -2734,6 +2764,68 @@ function useRoomNotificationSettings() {
|
|
|
2734
2764
|
return [settings, updateRoomNotificationSettings];
|
|
2735
2765
|
}, [settings, updateRoomNotificationSettings]);
|
|
2736
2766
|
}
|
|
2767
|
+
function useHistoryVersionData(versionId) {
|
|
2768
|
+
const [state, setState] = React4.useState({
|
|
2769
|
+
isLoading: true
|
|
2770
|
+
});
|
|
2771
|
+
const room = useRoom();
|
|
2772
|
+
React4.useEffect(() => {
|
|
2773
|
+
setState({ isLoading: true });
|
|
2774
|
+
const load = async () => {
|
|
2775
|
+
try {
|
|
2776
|
+
const response = await room[kInternal2].getTextVersion(versionId);
|
|
2777
|
+
const buffer = await response.arrayBuffer();
|
|
2778
|
+
const data = new Uint8Array(buffer);
|
|
2779
|
+
setState({
|
|
2780
|
+
isLoading: false,
|
|
2781
|
+
data
|
|
2782
|
+
});
|
|
2783
|
+
} catch (error) {
|
|
2784
|
+
setState({
|
|
2785
|
+
isLoading: false,
|
|
2786
|
+
error: error instanceof Error ? error : new Error(
|
|
2787
|
+
"An unknown error occurred while loading this version"
|
|
2788
|
+
)
|
|
2789
|
+
});
|
|
2790
|
+
}
|
|
2791
|
+
};
|
|
2792
|
+
void load();
|
|
2793
|
+
}, [room, versionId]);
|
|
2794
|
+
return state;
|
|
2795
|
+
}
|
|
2796
|
+
function useHistoryVersions() {
|
|
2797
|
+
const client = useClient();
|
|
2798
|
+
const room = useRoom();
|
|
2799
|
+
const queryKey = getVersionsQueryKey(room.id);
|
|
2800
|
+
const { store, getRoomVersions } = getExtrasForClient2(client);
|
|
2801
|
+
React4.useEffect(() => {
|
|
2802
|
+
void getRoomVersions(room);
|
|
2803
|
+
}, [room]);
|
|
2804
|
+
const selector = React4.useCallback(
|
|
2805
|
+
(state2) => {
|
|
2806
|
+
const query = state2.queries[queryKey];
|
|
2807
|
+
if (query === void 0 || query.isLoading) {
|
|
2808
|
+
return {
|
|
2809
|
+
isLoading: true
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
return {
|
|
2813
|
+
versions: state2.versions[room.id],
|
|
2814
|
+
isLoading: false,
|
|
2815
|
+
error: query.error
|
|
2816
|
+
};
|
|
2817
|
+
},
|
|
2818
|
+
[room, queryKey]
|
|
2819
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
2820
|
+
);
|
|
2821
|
+
const state = useSyncExternalStoreWithSelector2(
|
|
2822
|
+
store.subscribe,
|
|
2823
|
+
store.get,
|
|
2824
|
+
store.get,
|
|
2825
|
+
selector
|
|
2826
|
+
);
|
|
2827
|
+
return state;
|
|
2828
|
+
}
|
|
2737
2829
|
function useUpdateRoomNotificationSettings() {
|
|
2738
2830
|
const client = useClient();
|
|
2739
2831
|
const room = useRoom();
|
|
@@ -2866,64 +2958,35 @@ function useThreadsSuspense(options = {
|
|
|
2866
2958
|
useScrollToCommentOnLoadEffect(scrollOnLoad, state);
|
|
2867
2959
|
return state;
|
|
2868
2960
|
}
|
|
2869
|
-
function
|
|
2870
|
-
|
|
2871
|
-
|
|
2961
|
+
function useHistoryVersionsSuspense() {
|
|
2962
|
+
const client = useClient();
|
|
2963
|
+
const room = useRoom();
|
|
2964
|
+
const queryKey = getVersionsQueryKey(room.id);
|
|
2965
|
+
const { store, getRoomVersions } = getExtrasForClient2(client);
|
|
2966
|
+
const query = store.get().queries[queryKey];
|
|
2967
|
+
if (query === void 0 || query.isLoading) {
|
|
2968
|
+
throw getRoomVersions(room);
|
|
2872
2969
|
}
|
|
2873
|
-
if (
|
|
2874
|
-
|
|
2970
|
+
if (query.error) {
|
|
2971
|
+
throw query.error;
|
|
2875
2972
|
}
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
}
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
const getAttachmentUrlState = React4.useCallback(
|
|
2886
|
-
() => attachmentUrlsStore.getState(attachmentId),
|
|
2887
|
-
[attachmentUrlsStore, attachmentId]
|
|
2973
|
+
const selector = React4.useCallback(
|
|
2974
|
+
(state2) => {
|
|
2975
|
+
return {
|
|
2976
|
+
versions: state2.versions[room.id],
|
|
2977
|
+
isLoading: false
|
|
2978
|
+
};
|
|
2979
|
+
},
|
|
2980
|
+
[room, queryKey]
|
|
2981
|
+
// eslint-disable-line react-hooks/exhaustive-deps
|
|
2888
2982
|
);
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
getAttachmentUrlState,
|
|
2895
|
-
getAttachmentUrlState,
|
|
2896
|
-
selectorFor_useAttachmentUrl,
|
|
2897
|
-
shallow2
|
|
2983
|
+
const state = useSyncExternalStoreWithSelector2(
|
|
2984
|
+
store.subscribe,
|
|
2985
|
+
store.get,
|
|
2986
|
+
store.get,
|
|
2987
|
+
selector
|
|
2898
2988
|
);
|
|
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
|
-
};
|
|
2989
|
+
return state;
|
|
2927
2990
|
}
|
|
2928
2991
|
function useRoomNotificationSettingsSuspense() {
|
|
2929
2992
|
const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
|
|
@@ -2966,6 +3029,9 @@ function createRoomContext(client) {
|
|
|
2966
3029
|
function generateQueryKey(roomId, options) {
|
|
2967
3030
|
return `${roomId}-${stringify(options ?? {})}`;
|
|
2968
3031
|
}
|
|
3032
|
+
function getVersionsQueryKey(roomId) {
|
|
3033
|
+
return `${roomId}-VERSIONS`;
|
|
3034
|
+
}
|
|
2969
3035
|
var _RoomProvider = RoomProvider;
|
|
2970
3036
|
var _useBroadcastEvent = useBroadcastEvent;
|
|
2971
3037
|
var _useOthersListener = useOthersListener;
|
|
@@ -2982,6 +3048,8 @@ var _useOthersMapped = useOthersMapped;
|
|
|
2982
3048
|
var _useOthersMappedSuspense = useOthersMappedSuspense;
|
|
2983
3049
|
var _useThreads = useThreads;
|
|
2984
3050
|
var _useThreadsSuspense = useThreadsSuspense;
|
|
3051
|
+
var _useHistoryVersions = useHistoryVersions;
|
|
3052
|
+
var _useHistoryVersionsSuspense = useHistoryVersionsSuspense;
|
|
2985
3053
|
var _useOther = useOther;
|
|
2986
3054
|
function _useOthers(...args) {
|
|
2987
3055
|
return useOthers(...args);
|
|
@@ -3030,11 +3098,10 @@ export {
|
|
|
3030
3098
|
useMarkThreadAsUnresolved,
|
|
3031
3099
|
useThreadSubscription,
|
|
3032
3100
|
useRoomNotificationSettings,
|
|
3101
|
+
useHistoryVersionData,
|
|
3033
3102
|
useUpdateRoomNotificationSettings,
|
|
3034
3103
|
useOthersConnectionIdsSuspense,
|
|
3035
3104
|
useStorageStatusSuspense,
|
|
3036
|
-
useAttachmentUrl,
|
|
3037
|
-
useAttachmentUrlSuspense,
|
|
3038
3105
|
createRoomContext,
|
|
3039
3106
|
_RoomProvider,
|
|
3040
3107
|
_useBroadcastEvent,
|
|
@@ -3052,6 +3119,8 @@ export {
|
|
|
3052
3119
|
_useOthersMappedSuspense,
|
|
3053
3120
|
_useThreads,
|
|
3054
3121
|
_useThreadsSuspense,
|
|
3122
|
+
_useHistoryVersions,
|
|
3123
|
+
_useHistoryVersionsSuspense,
|
|
3055
3124
|
_useOther,
|
|
3056
3125
|
_useOthers,
|
|
3057
3126
|
_useOtherSuspense,
|
|
@@ -3082,4 +3151,4 @@ export {
|
|
|
3082
3151
|
_useUserThreads_experimental,
|
|
3083
3152
|
_useUserThreadsSuspense_experimental
|
|
3084
3153
|
};
|
|
3085
|
-
//# sourceMappingURL=chunk-
|
|
3154
|
+
//# sourceMappingURL=chunk-EDJS5J5R.mjs.map
|