@liveblocks/react 2.0.5 → 2.1.1-test1

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,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
2
  import React__default, { ReactNode, PropsWithChildren } from 'react';
3
3
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, Client, BaseMetadata as BaseMetadata$1 } from '@liveblocks/client';
4
- import { BaseMetadata, CommentBody, Patchable, QueryMetadata, DRI, InboxNotificationData, Resolve, ToImmutable, ThreadData, LiveblocksError, RoomEventMessage, CommentData, PartialUnless, OpaqueClient, DU, ClientOptions, DM, OpaqueRoom, RoomNotificationSettings as RoomNotificationSettings$1, DP, DS, DE } from '@liveblocks/core';
4
+ import { BaseMetadata, CommentBody, Patchable, QueryMetadata, StorageStatus, DRI, InboxNotificationData, Resolve, ToImmutable, ThreadData, LiveblocksError, RoomEventMessage, CommentData, PartialUnless, OpaqueClient, DU, ClientOptions, DM, OpaqueRoom, RoomNotificationSettings as RoomNotificationSettings$1, DP, DS, DE } from '@liveblocks/core';
5
5
 
6
6
  declare type Props = {
7
7
  fallback: ReactNode;
@@ -26,6 +26,9 @@ declare type Props = {
26
26
  */
27
27
  declare function ClientSideSuspense(props: Props): React$1.JSX.Element;
28
28
 
29
+ /**
30
+ * @private Internal API, do not rely on it.
31
+ */
29
32
  declare class CreateThreadError<M extends BaseMetadata> extends Error {
30
33
  cause: Error;
31
34
  context: {
@@ -119,6 +122,7 @@ declare class UpdateNotificationSettingsError extends Error {
119
122
  }
120
123
  declare type CommentsError<M extends BaseMetadata> = CreateThreadError<M> | EditThreadMetadataError<M> | CreateCommentError | EditCommentError | DeleteCommentError | MarkInboxNotificationAsReadError | UpdateNotificationSettingsError;
121
124
 
125
+ declare type StorageStatusSuccess = Exclude<StorageStatus, "not-loaded" | "loading">;
122
126
  declare type UseThreadsOptions<M extends BaseMetadata> = {
123
127
  /**
124
128
  * The query (including metadata) to filter the threads by. If provided, only threads
@@ -461,8 +465,13 @@ declare type RoomContextBundleCommon<P extends JsonObject, S extends LsonObject,
461
465
  * useEventListener is a React hook that allows you to respond to events broadcast
462
466
  * by other users in the room.
463
467
  *
468
+ * The `user` argument will indicate which `User` instance sent the message.
469
+ * This will be equal to one of the others in the room, but it can be `null`
470
+ * in case this event was broadcasted from the server.
471
+ *
464
472
  * @example
465
- * useEventListener(({ connectionId, event }) => {
473
+ * useEventListener(({ event, user, connectionId }) => {
474
+ * // ^^^^ Will be Client A
466
475
  * if (event.type === "CUSTOM_EVENT") {
467
476
  * // Do something
468
477
  * }
@@ -537,10 +546,9 @@ declare type RoomContextBundleCommon<P extends JsonObject, S extends LsonObject,
537
546
  * The first argument that gets passed into your callback will be
538
547
  * a "mutation context", which exposes the following:
539
548
  *
540
- * - `root` - The mutable Storage root.
541
- * You can normal mutation on Live structures with this, for
542
- * example: root.get('layers').get('layer1').set('fill',
543
- * 'red')
549
+ * - `storage` - The mutable Storage root.
550
+ * You can mutate any Live structures with this, for example:
551
+ * `storage.get('layers').get('layer1').set('fill', 'red')`
544
552
  *
545
553
  * - `setMyPresence` - Call this with a new (partial) Presence value.
546
554
  *
@@ -554,11 +562,11 @@ declare type RoomContextBundleCommon<P extends JsonObject, S extends LsonObject,
554
562
  * that gets passed into your callback will be a "mutation context".
555
563
  *
556
564
  * If you want get access to the immutable root somewhere in your mutation,
557
- * you can use `root.ToImmutable()`.
565
+ * you can use `storage.ToImmutable()`.
558
566
  *
559
567
  * @example
560
568
  * const fillLayers = useMutation(
561
- * ({ root }, color: Color) => {
569
+ * ({ storage }, color: Color) => {
562
570
  * ...
563
571
  * },
564
572
  * [],
@@ -567,7 +575,7 @@ declare type RoomContextBundleCommon<P extends JsonObject, S extends LsonObject,
567
575
  * fillLayers('red');
568
576
  *
569
577
  * const deleteLayers = useMutation(
570
- * ({ root }) => {
578
+ * ({ storage }) => {
571
579
  * ...
572
580
  * },
573
581
  * [],
@@ -577,8 +585,8 @@ declare type RoomContextBundleCommon<P extends JsonObject, S extends LsonObject,
577
585
  */
578
586
  useMutation<F extends (context: MutationContext<P, S, U>, ...args: any[]) => any>(callback: F, deps: readonly unknown[]): OmitFirstArg<F>;
579
587
  /**
580
- * Returns an object that lets you get information about all the users
581
- * currently connected in the room.
588
+ * Returns an array with information about all the users currently connected
589
+ * in the room (except yourself).
582
590
  *
583
591
  * @example
584
592
  * const others = useOthers();
@@ -773,6 +781,12 @@ declare type PrivateRoomContextApi = {
773
781
  useCommentsErrorListener<M extends BaseMetadata>(callback: (err: CommentsError<M>) => void): void;
774
782
  };
775
783
  declare type RoomContextBundle<P extends JsonObject, S extends LsonObject, U extends BaseUserMeta, E extends Json, M extends BaseMetadata> = Resolve<RoomContextBundleCommon<P, S, U, E, M> & SharedContextBundle<U>["classic"] & {
784
+ /**
785
+ * Returns the current storage status for the Room, and triggers
786
+ * a re-render whenever it changes. Can be used to render a "Saving..."
787
+ * indicator.
788
+ */
789
+ useStorageStatus(): StorageStatus;
776
790
  /**
777
791
  * Extract arbitrary data from the Liveblocks Storage state, using an
778
792
  * arbitrary selector function.
@@ -798,7 +812,9 @@ declare type RoomContextBundle<P extends JsonObject, S extends LsonObject, U ext
798
812
  *
799
813
  * @example
800
814
  * const me = useSelf();
801
- * const { x, y } = me.presence.cursor;
815
+ * if (me !== null) {
816
+ * const { x, y } = me.presence.cursor;
817
+ * }
802
818
  */
803
819
  useSelf(): User<P, U> | null;
804
820
  /**
@@ -846,6 +862,12 @@ declare type RoomContextBundle<P extends JsonObject, S extends LsonObject, U ext
846
862
  (settings: Partial<RoomNotificationSettings>) => void
847
863
  ];
848
864
  suspense: Resolve<RoomContextBundleCommon<P, S, U, E, M> & SharedContextBundle<U>["suspense"] & {
865
+ /**
866
+ * Returns the current storage status for the Room, and triggers
867
+ * a re-render whenever it changes. Can be used to render a "Saving..."
868
+ * indicator.
869
+ */
870
+ useStorageStatus(): StorageStatusSuccess;
849
871
  /**
850
872
  * Extract arbitrary data from the Liveblocks Storage state, using an
851
873
  * arbitrary selector function.
@@ -888,13 +910,9 @@ declare type RoomContextBundle<P extends JsonObject, S extends LsonObject, U ext
888
910
  * the result of a .map() or .filter() call from the selector. In those
889
911
  * cases, you'll probably want to use a `shallow` comparison check.
890
912
  *
891
- * Will return `null` while Liveblocks isn't connected to a room yet.
892
- *
893
913
  * @example
894
914
  * const cursor = useSelf(me => me.presence.cursor);
895
- * if (cursor !== null) {
896
- * const { x, y } = cursor;
897
- * }
915
+ * const { x, y } = cursor;
898
916
  *
899
917
  */
900
918
  useSelf<T>(selector: (me: User<P, U>) => T, isEqual?: (prev: T, curr: T) => boolean): T;
@@ -1000,6 +1018,12 @@ declare type LiveblocksContextBundle<U extends BaseUserMeta, M extends BaseMetad
1000
1018
  }>;
1001
1019
  }>;
1002
1020
 
1021
+ /**
1022
+ * Raw access to the React context where the LiveblocksProvider stores the
1023
+ * current client. Exposed for advanced use cases only.
1024
+ *
1025
+ * @private This is a private/advanced API. Do not rely on it.
1026
+ */
1003
1027
  declare const ClientContext: React__default.Context<OpaqueClient | null>;
1004
1028
  /**
1005
1029
  * Obtains a reference to the current Liveblocks client.
@@ -1014,69 +1038,737 @@ declare function useClient<U extends BaseUserMeta>(): Client<U>;
1014
1038
  * and it should be placed higher in your app’s component tree.
1015
1039
  */
1016
1040
  declare function LiveblocksProvider<U extends BaseUserMeta = DU>(props: PropsWithChildren<ClientOptions<U>>): React__default.JSX.Element;
1041
+ /**
1042
+ * Creates a LiveblocksProvider and a set of typed hooks. Note that any
1043
+ * LiveblocksProvider created in this way takes no props, because it uses
1044
+ * settings from the given client instead.
1045
+ */
1017
1046
  declare function createLiveblocksContext<U extends BaseUserMeta = DU, M extends BaseMetadata$1 = DM>(client: OpaqueClient): LiveblocksContextBundle<U, M>;
1047
+ /**
1048
+ * @beta
1049
+ *
1050
+ * Returns the inbox notifications for the current user.
1051
+ *
1052
+ * @example
1053
+ * const { inboxNotifications, error, isLoading } = useInboxNotifications();
1054
+ */
1018
1055
  declare function useInboxNotifications(): InboxNotificationsState;
1056
+ /**
1057
+ * @beta
1058
+ *
1059
+ * Returns the inbox notifications for the current user.
1060
+ *
1061
+ * @example
1062
+ * const { inboxNotifications } = useInboxNotifications();
1063
+ */
1019
1064
  declare function useInboxNotificationsSuspense(): InboxNotificationsStateSuccess;
1065
+ /**
1066
+ * @beta
1067
+ *
1068
+ * Returns a function that marks all inbox notifications as read.
1069
+ *
1070
+ * @example
1071
+ * const markAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead();
1072
+ * markAllInboxNotificationsAsRead();
1073
+ */
1020
1074
  declare function useMarkAllInboxNotificationsAsRead(): () => void;
1075
+ /**
1076
+ * @beta
1077
+ *
1078
+ * Returns a function that marks an inbox notification as read.
1079
+ *
1080
+ * @example
1081
+ * const markInboxNotificationAsRead = useMarkInboxNotificationAsRead();
1082
+ * markInboxNotificationAsRead("in_xxx");
1083
+ */
1021
1084
  declare function useMarkInboxNotificationAsRead(): (inboxNotificationId: string) => void;
1085
+ /**
1086
+ * @beta
1087
+ *
1088
+ * Returns the number of unread inbox notifications for the current user.
1089
+ *
1090
+ * @example
1091
+ * const { count, error, isLoading } = useUnreadInboxNotificationsCount();
1092
+ */
1022
1093
  declare function useUnreadInboxNotificationsCount(): UnreadInboxNotificationsCountState;
1094
+ /**
1095
+ * @beta
1096
+ *
1097
+ * Returns the number of unread inbox notifications for the current user.
1098
+ *
1099
+ * @example
1100
+ * const { count } = useUnreadInboxNotificationsCount();
1101
+ */
1023
1102
  declare function useUnreadInboxNotificationsCountSuspense(): UnreadInboxNotificationsCountStateSuccess;
1103
+ /**
1104
+ * Returns room info from a given room ID.
1105
+ *
1106
+ * @example
1107
+ * const { info, error, isLoading } = useRoomInfo("room-id");
1108
+ */
1024
1109
  declare function useRoomInfo(roomId: string): RoomInfoState;
1110
+ /**
1111
+ * Returns room info from a given room ID.
1112
+ *
1113
+ * @example
1114
+ * const { info } = useRoomInfo("room-id");
1115
+ */
1025
1116
  declare function useRoomInfoSuspense(roomId: string): RoomInfoStateSuccess;
1026
- declare const __1: LiveblocksContextBundle<DU, DM>["useInboxNotificationThread"];
1027
- declare const __2: LiveblocksContextBundle<DU, DM>["useUser"];
1028
- declare const __3: LiveblocksContextBundle<DU, DM>["suspense"]["useUser"];
1117
+ declare type TypedBundle$1 = LiveblocksContextBundle<DU, DM>;
1118
+ /**
1119
+ * @beta
1120
+ *
1121
+ * Returns the thread associated with a `"thread"` inbox notification.
1122
+ *
1123
+ * @example
1124
+ * const thread = useInboxNotificationThread("in_xxx");
1125
+ */
1126
+ declare const _useInboxNotificationThread: TypedBundle$1["useInboxNotificationThread"];
1127
+ /**
1128
+ * Returns user info from a given user ID.
1129
+ *
1130
+ * @example
1131
+ * const { user, error, isLoading } = useUser("user-id");
1132
+ */
1133
+ declare const _useUser: TypedBundle$1["useUser"];
1134
+ /**
1135
+ * Returns user info from a given user ID.
1136
+ *
1137
+ * @example
1138
+ * const { user } = useUser("user-id");
1139
+ */
1140
+ declare const _useUserSuspense: TypedBundle$1["suspense"]["useUser"];
1029
1141
 
1142
+ /**
1143
+ * Raw access to the React context where the RoomProvider stores the current
1144
+ * room. Exposed for advanced use cases only.
1145
+ *
1146
+ * @private This is a private/advanced API. Do not rely on it.
1147
+ */
1030
1148
  declare const RoomContext: React$1.Context<OpaqueRoom | null>;
1149
+ /**
1150
+ * Returns the current connection status for the Room, and triggers
1151
+ * a re-render whenever it changes. Can be used to render a status badge.
1152
+ */
1031
1153
  declare function useStatus(): Status;
1154
+ /**
1155
+ * Returns the current storage status for the Room, and triggers
1156
+ * a re-render whenever it changes. Can be used to render a "Saving..."
1157
+ * indicator.
1158
+ */
1159
+ declare function useStorageStatus(): StorageStatus;
1160
+ /**
1161
+ * @deprecated It's recommended to use `useMutation` for writing to Storage,
1162
+ * which will automatically batch all mutations.
1163
+ *
1164
+ * Returns a function that batches modifications made during the given function.
1165
+ * All the modifications are sent to other clients in a single message.
1166
+ * All the modifications are merged in a single history item (undo/redo).
1167
+ * All the subscribers are called only after the batch is over.
1168
+ */
1032
1169
  declare function useBatch<T>(): (callback: () => T) => T;
1170
+ /**
1171
+ * Get informed when reconnecting to the Liveblocks servers is taking
1172
+ * longer than usual. This typically is a sign of a client that has lost
1173
+ * internet connectivity.
1174
+ *
1175
+ * This isn't problematic (because the Liveblocks client is still trying to
1176
+ * reconnect), but it's typically a good idea to inform users about it if
1177
+ * the connection takes too long to recover.
1178
+ *
1179
+ * @example
1180
+ * useLostConnectionListener(event => {
1181
+ * if (event === 'lost') {
1182
+ * toast.warn('Reconnecting to the Liveblocks servers is taking longer than usual...')
1183
+ * } else if (event === 'failed') {
1184
+ * toast.warn('Reconnecting to the Liveblocks servers failed.')
1185
+ * } else if (event === 'restored') {
1186
+ * toast.clear();
1187
+ * }
1188
+ * })
1189
+ */
1033
1190
  declare function useLostConnectionListener(callback: (event: LostConnectionEvent) => void): void;
1191
+ /**
1192
+ * useErrorListener is a React hook that allows you to respond to potential room
1193
+ * connection errors.
1194
+ *
1195
+ * @example
1196
+ * useErrorListener(er => {
1197
+ * console.error(er);
1198
+ * })
1199
+ */
1034
1200
  declare function useErrorListener(callback: (err: LiveblocksError) => void): void;
1201
+ /**
1202
+ * Returns the room.history
1203
+ */
1035
1204
  declare function useHistory(): History;
1205
+ /**
1206
+ * Returns a function that undoes the last operation executed by the current
1207
+ * client. It does not impact operations made by other clients.
1208
+ */
1036
1209
  declare function useUndo(): () => void;
1210
+ /**
1211
+ * Returns a function that redoes the last operation executed by the current
1212
+ * client. It does not impact operations made by other clients.
1213
+ */
1037
1214
  declare function useRedo(): () => void;
1215
+ /**
1216
+ * Returns whether there are any operations to undo.
1217
+ */
1038
1218
  declare function useCanUndo(): boolean;
1219
+ /**
1220
+ * Returns whether there are any operations to redo.
1221
+ */
1039
1222
  declare function useCanRedo(): boolean;
1223
+ /**
1224
+ * Returns an array of connection IDs. This matches the values you'll get by
1225
+ * using the `useOthers()` hook.
1226
+ *
1227
+ * Roughly equivalent to:
1228
+ * useOthers((others) => others.map(other => other.connectionId), shallow)
1229
+ *
1230
+ * This is useful in particular to implement efficiently rendering components
1231
+ * for each user in the room, e.g. cursors.
1232
+ *
1233
+ * @example
1234
+ * const ids = useOthersConnectionIds();
1235
+ * // [2, 4, 7]
1236
+ */
1040
1237
  declare function useOthersConnectionIds(): readonly number[];
1238
+ /**
1239
+ * @private Internal API, do not rely on it.
1240
+ */
1041
1241
  declare function useCommentsErrorListener<M extends BaseMetadata$1>(callback: (error: CommentsError<M>) => void): void;
1242
+ /**
1243
+ * Returns a function that adds a comment to a thread.
1244
+ *
1245
+ * @example
1246
+ * const createComment = useCreateComment();
1247
+ * createComment({ threadId: "th_xxx", body: {} });
1248
+ */
1042
1249
  declare function useCreateComment(): (options: CreateCommentOptions) => CommentData;
1250
+ /**
1251
+ * Returns a function that edits a comment's body.
1252
+ *
1253
+ * @example
1254
+ * const editComment = useEditComment()
1255
+ * editComment({ threadId: "th_xxx", commentId: "cm_xxx", body: {} })
1256
+ */
1043
1257
  declare function useEditComment(): (options: EditCommentOptions) => void;
1258
+ /**
1259
+ * Returns a function that deletes a comment.
1260
+ * If it is the last non-deleted comment, the thread also gets deleted.
1261
+ *
1262
+ * @example
1263
+ * const deleteComment = useDeleteComment();
1264
+ * deleteComment({ threadId: "th_xxx", commentId: "cm_xxx" })
1265
+ */
1044
1266
  declare function useDeleteComment(): ({ threadId, commentId }: DeleteCommentOptions) => void;
1267
+ /**
1268
+ * Returns a function that removes a reaction on a comment.
1269
+ *
1270
+ * @example
1271
+ * const removeReaction = useRemoveReaction();
1272
+ * removeReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
1273
+ */
1045
1274
  declare function useRemoveReaction(): ({ threadId, commentId, emoji }: CommentReactionOptions) => void;
1275
+ /**
1276
+ * Returns a function that marks a thread as read.
1277
+ *
1278
+ * @example
1279
+ * const markThreadAsRead = useMarkThreadAsRead();
1280
+ * markThreadAsRead("th_xxx");
1281
+ */
1046
1282
  declare function useMarkThreadAsRead(): (threadId: string) => void;
1283
+ /**
1284
+ * Returns the subscription status of a thread.
1285
+ *
1286
+ * @example
1287
+ * const { status, unreadSince } = useThreadSubscription("th_xxx");
1288
+ */
1047
1289
  declare function useThreadSubscription(threadId: string): ThreadSubscription;
1290
+ /**
1291
+ * @beta
1292
+ *
1293
+ * Returns the user's notification settings for the current room
1294
+ * and a function to update them.
1295
+ *
1296
+ * @example
1297
+ * const [{ settings }, updateSettings] = useRoomNotificationSettings();
1298
+ */
1048
1299
  declare function useRoomNotificationSettings(): [
1049
1300
  RoomNotificationSettingsState,
1050
1301
  (settings: Partial<RoomNotificationSettings$1>) => void
1051
1302
  ];
1303
+ /**
1304
+ * @beta
1305
+ *
1306
+ * Returns a function that updates the user's notification settings
1307
+ * for the current room.
1308
+ *
1309
+ * @example
1310
+ * const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
1311
+ * updateRoomNotificationSettings({ threads: "all" });
1312
+ */
1052
1313
  declare function useUpdateRoomNotificationSettings(): (settings: Partial<RoomNotificationSettings$1>) => void;
1314
+ /**
1315
+ * Returns an array of connection IDs. This matches the values you'll get by
1316
+ * using the `useOthers()` hook.
1317
+ *
1318
+ * Roughly equivalent to:
1319
+ * useOthers((others) => others.map(other => other.connectionId), shallow)
1320
+ *
1321
+ * This is useful in particular to implement efficiently rendering components
1322
+ * for each user in the room, e.g. cursors.
1323
+ *
1324
+ * @example
1325
+ * const ids = useOthersConnectionIds();
1326
+ * // [2, 4, 7]
1327
+ */
1053
1328
  declare function useOthersConnectionIdsSuspense(): readonly number[];
1329
+ /**
1330
+ * Returns the current storage status for the Room, and triggers
1331
+ * a re-render whenever it changes. Can be used to render a "Saving..."
1332
+ * indicator.
1333
+ */
1334
+ declare function useStorageStatusSuspense(): StorageStatusSuccess;
1335
+ /**
1336
+ * Creates a RoomProvider and a set of typed hooks to use in your app. Note
1337
+ * that any RoomProvider created in this way does not need to be nested in
1338
+ * LiveblocksProvider, as it already has access to the client.
1339
+ */
1054
1340
  declare function createRoomContext<P extends JsonObject = DP, S extends LsonObject = DS, U extends BaseUserMeta = DU, E extends Json = DE, M extends BaseMetadata$1 = DM>(client: OpaqueClient): RoomContextBundle<P, S, U, E, M>;
1055
- declare type DefaultRoomContextBundle = RoomContextBundle<DP, DS, DU, DE, DM>;
1056
- declare const _RoomProvider: DefaultRoomContextBundle["RoomProvider"];
1057
- declare const _useBroadcastEvent: DefaultRoomContextBundle["useBroadcastEvent"];
1058
- declare const _useOthersListener: DefaultRoomContextBundle["useOthersListener"];
1059
- declare const _useRoom: DefaultRoomContextBundle["useRoom"];
1060
- declare const _useAddReaction: DefaultRoomContextBundle["useAddReaction"];
1061
- declare const _useMutation: DefaultRoomContextBundle["useMutation"];
1062
- declare const _useCreateThread: DefaultRoomContextBundle["useCreateThread"];
1063
- declare const _useDeleteThread: DefaultRoomContextBundle["useDeleteThread"];
1064
- declare const _useEditThreadMetadata: DefaultRoomContextBundle["useEditThreadMetadata"];
1065
- declare const _useEventListener: DefaultRoomContextBundle["useEventListener"];
1066
- declare const _useMyPresence: DefaultRoomContextBundle["useMyPresence"];
1067
- declare const _useOthersMapped: DefaultRoomContextBundle["useOthersMapped"];
1068
- declare const _useOthersMappedSuspense: DefaultRoomContextBundle["suspense"]["useOthersMapped"];
1069
- declare const _useThreads: DefaultRoomContextBundle["useThreads"];
1070
- declare const _useThreadsSuspense: DefaultRoomContextBundle["suspense"]["useThreads"];
1071
- declare const _useOther: DefaultRoomContextBundle["useOther"];
1072
- declare const _useOthers: DefaultRoomContextBundle["useOthers"];
1073
- declare const _useOtherSuspense: DefaultRoomContextBundle["suspense"]["useOther"];
1074
- declare const _useOthersSuspense: DefaultRoomContextBundle["suspense"]["useOthers"];
1075
- declare const _useStorage: DefaultRoomContextBundle["useStorage"];
1076
- declare const _useStorageSuspense: DefaultRoomContextBundle["suspense"]["useStorage"];
1077
- declare const _useSelf: DefaultRoomContextBundle["useSelf"];
1078
- declare const _useSelfSuspense: DefaultRoomContextBundle["suspense"]["useSelf"];
1079
- declare const _useStorageRoot: DefaultRoomContextBundle["useStorageRoot"];
1080
- declare const _useUpdateMyPresence: DefaultRoomContextBundle["useUpdateMyPresence"];
1341
+ declare type TypedBundle = RoomContextBundle<DP, DS, DU, DE, DM>;
1342
+ /**
1343
+ * Makes a Room available in the component hierarchy below.
1344
+ * Joins the room when the component is mounted, and automatically leaves
1345
+ * the room when the component is unmounted.
1346
+ */
1347
+ declare const _RoomProvider: TypedBundle["RoomProvider"];
1348
+ /**
1349
+ * Returns a callback that lets you broadcast custom events to other users in the room
1350
+ *
1351
+ * @example
1352
+ * const broadcast = useBroadcastEvent();
1353
+ *
1354
+ * broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
1355
+ */
1356
+ declare const _useBroadcastEvent: TypedBundle["useBroadcastEvent"];
1357
+ /**
1358
+ * Get informed when users enter or leave the room, as an event.
1359
+ *
1360
+ * @example
1361
+ * useOthersListener({ type, user, others }) => {
1362
+ * if (type === 'enter') {
1363
+ * // `user` has joined the room
1364
+ * } else if (type === 'leave') {
1365
+ * // `user` has left the room
1366
+ * }
1367
+ * })
1368
+ */
1369
+ declare const _useOthersListener: TypedBundle["useOthersListener"];
1370
+ /**
1371
+ * Returns the Room of the nearest RoomProvider above in the React component
1372
+ * tree.
1373
+ */
1374
+ declare const _useRoom: TypedBundle["useRoom"];
1375
+ /**
1376
+ * Returns a function that adds a reaction from a comment.
1377
+ *
1378
+ * @example
1379
+ * const addReaction = useAddReaction();
1380
+ * addReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
1381
+ */
1382
+ declare const _useAddReaction: TypedBundle["useAddReaction"];
1383
+ /**
1384
+ * Create a callback function that lets you mutate Liveblocks state.
1385
+ *
1386
+ * The first argument that gets passed into your callback will be
1387
+ * a "mutation context", which exposes the following:
1388
+ *
1389
+ * - `storage` - The mutable Storage root.
1390
+ * You can mutate any Live structures with this, for example:
1391
+ * `storage.get('layers').get('layer1').set('fill', 'red')`
1392
+ *
1393
+ * - `setMyPresence` - Call this with a new (partial) Presence value.
1394
+ *
1395
+ * - `self` - A read-only version of the latest self, if you need it to
1396
+ * compute the next state.
1397
+ *
1398
+ * - `others` - A read-only version of the latest others list, if you
1399
+ * need it to compute the next state.
1400
+ *
1401
+ * useMutation is like React's useCallback, except that the first argument
1402
+ * that gets passed into your callback will be a "mutation context".
1403
+ *
1404
+ * If you want get access to the immutable root somewhere in your mutation,
1405
+ * you can use `storage.ToImmutable()`.
1406
+ *
1407
+ * @example
1408
+ * const fillLayers = useMutation(
1409
+ * ({ storage }, color: Color) => {
1410
+ * ...
1411
+ * },
1412
+ * [],
1413
+ * );
1414
+ *
1415
+ * fillLayers('red');
1416
+ *
1417
+ * const deleteLayers = useMutation(
1418
+ * ({ storage }) => {
1419
+ * ...
1420
+ * },
1421
+ * [],
1422
+ * );
1423
+ *
1424
+ * deleteLayers();
1425
+ */
1426
+ declare const _useMutation: TypedBundle["useMutation"];
1427
+ /**
1428
+ * Returns a function that creates a thread with an initial comment, and optionally some metadata.
1429
+ *
1430
+ * @example
1431
+ * const createThread = useCreateThread();
1432
+ * createThread({ body: {}, metadata: {} });
1433
+ */
1434
+ declare const _useCreateThread: TypedBundle["useCreateThread"];
1435
+ /**
1436
+ * Returns a function that deletes a thread and its associated comments.
1437
+ * Only the thread creator can delete a thread, it will throw otherwise.
1438
+ *
1439
+ * @example
1440
+ * const deleteThread = useDeleteThread();
1441
+ * deleteThread("th_xxx");
1442
+ */
1443
+ declare const _useDeleteThread: TypedBundle["useDeleteThread"];
1444
+ /**
1445
+ * Returns a function that edits a thread's metadata.
1446
+ * To delete an existing metadata property, set its value to `null`.
1447
+ *
1448
+ * @example
1449
+ * const editThreadMetadata = useEditThreadMetadata();
1450
+ * editThreadMetadata({ threadId: "th_xxx", metadata: {} })
1451
+ */
1452
+ declare const _useEditThreadMetadata: TypedBundle["useEditThreadMetadata"];
1453
+ /**
1454
+ * useEventListener is a React hook that allows you to respond to events broadcast
1455
+ * by other users in the room.
1456
+ *
1457
+ * The `user` argument will indicate which `User` instance sent the message.
1458
+ * This will be equal to one of the others in the room, but it can be `null`
1459
+ * in case this event was broadcasted from the server.
1460
+ *
1461
+ * @example
1462
+ * useEventListener(({ event, user, connectionId }) => {
1463
+ * // ^^^^ Will be Client A
1464
+ * if (event.type === "CUSTOM_EVENT") {
1465
+ * // Do something
1466
+ * }
1467
+ * });
1468
+ */
1469
+ declare const _useEventListener: TypedBundle["useEventListener"];
1470
+ /**
1471
+ * Returns the presence of the current user of the current room, and a function to update it.
1472
+ * It is different from the setState function returned by the useState hook from React.
1473
+ * You don't need to pass the full presence object to update it.
1474
+ *
1475
+ * @example
1476
+ * const [myPresence, updateMyPresence] = useMyPresence();
1477
+ * updateMyPresence({ x: 0 });
1478
+ * updateMyPresence({ y: 0 });
1479
+ *
1480
+ * // At the next render, "myPresence" will be equal to "{ x: 0, y: 0 }"
1481
+ */
1482
+ declare const _useMyPresence: TypedBundle["useMyPresence"];
1483
+ /**
1484
+ * Related to useOthers(), but optimized for selecting only "subsets" of
1485
+ * others. This is useful for performance reasons in particular, because
1486
+ * selecting only a subset of users also means limiting the number of
1487
+ * re-renders that will be triggered.
1488
+ *
1489
+ * @example
1490
+ * const avatars = useOthersMapped(user => user.info.avatar);
1491
+ * // ^^^^^^^
1492
+ * // { connectionId: number; data: string }[]
1493
+ *
1494
+ * The selector function you pass to useOthersMapped() is called an "item
1495
+ * selector", and operates on a single user at a time. If you provide an
1496
+ * (optional) "item comparison" function, it will be used to compare each
1497
+ * item pairwise.
1498
+ *
1499
+ * For example, to select multiple properties:
1500
+ *
1501
+ * @example
1502
+ * const avatarsAndCursors = useOthersMapped(
1503
+ * user => [u.info.avatar, u.presence.cursor],
1504
+ * shallow, // 👈
1505
+ * );
1506
+ */
1507
+ declare const _useOthersMapped: TypedBundle["useOthersMapped"];
1508
+ /**
1509
+ * Related to useOthers(), but optimized for selecting only "subsets" of
1510
+ * others. This is useful for performance reasons in particular, because
1511
+ * selecting only a subset of users also means limiting the number of
1512
+ * re-renders that will be triggered.
1513
+ *
1514
+ * @example
1515
+ * const avatars = useOthersMapped(user => user.info.avatar);
1516
+ * // ^^^^^^^
1517
+ * // { connectionId: number; data: string }[]
1518
+ *
1519
+ * The selector function you pass to useOthersMapped() is called an "item
1520
+ * selector", and operates on a single user at a time. If you provide an
1521
+ * (optional) "item comparison" function, it will be used to compare each
1522
+ * item pairwise.
1523
+ *
1524
+ * For example, to select multiple properties:
1525
+ *
1526
+ * @example
1527
+ * const avatarsAndCursors = useOthersMapped(
1528
+ * user => [u.info.avatar, u.presence.cursor],
1529
+ * shallow, // 👈
1530
+ * );
1531
+ */
1532
+ declare const _useOthersMappedSuspense: TypedBundle["suspense"]["useOthersMapped"];
1533
+ /**
1534
+ * Returns the threads within the current room.
1535
+ *
1536
+ * @example
1537
+ * const { threads, error, isLoading } = useThreads();
1538
+ */
1539
+ declare const _useThreads: TypedBundle["useThreads"];
1540
+ /**
1541
+ * Returns the threads within the current room.
1542
+ *
1543
+ * @example
1544
+ * const { threads } = useThreads();
1545
+ */
1546
+ declare const _useThreadsSuspense: TypedBundle["suspense"]["useThreads"];
1547
+ /**
1548
+ * Given a connection ID (as obtained by using `useOthersConnectionIds`), you
1549
+ * can call this selector deep down in your component stack to only have the
1550
+ * component re-render if properties for this particular user change.
1551
+ *
1552
+ * @example
1553
+ * // Returns only the selected values re-renders whenever that selection changes)
1554
+ * const { x, y } = useOther(2, user => user.presence.cursor);
1555
+ */
1556
+ declare const _useOther: TypedBundle["useOther"];
1557
+ /**
1558
+ * Returns an array with information about all the users currently connected in
1559
+ * the room (except yourself).
1560
+ *
1561
+ * @example
1562
+ * const others = useOthers();
1563
+ *
1564
+ * // Example to map all cursors in JSX
1565
+ * return (
1566
+ * <>
1567
+ * {others.map((user) => {
1568
+ * if (user.presence.cursor == null) {
1569
+ * return null;
1570
+ * }
1571
+ * return <Cursor key={user.connectionId} cursor={user.presence.cursor} />
1572
+ * })}
1573
+ * </>
1574
+ * )
1575
+ */
1576
+ declare function _useOthers(): readonly User<DP, DU>[];
1577
+ /**
1578
+ * Extract arbitrary data based on all the users currently connected in the
1579
+ * room (except yourself).
1580
+ *
1581
+ * The selector function will get re-evaluated any time a user enters or
1582
+ * leaves the room, as well as whenever their presence data changes.
1583
+ *
1584
+ * The component that uses this hook will automatically re-render if your
1585
+ * selector function returns a different value from its previous run.
1586
+ *
1587
+ * By default `useOthers()` uses strict `===` to check for equality. Take
1588
+ * extra care when returning a computed object or list, for example when you
1589
+ * return the result of a .map() or .filter() call from the selector. In
1590
+ * those cases, you'll probably want to use a `shallow` comparison check.
1591
+ *
1592
+ * @example
1593
+ * const avatars = useOthers(users => users.map(u => u.info.avatar), shallow);
1594
+ * const cursors = useOthers(users => users.map(u => u.presence.cursor), shallow);
1595
+ * const someoneIsTyping = useOthers(users => users.some(u => u.presence.isTyping));
1596
+ *
1597
+ */
1598
+ declare function _useOthers<T>(selector: (others: readonly User<DP, DU>[]) => T, isEqual?: (prev: T, curr: T) => boolean): T;
1599
+ /**
1600
+ * Given a connection ID (as obtained by using `useOthersConnectionIds`), you
1601
+ * can call this selector deep down in your component stack to only have the
1602
+ * component re-render if properties for this particular user change.
1603
+ *
1604
+ * @example
1605
+ * // Returns only the selected values re-renders whenever that selection changes)
1606
+ * const { x, y } = useOther(2, user => user.presence.cursor);
1607
+ */
1608
+ declare const _useOtherSuspense: TypedBundle["suspense"]["useOther"];
1609
+ /**
1610
+ * Returns an array with information about all the users currently connected in
1611
+ * the room (except yourself).
1612
+ *
1613
+ * @example
1614
+ * const others = useOthers();
1615
+ *
1616
+ * // Example to map all cursors in JSX
1617
+ * return (
1618
+ * <>
1619
+ * {others.map((user) => {
1620
+ * if (user.presence.cursor == null) {
1621
+ * return null;
1622
+ * }
1623
+ * return <Cursor key={user.connectionId} cursor={user.presence.cursor} />
1624
+ * })}
1625
+ * </>
1626
+ * )
1627
+ */
1628
+ declare function _useOthersSuspense(): readonly User<DP, DU>[];
1629
+ /**
1630
+ * Extract arbitrary data based on all the users currently connected in the
1631
+ * room (except yourself).
1632
+ *
1633
+ * The selector function will get re-evaluated any time a user enters or
1634
+ * leaves the room, as well as whenever their presence data changes.
1635
+ *
1636
+ * The component that uses this hook will automatically re-render if your
1637
+ * selector function returns a different value from its previous run.
1638
+ *
1639
+ * By default `useOthers()` uses strict `===` to check for equality. Take
1640
+ * extra care when returning a computed object or list, for example when you
1641
+ * return the result of a .map() or .filter() call from the selector. In
1642
+ * those cases, you'll probably want to use a `shallow` comparison check.
1643
+ *
1644
+ * @example
1645
+ * const avatars = useOthers(users => users.map(u => u.info.avatar), shallow);
1646
+ * const cursors = useOthers(users => users.map(u => u.presence.cursor), shallow);
1647
+ * const someoneIsTyping = useOthers(users => users.some(u => u.presence.isTyping));
1648
+ *
1649
+ */
1650
+ declare function _useOthersSuspense<T>(selector: (others: readonly User<DP, DU>[]) => T, isEqual?: (prev: T, curr: T) => boolean): T;
1651
+ /**
1652
+ * Extract arbitrary data from the Liveblocks Storage state, using an
1653
+ * arbitrary selector function.
1654
+ *
1655
+ * The selector function will get re-evaluated any time something changes in
1656
+ * Storage. The value returned by your selector function will also be the
1657
+ * value returned by the hook.
1658
+ *
1659
+ * The `root` value that gets passed to your selector function is
1660
+ * a immutable/readonly version of your Liveblocks storage root.
1661
+ *
1662
+ * The component that uses this hook will automatically re-render if the
1663
+ * returned value changes.
1664
+ *
1665
+ * By default `useStorage()` uses strict `===` to check for equality. Take
1666
+ * extra care when returning a computed object or list, for example when you
1667
+ * return the result of a .map() or .filter() call from the selector. In
1668
+ * those cases, you'll probably want to use a `shallow` comparison check.
1669
+ */
1670
+ declare const _useStorage: TypedBundle["useStorage"];
1671
+ /**
1672
+ * Extract arbitrary data from the Liveblocks Storage state, using an
1673
+ * arbitrary selector function.
1674
+ *
1675
+ * The selector function will get re-evaluated any time something changes in
1676
+ * Storage. The value returned by your selector function will also be the
1677
+ * value returned by the hook.
1678
+ *
1679
+ * The `root` value that gets passed to your selector function is
1680
+ * a immutable/readonly version of your Liveblocks storage root.
1681
+ *
1682
+ * The component that uses this hook will automatically re-render if the
1683
+ * returned value changes.
1684
+ *
1685
+ * By default `useStorage()` uses strict `===` to check for equality. Take
1686
+ * extra care when returning a computed object or list, for example when you
1687
+ * return the result of a .map() or .filter() call from the selector. In
1688
+ * those cases, you'll probably want to use a `shallow` comparison check.
1689
+ */
1690
+ declare const _useStorageSuspense: TypedBundle["suspense"]["useStorage"];
1691
+ /**
1692
+ * Gets the current user once it is connected to the room.
1693
+ *
1694
+ * @example
1695
+ * const me = useSelf();
1696
+ * if (me !== null) {
1697
+ * const { x, y } = me.presence.cursor;
1698
+ * }
1699
+ */
1700
+ declare function _useSelf(): User<DP, DU> | null;
1701
+ /**
1702
+ * Extract arbitrary data based on the current user.
1703
+ *
1704
+ * The selector function will get re-evaluated any time your presence data
1705
+ * changes.
1706
+ *
1707
+ * The component that uses this hook will automatically re-render if your
1708
+ * selector function returns a different value from its previous run.
1709
+ *
1710
+ * By default `useSelf()` uses strict `===` to check for equality. Take extra
1711
+ * care when returning a computed object or list, for example when you return
1712
+ * the result of a .map() or .filter() call from the selector. In those
1713
+ * cases, you'll probably want to use a `shallow` comparison check.
1714
+ *
1715
+ * Will return `null` while Liveblocks isn't connected to a room yet.
1716
+ *
1717
+ * @example
1718
+ * const cursor = useSelf(me => me.presence.cursor);
1719
+ * if (cursor !== null) {
1720
+ * const { x, y } = cursor;
1721
+ * }
1722
+ *
1723
+ */
1724
+ declare function _useSelf<T>(selector: (me: User<DP, DU>) => T, isEqual?: (prev: T, curr: T) => boolean): T | null;
1725
+ /**
1726
+ * Gets the current user once it is connected to the room.
1727
+ *
1728
+ * @example
1729
+ * const me = useSelf();
1730
+ * const { x, y } = me.presence.cursor;
1731
+ */
1732
+ declare function _useSelfSuspense(): User<DP, DU>;
1733
+ /**
1734
+ * Extract arbitrary data based on the current user.
1735
+ *
1736
+ * The selector function will get re-evaluated any time your presence data
1737
+ * changes.
1738
+ *
1739
+ * The component that uses this hook will automatically re-render if your
1740
+ * selector function returns a different value from its previous run.
1741
+ *
1742
+ * By default `useSelf()` uses strict `===` to check for equality. Take extra
1743
+ * care when returning a computed object or list, for example when you return
1744
+ * the result of a .map() or .filter() call from the selector. In those
1745
+ * cases, you'll probably want to use a `shallow` comparison check.
1746
+ *
1747
+ * @example
1748
+ * const cursor = useSelf(me => me.presence.cursor);
1749
+ * const { x, y } = cursor;
1750
+ *
1751
+ */
1752
+ declare function _useSelfSuspense<T>(selector: (me: User<DP, DU>) => T, isEqual?: (prev: T, curr: T) => boolean): T;
1753
+ /**
1754
+ * Returns the mutable (!) Storage root. This hook exists for
1755
+ * backward-compatible reasons.
1756
+ *
1757
+ * @example
1758
+ * const [root] = useStorageRoot();
1759
+ */
1760
+ declare const _useStorageRoot: TypedBundle["useStorageRoot"];
1761
+ /**
1762
+ * useUpdateMyPresence is similar to useMyPresence but it only returns the function to update the current user presence.
1763
+ * If you don't use the current user presence in your component, but you need to update it (e.g. live cursor), it's better to use useUpdateMyPresence to avoid unnecessary renders.
1764
+ *
1765
+ * @example
1766
+ * const updateMyPresence = useUpdateMyPresence();
1767
+ * updateMyPresence({ x: 0 });
1768
+ * updateMyPresence({ y: 0 });
1769
+ *
1770
+ * // At the next render, the presence of the current user will be equal to "{ x: 0, y: 0 }"
1771
+ */
1772
+ declare const _useUpdateMyPresence: TypedBundle["useUpdateMyPresence"];
1081
1773
 
1082
- export { useUnreadInboxNotificationsCount as $, useRedo as A, useRemoveReaction as B, ClientSideSuspense as C, _useRoom as D, useRoomNotificationSettings as E, useStatus as F, _useStorageRoot as G, useThreadSubscription as H, useUndo as I, _useUpdateMyPresence as J, useUpdateRoomNotificationSettings as K, LiveblocksProvider as L, type MutationContext as M, useCommentsErrorListener as N, CreateThreadError as O, _useOther as P, _useOthers as Q, RoomContext as R, useOthersConnectionIds as S, _useOthersMapped as T, type UseThreadsOptions as U, _useSelf as V, _useStorage as W, _useThreads as X, useInboxNotifications as Y, useRoomInfo as Z, __1 as _, ClientContext as a, __2 as a0, _useOtherSuspense as a1, _useOthersSuspense as a2, useOthersConnectionIdsSuspense as a3, _useOthersMappedSuspense as a4, _useSelfSuspense as a5, _useStorageSuspense as a6, _useThreadsSuspense as a7, useInboxNotificationsSuspense as a8, useRoomInfoSuspense as a9, useUnreadInboxNotificationsCountSuspense as aa, __3 as ab, useMarkAllInboxNotificationsAsRead as b, createLiveblocksContext as c, useMarkInboxNotificationAsRead as d, createRoomContext as e, _RoomProvider as f, _useAddReaction as g, useBatch as h, _useBroadcastEvent as i, useCanRedo as j, useCanUndo as k, useCreateComment as l, _useCreateThread as m, _useDeleteThread as n, useDeleteComment as o, useEditComment as p, _useEditThreadMetadata as q, useErrorListener as r, _useEventListener as s, useHistory as t, useClient as u, useLostConnectionListener as v, useMarkThreadAsRead as w, _useMutation as x, _useMyPresence as y, _useOthersListener as z };
1774
+ export { useRoomInfo as $, useRedo as A, useRemoveReaction as B, ClientSideSuspense as C, _useRoom as D, useRoomNotificationSettings as E, useStatus as F, _useStorageRoot as G, useThreadSubscription as H, useUndo as I, _useUpdateMyPresence as J, useUpdateRoomNotificationSettings as K, LiveblocksProvider as L, type MutationContext as M, useCommentsErrorListener as N, CreateThreadError as O, _useOther as P, _useOthers as Q, RoomContext as R, useOthersConnectionIds as S, _useOthersMapped as T, type UseThreadsOptions as U, _useSelf as V, _useStorage as W, useStorageStatus as X, _useThreads as Y, useInboxNotifications as Z, _useInboxNotificationThread as _, ClientContext as a, useUnreadInboxNotificationsCount as a0, _useUser as a1, _useOtherSuspense as a2, _useOthersSuspense as a3, useOthersConnectionIdsSuspense as a4, _useOthersMappedSuspense as a5, _useSelfSuspense as a6, _useStorageSuspense as a7, useStorageStatusSuspense as a8, _useThreadsSuspense as a9, useInboxNotificationsSuspense as aa, useRoomInfoSuspense as ab, useUnreadInboxNotificationsCountSuspense as ac, _useUserSuspense as ad, useMarkAllInboxNotificationsAsRead as b, createLiveblocksContext as c, useMarkInboxNotificationAsRead as d, createRoomContext as e, _RoomProvider as f, _useAddReaction as g, useBatch as h, _useBroadcastEvent as i, useCanRedo as j, useCanUndo as k, useCreateComment as l, _useCreateThread as m, useDeleteComment as n, _useDeleteThread as o, useEditComment as p, _useEditThreadMetadata as q, useErrorListener as r, _useEventListener as s, useHistory as t, useClient as u, useLostConnectionListener as v, useMarkThreadAsRead as w, _useMutation as x, _useMyPresence as y, _useOthersListener as z };