@liveblocks/react 1.12.0 → 2.0.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,1097 +1,4 @@
1
- import { ReactElement, ReactNode, PropsWithChildren } from 'react';
2
- import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Json, RoomNotificationSettings, Room, Status, BroadcastOptions, OthersEvent, LostConnectionEvent, History, BaseMetadata as BaseMetadata$1, Client } from '@liveblocks/client';
1
+ export { a as ClientContext, C as ClientSideSuspense, L as LiveblocksProvider, M as MutationContext, R as RoomContext, f as RoomProvider, U as UseThreadsOptions, c as createLiveblocksContext, e as createRoomContext, g as useAddReaction, h as useBatch, i as useBroadcastEvent, j as useCanRedo, k as useCanUndo, u as useClient, l as useCreateComment, m as useCreateThread, n as useDeleteComment, o as useEditComment, p as useEditThreadMetadata, q as useErrorListener, r as useEventListener, s as useHistory, _ as useInboxNotificationThread, V as useInboxNotifications, t as useLostConnectionListener, b as useMarkAllInboxNotificationsAsRead, d as useMarkInboxNotificationAsRead, v as useMarkThreadAsRead, w as useMutation, x as useMyPresence, K as useOther, N as useOthers, O as useOthersConnectionIds, y as useOthersListener, P as useOthersMapped, z as useRedo, A as useRemoveReaction, B as useRoom, W as useRoomInfo, D as useRoomNotificationSettings, Q as useSelf, E as useStatus, S as useStorage, F as useStorageRoot, G as useThreadSubscription, T as useThreads, H as useUndo, X as useUnreadInboxNotificationsCount, I as useUpdateMyPresence, J as useUpdateRoomNotificationSettings, Y as useUser } from './suspense-9ZocWu4y.mjs';
3
2
  export { Json, JsonObject, shallow } from '@liveblocks/client';
4
- import * as _liveblocks_core from '@liveblocks/core';
5
- import { BaseMetadata, QueryMetadata, Resolve, ToImmutable, kInternal, ThreadData, InboxNotificationData, LiveblocksError, RoomEventMessage, CommentData, RoomInfo, CommentBody, PartialNullable, RoomInitializers, ResolveUsersArgs, OptionalPromise, ResolveMentionSuggestionsArgs, BaseUserMeta as BaseUserMeta$1 } from '@liveblocks/core';
6
-
7
- declare type Props = {
8
- fallback: NonNullable<ReactNode> | null;
9
- children: () => ReactNode | undefined;
10
- };
11
- /**
12
- * Almost like a normal <Suspense> component, except that for server-side
13
- * renders, the fallback will be used.
14
- *
15
- * The child props will have to be provided in a function, i.e. change:
16
- *
17
- * <Suspense fallback={<Loading />}>
18
- * <MyRealComponent a={1} />
19
- * </Suspense>
20
- *
21
- * To:
22
- *
23
- * <ClientSideSuspense fallback={<Loading />}>
24
- * {() => <MyRealComponent a={1} />}
25
- * </ClientSideSuspense>
26
- *
27
- */
28
- declare function ClientSideSuspense(props: Props): ReactElement;
29
-
30
- declare type UseThreadsOptions<TThreadMetadata extends BaseMetadata> = {
31
- /**
32
- * The query (including metadata) to filter the threads by. If provided, only threads
33
- * that match the query will be returned. If not provided, all threads will be returned.
34
- */
35
- query?: {
36
- /**
37
- * The metadata to filter the threads by. If provided, only threads with metadata that matches
38
- * the provided metadata will be returned. If not provided, all threads will be returned.
39
- */
40
- metadata?: Partial<QueryMetadata<TThreadMetadata>>;
41
- };
42
- /**
43
- * Whether to scroll to a comment on load based on the URL hash. Defaults to `true`.
44
- *
45
- * @example
46
- * Given the URL `https://example.com/my-room#cm_xxx`, the `cm_xxx` comment will be
47
- * scrolled to on load if it exists in the page.
48
- */
49
- scrollOnLoad?: boolean;
50
- };
51
-
52
- declare type UserStateLoading = {
53
- isLoading: true;
54
- user?: never;
55
- error?: never;
56
- };
57
- declare type UserStateError = {
58
- isLoading: false;
59
- user?: never;
60
- error: Error;
61
- };
62
- declare type UserStateSuccess<T> = {
63
- isLoading: false;
64
- user: T;
65
- error?: never;
66
- };
67
- declare type UserState<T> = UserStateLoading | UserStateError | UserStateSuccess<T>;
68
- declare type RoomInfoStateLoading = {
69
- isLoading: true;
70
- info?: never;
71
- error?: never;
72
- };
73
- declare type RoomInfoStateError = {
74
- isLoading: false;
75
- info?: never;
76
- error: Error;
77
- };
78
- declare type RoomInfoStateSuccess = {
79
- isLoading: false;
80
- info: RoomInfo;
81
- error?: never;
82
- };
83
- declare type RoomInfoState = RoomInfoStateLoading | RoomInfoStateError | RoomInfoStateSuccess;
84
- declare type CreateThreadOptions<TMetadata extends BaseMetadata> = [
85
- TMetadata
86
- ] extends [never] ? {
87
- body: CommentBody;
88
- } : {
89
- body: CommentBody;
90
- metadata: TMetadata;
91
- };
92
- declare type EditThreadMetadataOptions<TMetadata extends BaseMetadata> = [
93
- TMetadata
94
- ] extends [never] ? {
95
- threadId: string;
96
- } : {
97
- threadId: string;
98
- metadata: Resolve<PartialNullable<TMetadata>>;
99
- };
100
- declare type CreateCommentOptions = {
101
- threadId: string;
102
- body: CommentBody;
103
- };
104
- declare type EditCommentOptions = {
105
- threadId: string;
106
- commentId: string;
107
- body: CommentBody;
108
- };
109
- declare type DeleteCommentOptions = {
110
- threadId: string;
111
- commentId: string;
112
- };
113
- declare type CommentReactionOptions = {
114
- threadId: string;
115
- commentId: string;
116
- emoji: string;
117
- };
118
- declare type ThreadsStateLoading = {
119
- isLoading: true;
120
- threads?: never;
121
- error?: never;
122
- };
123
- declare type ThreadsStateResolved<TThreadMetadata extends BaseMetadata> = {
124
- isLoading: false;
125
- threads: ThreadData<TThreadMetadata>[];
126
- error?: Error;
127
- };
128
- declare type ThreadsStateSuccess<TThreadMetadata extends BaseMetadata> = {
129
- isLoading: false;
130
- threads: ThreadData<TThreadMetadata>[];
131
- error?: never;
132
- };
133
- declare type ThreadsState<TThreadMetadata extends BaseMetadata> = ThreadsStateLoading | ThreadsStateResolved<TThreadMetadata>;
134
- declare type InboxNotificationsStateLoading = {
135
- isLoading: true;
136
- inboxNotifications?: never;
137
- error?: never;
138
- };
139
- declare type InboxNotificationsStateResolved = {
140
- isLoading: false;
141
- inboxNotifications: InboxNotificationData[];
142
- error?: Error;
143
- };
144
- declare type InboxNotificationsStateSuccess = {
145
- isLoading: false;
146
- inboxNotifications: InboxNotificationData[];
147
- error?: never;
148
- };
149
- declare type InboxNotificationsStateError = {
150
- isLoading: false;
151
- inboxNotifications?: never;
152
- error: Error;
153
- };
154
- declare type InboxNotificationsState = InboxNotificationsStateLoading | InboxNotificationsStateResolved | InboxNotificationsStateError;
155
- declare type UnreadInboxNotificationsCountStateLoading = {
156
- isLoading: true;
157
- count?: never;
158
- error?: never;
159
- };
160
- declare type UnreadInboxNotificationsCountStateSuccess = {
161
- isLoading: false;
162
- count: number;
163
- error?: never;
164
- };
165
- declare type UnreadInboxNotificationsCountStateError = {
166
- isLoading: false;
167
- count?: never;
168
- error: Error;
169
- };
170
- declare type UnreadInboxNotificationsCountState = UnreadInboxNotificationsCountStateLoading | UnreadInboxNotificationsCountStateSuccess | UnreadInboxNotificationsCountStateError;
171
- declare type RoomNotificationSettingsStateLoading = {
172
- isLoading: true;
173
- settings?: never;
174
- error?: never;
175
- };
176
- declare type RoomNotificationSettingsStateError = {
177
- isLoading: false;
178
- settings?: never;
179
- error: Error;
180
- };
181
- declare type RoomNotificationSettingsStateSuccess = {
182
- isLoading: false;
183
- settings: RoomNotificationSettings;
184
- error?: never;
185
- };
186
- declare type RoomNotificationSettingsState = RoomNotificationSettingsStateLoading | RoomNotificationSettingsStateError | RoomNotificationSettingsStateSuccess;
187
- declare type RoomProviderProps<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<{
188
- /**
189
- * The id of the room you want to connect to
190
- */
191
- id: string;
192
- children: React.ReactNode;
193
- /**
194
- * Whether or not the room should connect to Liveblocks servers
195
- * when the RoomProvider is rendered.
196
- *
197
- * By default equals to `typeof window !== "undefined"`,
198
- * meaning the RoomProvider tries to connect to Liveblocks servers
199
- * only on the client side.
200
- */
201
- autoConnect?: boolean;
202
- /** @deprecated Renamed to `autoConnect` */
203
- shouldInitiallyConnect?: boolean;
204
- /**
205
- * If you're on React 17 or lower, pass in a reference to
206
- * `ReactDOM.unstable_batchedUpdates` or
207
- * `ReactNative.unstable_batchedUpdates` here.
208
- *
209
- * @example
210
- * import { unstable_batchedUpdates } from "react-dom";
211
- *
212
- * <RoomProvider ... unstable_batchedUpdates={unstable_batchedUpdates} />
213
- *
214
- * This will prevent you from running into the so-called "stale props"
215
- * and/or "zombie child" problem that React 17 and lower can suffer from.
216
- * Not necessary when you're on React v18 or later.
217
- */
218
- unstable_batchedUpdates?: (cb: () => void) => void;
219
- } & RoomInitializers<TPresence, TStorage>>;
220
- /**
221
- * For any function type, returns a similar function type, but without the
222
- * first argument.
223
- */
224
- declare type OmitFirstArg<F> = F extends (first: any, ...rest: infer A) => infer R ? (...args: A) => R : never;
225
- declare type MutationContext<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta> = {
226
- storage: LiveObject<TStorage>;
227
- self: User<TPresence, TUserMeta>;
228
- others: readonly User<TPresence, TUserMeta>[];
229
- setMyPresence: (patch: Partial<TPresence>, options?: {
230
- addToHistory: boolean;
231
- }) => void;
232
- };
233
- declare type ThreadSubscription = {
234
- status: "not-subscribed";
235
- unreadSince?: never;
236
- } | {
237
- status: "subscribed";
238
- unreadSince: null;
239
- } | {
240
- status: "subscribed";
241
- unreadSince: Date;
242
- };
243
- declare type SharedContextBundle<TUserMeta extends BaseUserMeta> = {
244
- /**
245
- * @beta
246
- *
247
- * Returns user info from a given user ID.
248
- *
249
- * @example
250
- * const { user, error, isLoading } = useUser("user-id");
251
- */
252
- useUser(userId: string): UserState<TUserMeta["info"]>;
253
- /**
254
- * @private
255
- *
256
- * Returns room info from a given room ID.
257
- *
258
- * @example
259
- * const { info, error, isLoading } = useRoomInfo("room-id");
260
- */
261
- useRoomInfo(roomId: string): RoomInfoState;
262
- suspense: {
263
- /**
264
- * @beta
265
- *
266
- * Returns user info from a given user ID.
267
- *
268
- * @example
269
- * const { user } = useUser("user-id");
270
- */
271
- useUser(userId: string): UserStateSuccess<TUserMeta["info"]>;
272
- /**
273
- * @private
274
- *
275
- * Returns room info from a given room ID.
276
- *
277
- * @example
278
- * const { info } = useRoomInfo("room-id");
279
- */
280
- useRoomInfo(roomId: string): RoomInfoStateSuccess;
281
- };
282
- };
283
- /**
284
- * Properties that are the same in RoomContext and RoomContext["suspense"].
285
- */
286
- declare type RoomContextBundleCommon<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json, TThreadMetadata extends BaseMetadata> = {
287
- /**
288
- * You normally don't need to directly interact with the RoomContext, but
289
- * it can be necessary if you're building an advanced app where you need to
290
- * set up a context bridge between two React renderers.
291
- */
292
- RoomContext: React.Context<Room<TPresence, TStorage, TUserMeta, TRoomEvent> | null>;
293
- /**
294
- * Makes a Room available in the component hierarchy below.
295
- * Joins the room when the component is mounted, and automatically leaves
296
- * the room when the component is unmounted.
297
- */
298
- RoomProvider(props: RoomProviderProps<TPresence, TStorage>): JSX.Element;
299
- /**
300
- * Returns the Room of the nearest RoomProvider above in the React component
301
- * tree.
302
- */
303
- useRoom(): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
304
- /**
305
- * Returns the current connection status for the Room, and triggers
306
- * a re-render whenever it changes. Can be used to render a status badge.
307
- */
308
- useStatus(): Status;
309
- /**
310
- * Returns a function that batches modifications made during the given function.
311
- * All the modifications are sent to other clients in a single message.
312
- * All the modifications are merged in a single history item (undo/redo).
313
- * All the subscribers are called only after the batch is over.
314
- */
315
- useBatch<T>(): (callback: () => T) => T;
316
- /**
317
- * Returns a callback that lets you broadcast custom events to other users in the room
318
- *
319
- * @example
320
- * const broadcast = useBroadcastEvent();
321
- *
322
- * broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
323
- */
324
- useBroadcastEvent(): (event: TRoomEvent, options?: BroadcastOptions) => void;
325
- /**
326
- * Get informed when users enter or leave the room, as an event.
327
- *
328
- * @example
329
- * useOthersListener({ type, user, others }) => {
330
- * if (type === 'enter') {
331
- * // `user` has joined the room
332
- * } else if (type === 'leave') {
333
- * // `user` has left the room
334
- * }
335
- * })
336
- */
337
- useOthersListener(callback: (event: OthersEvent<TPresence, TUserMeta>) => void): void;
338
- /**
339
- * Get informed when reconnecting to the Liveblocks servers is taking
340
- * longer than usual. This typically is a sign of a client that has lost
341
- * internet connectivity.
342
- *
343
- * This isn't problematic (because the Liveblocks client is still trying to
344
- * reconnect), but it's typically a good idea to inform users about it if
345
- * the connection takes too long to recover.
346
- *
347
- * @example
348
- * useLostConnectionListener(event => {
349
- * if (event === 'lost') {
350
- * toast.warn('Reconnecting to the Liveblocks servers is taking longer than usual...')
351
- * } else if (event === 'failed') {
352
- * toast.warn('Reconnecting to the Liveblocks servers failed.')
353
- * } else if (event === 'restored') {
354
- * toast.clear();
355
- * }
356
- * })
357
- */
358
- useLostConnectionListener(callback: (event: LostConnectionEvent) => void): void;
359
- /**
360
- * useErrorListener is a React hook that allows you to respond to potential room
361
- * connection errors.
362
- *
363
- * @example
364
- * useErrorListener(er => {
365
- * console.error(er);
366
- * })
367
- */
368
- useErrorListener(callback: (err: LiveblocksError) => void): void;
369
- /**
370
- * useEventListener is a React hook that allows you to respond to events broadcast
371
- * by other users in the room.
372
- *
373
- * @example
374
- * useEventListener(({ connectionId, event }) => {
375
- * if (event.type === "CUSTOM_EVENT") {
376
- * // Do something
377
- * }
378
- * });
379
- */
380
- useEventListener(callback: (data: RoomEventMessage<TPresence, TUserMeta, TRoomEvent>) => void): void;
381
- /**
382
- * Returns the room.history
383
- */
384
- useHistory(): History;
385
- /**
386
- * Returns a function that undoes the last operation executed by the current client.
387
- * It does not impact operations made by other clients.
388
- */
389
- useUndo(): () => void;
390
- /**
391
- * Returns a function that redoes the last operation executed by the current client.
392
- * It does not impact operations made by other clients.
393
- */
394
- useRedo(): () => void;
395
- /**
396
- * Returns whether there are any operations to undo.
397
- */
398
- useCanUndo(): boolean;
399
- /**
400
- * Returns whether there are any operations to redo.
401
- */
402
- useCanRedo(): boolean;
403
- /**
404
- * Returns the mutable (!) Storage root. This hook exists for
405
- * backward-compatible reasons.
406
- *
407
- * @example
408
- * const [root] = useStorageRoot();
409
- */
410
- useStorageRoot(): [root: LiveObject<TStorage> | null];
411
- /**
412
- * Returns the presence of the current user of the current room, and a function to update it.
413
- * It is different from the setState function returned by the useState hook from React.
414
- * You don't need to pass the full presence object to update it.
415
- *
416
- * @example
417
- * const [myPresence, updateMyPresence] = useMyPresence();
418
- * updateMyPresence({ x: 0 });
419
- * updateMyPresence({ y: 0 });
420
- *
421
- * // At the next render, "myPresence" will be equal to "{ x: 0, y: 0 }"
422
- */
423
- useMyPresence(): [
424
- TPresence,
425
- (patch: Partial<TPresence>, options?: {
426
- addToHistory: boolean;
427
- }) => void
428
- ];
429
- /**
430
- * useUpdateMyPresence is similar to useMyPresence but it only returns the function to update the current user presence.
431
- * 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.
432
- *
433
- * @example
434
- * const updateMyPresence = useUpdateMyPresence();
435
- * updateMyPresence({ x: 0 });
436
- * updateMyPresence({ y: 0 });
437
- *
438
- * // At the next render, the presence of the current user will be equal to "{ x: 0, y: 0 }"
439
- */
440
- useUpdateMyPresence(): (patch: Partial<TPresence>, options?: {
441
- addToHistory: boolean;
442
- }) => void;
443
- /**
444
- * Create a callback function that lets you mutate Liveblocks state.
445
- *
446
- * The first argument that gets passed into your callback will be
447
- * a "mutation context", which exposes the following:
448
- *
449
- * - `root` - The mutable Storage root.
450
- * You can normal mutation on Live structures with this, for
451
- * example: root.get('layers').get('layer1').set('fill',
452
- * 'red')
453
- *
454
- * - `setMyPresence` - Call this with a new (partial) Presence value.
455
- *
456
- * - `self` - A read-only version of the latest self, if you need it to
457
- * compute the next state.
458
- *
459
- * - `others` - A read-only version of the latest others list, if you
460
- * need it to compute the next state.
461
- *
462
- * useMutation is like React's useCallback, except that the first argument
463
- * that gets passed into your callback will be a "mutation context".
464
- *
465
- * If you want get access to the immutable root somewhere in your mutation,
466
- * you can use `root.ToImmutable()`.
467
- *
468
- * @example
469
- * const fillLayers = useMutation(
470
- * ({ root }, color: Color) => {
471
- * ...
472
- * },
473
- * [],
474
- * );
475
- *
476
- * fillLayers('red');
477
- *
478
- * const deleteLayers = useMutation(
479
- * ({ root }) => {
480
- * ...
481
- * },
482
- * [],
483
- * );
484
- *
485
- * deleteLayers();
486
- */
487
- useMutation<F extends (context: MutationContext<TPresence, TStorage, TUserMeta>, ...args: any[]) => any>(callback: F, deps: readonly unknown[]): OmitFirstArg<F>;
488
- /**
489
- * Returns an object that lets you get information about all the users
490
- * currently connected in the room.
491
- *
492
- * @example
493
- * const others = useOthers();
494
- *
495
- * // Example to map all cursors in JSX
496
- * return (
497
- * <>
498
- * {others.map((user) => {
499
- * if (user.presence.cursor == null) {
500
- * return null;
501
- * }
502
- * return <Cursor key={user.connectionId} cursor={user.presence.cursor} />
503
- * })}
504
- * </>
505
- * )
506
- */
507
- useOthers(): readonly User<TPresence, TUserMeta>[];
508
- /**
509
- * Extract arbitrary data based on all the users currently connected in the
510
- * room (except yourself).
511
- *
512
- * The selector function will get re-evaluated any time a user enters or
513
- * leaves the room, as well as whenever their presence data changes.
514
- *
515
- * The component that uses this hook will automatically re-render if your
516
- * selector function returns a different value from its previous run.
517
- *
518
- * By default `useOthers()` uses strict `===` to check for equality. Take
519
- * extra care when returning a computed object or list, for example when you
520
- * return the result of a .map() or .filter() call from the selector. In
521
- * those cases, you'll probably want to use a `shallow` comparison check.
522
- *
523
- * @example
524
- * const avatars = useOthers(users => users.map(u => u.info.avatar), shallow);
525
- * const cursors = useOthers(users => users.map(u => u.presence.cursor), shallow);
526
- * const someoneIsTyping = useOthers(users => users.some(u => u.presence.isTyping));
527
- *
528
- */
529
- useOthers<T>(selector: (others: readonly User<TPresence, TUserMeta>[]) => T, isEqual?: (prev: T, curr: T) => boolean): T;
530
- /**
531
- * Returns an array of connection IDs. This matches the values you'll get by
532
- * using the `useOthers()` hook.
533
- *
534
- * Roughly equivalent to:
535
- * useOthers((others) => others.map(other => other.connectionId), shallow)
536
- *
537
- * This is useful in particular to implement efficiently rendering components
538
- * for each user in the room, e.g. cursors.
539
- *
540
- * @example
541
- * const ids = useOthersConnectionIds();
542
- * // [2, 4, 7]
543
- */
544
- useOthersConnectionIds(): readonly number[];
545
- /**
546
- * Related to useOthers(), but optimized for selecting only "subsets" of
547
- * others. This is useful for performance reasons in particular, because
548
- * selecting only a subset of users also means limiting the number of
549
- * re-renders that will be triggered.
550
- *
551
- * @example
552
- * const avatars = useOthersMapped(user => user.info.avatar);
553
- * // ^^^^^^^
554
- * // { connectionId: number; data: string }[]
555
- *
556
- * The selector function you pass to useOthersMapped() is called an "item
557
- * selector", and operates on a single user at a time. If you provide an
558
- * (optional) "item comparison" function, it will be used to compare each
559
- * item pairwise.
560
- *
561
- * For example, to select multiple properties:
562
- *
563
- * @example
564
- * const avatarsAndCursors = useOthersMapped(
565
- * user => [u.info.avatar, u.presence.cursor],
566
- * shallow, // 👈
567
- * );
568
- */
569
- useOthersMapped<T>(itemSelector: (other: User<TPresence, TUserMeta>) => T, itemIsEqual?: (prev: T, curr: T) => boolean): ReadonlyArray<readonly [connectionId: number, data: T]>;
570
- /**
571
- * Given a connection ID (as obtained by using `useOthersConnectionIds`), you
572
- * can call this selector deep down in your component stack to only have the
573
- * component re-render if properties for this particular user change.
574
- *
575
- * @example
576
- * // Returns only the selected values re-renders whenever that selection changes)
577
- * const { x, y } = useOther(2, user => user.presence.cursor);
578
- */
579
- useOther<T>(connectionId: number, selector: (other: User<TPresence, TUserMeta>) => T, isEqual?: (prev: T, curr: T) => boolean): T;
580
- /**
581
- * @beta
582
- *
583
- * Returns a function that creates a thread with an initial comment, and optionally some metadata.
584
- *
585
- * @example
586
- * const createThread = useCreateThread();
587
- * createThread({ body: {}, metadata: {} });
588
- */
589
- useCreateThread(): (options: CreateThreadOptions<TThreadMetadata>) => ThreadData<TThreadMetadata>;
590
- /**
591
- * @beta
592
- *
593
- * Returns a function that edits a thread's metadata.
594
- * To delete an existing metadata property, set its value to `null`.
595
- *
596
- * @example
597
- * const editThreadMetadata = useEditThreadMetadata();
598
- * editThreadMetadata({ threadId: "th_xxx", metadata: {} })
599
- */
600
- useEditThreadMetadata(): (options: EditThreadMetadataOptions<TThreadMetadata>) => void;
601
- /**
602
- * @beta
603
- *
604
- * Returns a function that adds a comment to a thread.
605
- *
606
- * @example
607
- * const createComment = useCreateComment();
608
- * createComment({ threadId: "th_xxx", body: {} });
609
- */
610
- useCreateComment(): (options: CreateCommentOptions) => CommentData;
611
- /**
612
- * @beta
613
- *
614
- * Returns a function that edits a comment's body.
615
- *
616
- * @example
617
- * const editComment = useEditComment()
618
- * editComment({ threadId: "th_xxx", commentId: "cm_xxx", body: {} })
619
- */
620
- useEditComment(): (options: EditCommentOptions) => void;
621
- /**
622
- * @beta
623
- *
624
- * Returns a function that deletes a comment.
625
- * If it is the last non-deleted comment, the thread also gets deleted.
626
- *
627
- * @example
628
- * const deleteComment = useDeleteComment();
629
- * deleteComment({ threadId: "th_xxx", commentId: "cm_xxx" })
630
- */
631
- useDeleteComment(): (options: DeleteCommentOptions) => void;
632
- /**
633
- * @beta
634
- *
635
- * Returns a function that adds a reaction from a comment.
636
- *
637
- * @example
638
- * const addReaction = useAddReaction();
639
- * addReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
640
- */
641
- useAddReaction(): (options: CommentReactionOptions) => void;
642
- /**
643
- * @beta
644
- *
645
- * Returns a function that removes a reaction on a comment.
646
- *
647
- * @example
648
- * const removeReaction = useRemoveReaction();
649
- * removeReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
650
- */
651
- useRemoveReaction(): (options: CommentReactionOptions) => void;
652
- /**
653
- * @beta
654
- *
655
- * Returns a function that updates the user's notification settings
656
- * for the current room.
657
- *
658
- * @example
659
- * const updateRoomNotificationSettings = useUpdateRoomNotificationSettings();
660
- * updateRoomNotificationSettings({ threads: "all" });
661
- */
662
- useUpdateRoomNotificationSettings(): (settings: Partial<RoomNotificationSettings>) => void;
663
- /**
664
- * @beta
665
- *
666
- * Returns a function that marks a thread as read.
667
- *
668
- * @example
669
- * const markThreadAsRead = useMarkThreadAsRead();
670
- * markThreadAsRead("th_xxx");
671
- */
672
- useMarkThreadAsRead(): (threadId: string) => void;
673
- /**
674
- * @beta
675
- *
676
- * Returns the subscription status of a thread.
677
- *
678
- * @example
679
- * const { status, unreadSince } = useThreadSubscription("th_xxx");
680
- */
681
- useThreadSubscription(threadId: string): ThreadSubscription;
682
- };
683
- /**
684
- * @private
685
- *
686
- * Private methods and variables used in the core internals, but as a user
687
- * of Liveblocks, NEVER USE ANY OF THESE DIRECTLY, because bad things
688
- * will probably happen if you do.
689
- */
690
- declare type PrivateRoomContextApi = {
691
- hasResolveMentionSuggestions: boolean;
692
- useMentionSuggestions(search?: string): string[] | undefined;
693
- useCurrentUserId(): string | null;
694
- };
695
- declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json, TThreadMetadata extends BaseMetadata> = Resolve<RoomContextBundleCommon<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata> & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
696
- /**
697
- * Extract arbitrary data from the Liveblocks Storage state, using an
698
- * arbitrary selector function.
699
- *
700
- * The selector function will get re-evaluated any time something changes in
701
- * Storage. The value returned by your selector function will also be the
702
- * value returned by the hook.
703
- *
704
- * The `root` value that gets passed to your selector function is
705
- * a immutable/readonly version of your Liveblocks storage root.
706
- *
707
- * The component that uses this hook will automatically re-render if the
708
- * returned value changes.
709
- *
710
- * By default `useStorage()` uses strict `===` to check for equality. Take
711
- * extra care when returning a computed object or list, for example when you
712
- * return the result of a .map() or .filter() call from the selector. In
713
- * those cases, you'll probably want to use a `shallow` comparison check.
714
- */
715
- useStorage<T>(selector: (root: ToImmutable<TStorage>) => T, isEqual?: (prev: T | null, curr: T | null) => boolean): T | null;
716
- /**
717
- * Gets the current user once it is connected to the room.
718
- *
719
- * @example
720
- * const me = useSelf();
721
- * const { x, y } = me.presence.cursor;
722
- */
723
- useSelf(): User<TPresence, TUserMeta> | null;
724
- /**
725
- * Extract arbitrary data based on the current user.
726
- *
727
- * The selector function will get re-evaluated any time your presence data
728
- * changes.
729
- *
730
- * The component that uses this hook will automatically re-render if your
731
- * selector function returns a different value from its previous run.
732
- *
733
- * By default `useSelf()` uses strict `===` to check for equality. Take extra
734
- * care when returning a computed object or list, for example when you return
735
- * the result of a .map() or .filter() call from the selector. In those
736
- * cases, you'll probably want to use a `shallow` comparison check.
737
- *
738
- * Will return `null` while Liveblocks isn't connected to a room yet.
739
- *
740
- * @example
741
- * const cursor = useSelf(me => me.presence.cursor);
742
- * if (cursor !== null) {
743
- * const { x, y } = cursor;
744
- * }
745
- *
746
- */
747
- useSelf<T>(selector: (me: User<TPresence, TUserMeta>) => T, isEqual?: (prev: T, curr: T) => boolean): T | null;
748
- /**
749
- * @beta
750
- *
751
- * Returns the threads within the current room.
752
- *
753
- * @example
754
- * const { threads, error, isLoading } = useThreads();
755
- */
756
- useThreads(options?: UseThreadsOptions<TThreadMetadata>): ThreadsState<TThreadMetadata>;
757
- /**
758
- * @beta
759
- *
760
- * Returns the user's notification settings for the current room
761
- * and a function to update them.
762
- *
763
- * @example
764
- * const [{ settings }, updateSettings] = useRoomNotificationSettings();
765
- */
766
- useRoomNotificationSettings(): [
767
- RoomNotificationSettingsState,
768
- (settings: Partial<RoomNotificationSettings>) => void
769
- ];
770
- /**
771
- * Returns the LiveList associated with the provided key. The hook triggers
772
- * a re-render if the LiveList is updated, however it does not triggers
773
- * a re-render if a nested CRDT is updated.
774
- *
775
- * @param key The top-level storage key associated with the LiveList
776
- * @returns null while storage is still loading, otherwise, returns the LiveList instance at the storage key
777
- *
778
- * @example
779
- * const animals = useList("animals"); // e.g. [] or ["🦁", "🐍", "🦍"] // ❌ No longer recommended
780
- * const animals = useStorage((root) => root.animals); // ✅ Do this instead
781
- *
782
- * @deprecated We no longer recommend using `useList`. Prefer `useStorage`
783
- * for reading and `useMutation` for writing.
784
- */
785
- useList<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey] | null;
786
- /**
787
- * Returns the LiveMap associated with the provided key. If the LiveMap
788
- * does not exist, a new empty LiveMap will be created. The hook triggers
789
- * a re-render if the LiveMap is updated, however it does not triggers
790
- * a re-render if a nested CRDT is updated.
791
- *
792
- * @param key The top-level storage key associated with the LiveMap
793
- * @returns null while storage is still loading, otherwise, returns the LiveMap instance at the storage key
794
- *
795
- * @example
796
- * const shapesById = useMap("shapes"); // ❌ No longer recommended
797
- * const shapesById = useStorage((root) => root.shapes); // ✅ Do this instead
798
- *
799
- * @deprecated We no longer recommend using `useMap`. Prefer `useStorage`
800
- * for reading and `useMutation` for writing.
801
- */
802
- useMap<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey] | null;
803
- /**
804
- * Returns the LiveObject associated with the provided key.
805
- * The hook triggers a re-render if the LiveObject is updated, however it does not triggers a re-render if a nested CRDT is updated.
806
- *
807
- * @param key The top-level storage key associated with the LiveObject
808
- * @returns null while storage is still loading, otherwise, returns the LiveObject instance at the storage key
809
- *
810
- * @example
811
- * const object = useObject("obj"); // ❌ No longer recommended
812
- * const object = useStorage((root) => root.obj); // ✅ Do this instead
813
- *
814
- * @deprecated We no longer recommend using `useObject`. Prefer `useStorage`
815
- * for reading and `useMutation` for writing.
816
- */
817
- useObject<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey] | null;
818
- suspense: Resolve<RoomContextBundleCommon<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata> & SharedContextBundle<TUserMeta>["suspense"] & {
819
- /**
820
- * Extract arbitrary data from the Liveblocks Storage state, using an
821
- * arbitrary selector function.
822
- *
823
- * The selector function will get re-evaluated any time something changes in
824
- * Storage. The value returned by your selector function will also be the
825
- * value returned by the hook.
826
- *
827
- * The `root` value that gets passed to your selector function is
828
- * a immutable/readonly version of your Liveblocks storage root.
829
- *
830
- * The component that uses this hook will automatically re-render if the
831
- * returned value changes.
832
- *
833
- * By default `useStorage()` uses strict `===` to check for equality. Take
834
- * extra care when returning a computed object or list, for example when you
835
- * return the result of a .map() or .filter() call from the selector. In
836
- * those cases, you'll probably want to use a `shallow` comparison check.
837
- */
838
- useStorage<T>(selector: (root: ToImmutable<TStorage>) => T, isEqual?: (prev: T, curr: T) => boolean): T;
839
- /**
840
- * Gets the current user once it is connected to the room.
841
- *
842
- * @example
843
- * const me = useSelf();
844
- * const { x, y } = me.presence.cursor;
845
- */
846
- useSelf(): User<TPresence, TUserMeta>;
847
- /**
848
- * Extract arbitrary data based on the current user.
849
- *
850
- * The selector function will get re-evaluated any time your presence data
851
- * changes.
852
- *
853
- * The component that uses this hook will automatically re-render if your
854
- * selector function returns a different value from its previous run.
855
- *
856
- * By default `useSelf()` uses strict `===` to check for equality. Take extra
857
- * care when returning a computed object or list, for example when you return
858
- * the result of a .map() or .filter() call from the selector. In those
859
- * cases, you'll probably want to use a `shallow` comparison check.
860
- *
861
- * Will return `null` while Liveblocks isn't connected to a room yet.
862
- *
863
- * @example
864
- * const cursor = useSelf(me => me.presence.cursor);
865
- * if (cursor !== null) {
866
- * const { x, y } = cursor;
867
- * }
868
- *
869
- */
870
- useSelf<T>(selector: (me: User<TPresence, TUserMeta>) => T, isEqual?: (prev: T, curr: T) => boolean): T;
871
- /**
872
- * @beta
873
- *
874
- * Returns the threads within the current room.
875
- *
876
- * @example
877
- * const { threads } = useThreads();
878
- */
879
- useThreads(options?: UseThreadsOptions<TThreadMetadata>): ThreadsStateSuccess<TThreadMetadata>;
880
- /**
881
- * @beta
882
- *
883
- * Returns the user's notification settings for the current room
884
- * and a function to update them.
885
- *
886
- * @example
887
- * const [{ settings }, updateSettings] = useRoomNotificationSettings();
888
- */
889
- useRoomNotificationSettings(): [
890
- RoomNotificationSettingsStateSuccess,
891
- (settings: Partial<RoomNotificationSettings>) => void
892
- ];
893
- /**
894
- * Returns the LiveList associated with the provided key. The hook triggers
895
- * a re-render if the LiveList is updated, however it does not triggers
896
- * a re-render if a nested CRDT is updated.
897
- *
898
- * @param key The top-level storage key associated with the LiveList
899
- * @returns Returns the LiveList instance at the storage key
900
- *
901
- * @example
902
- * const animals = useList("animals"); // e.g. [] or ["🦁", "🐍", "🦍"] // ❌ No longer recommended
903
- * const animals = useStorage((root) => root.animals); // ✅ Do this instead
904
- *
905
- * @deprecated We no longer recommend using `useList`. Prefer `useStorage`
906
- * for reading and `useMutation` for writing.
907
- */
908
- useList<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey];
909
- /**
910
- * Returns the LiveMap associated with the provided key. If the LiveMap
911
- * does not exist, a new empty LiveMap will be created. The hook triggers
912
- * a re-render if the LiveMap is updated, however it does not triggers
913
- * a re-render if a nested CRDT is updated.
914
- *
915
- * @param key The top-level storage key associated with the LiveMap
916
- * @returns Returns the LiveMap instance at the storage key
917
- *
918
- * @example
919
- * const shapesById = useMap("shapes"); // ❌ No longer recommended
920
- * const shapesById = useStorage((root) => root.shapes); // ✅ Do this instead
921
- *
922
- * @deprecated We no longer recommend using `useMap`. Prefer `useStorage`
923
- * for reading and `useMutation` for writing.
924
- */
925
- useMap<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey];
926
- /**
927
- * Returns the LiveObject associated with the provided key.
928
- * The hook triggers a re-render if the LiveObject is updated, however it does not triggers a re-render if a nested CRDT is updated.
929
- *
930
- * @param key The top-level storage key associated with the LiveObject
931
- * @returns Returns the LiveObject instance at the storage key
932
- *
933
- * @example
934
- * const object = useObject("obj"); // ❌ No longer recommended
935
- * const object = useStorage((root) => root.obj); // ✅ Do this instead
936
- *
937
- * @deprecated We no longer recommend using `useObject`. Prefer `useStorage`
938
- * for reading and `useMutation` for writing.
939
- */
940
- useObject<TKey extends Extract<keyof TStorage, string>>(key: TKey): TStorage[TKey];
941
- }>;
942
- }> & {
943
- /**
944
- * @private
945
- *
946
- * Private methods and variables used in the core internals, but as a user
947
- * of Liveblocks, NEVER USE ANY OF THESE DIRECTLY, because bad things
948
- * will probably happen if you do.
949
- */
950
- readonly [kInternal]: PrivateRoomContextApi;
951
- };
952
- /**
953
- * Properties that are the same in LiveblocksContext and LiveblocksContext["suspense"].
954
- */
955
- declare type LiveblocksContextBundleCommon<TThreadMetadata extends BaseMetadata> = {
956
- /**
957
- * @beta
958
- *
959
- * Makes Liveblocks features outside of rooms (e.g. Notifications) available
960
- * in the component hierarchy below.
961
- */
962
- LiveblocksProvider(props: PropsWithChildren): JSX.Element;
963
- /**
964
- * @beta
965
- *
966
- * Returns a function that marks an inbox notification as read.
967
- *
968
- * @example
969
- * const markInboxNotificationAsRead = useMarkInboxNotificationAsRead();
970
- * markInboxNotificationAsRead("in_xxx");
971
- */
972
- useMarkInboxNotificationAsRead(): (inboxNotificationId: string) => void;
973
- /**
974
- * @beta
975
- *
976
- * Returns a function that marks all inbox notifications as read.
977
- *
978
- * @example
979
- * const markAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead();
980
- * markAllInboxNotificationsAsRead();
981
- */
982
- useMarkAllInboxNotificationsAsRead(): () => void;
983
- /**
984
- * @beta
985
- *
986
- * Returns the thread associated with a `"thread"` inbox notification.
987
- *
988
- * @example
989
- * const thread = useInboxNotificationThread("in_xxx");
990
- */
991
- useInboxNotificationThread(inboxNotificationId: string): ThreadData<TThreadMetadata>;
992
- };
993
- /**
994
- * @private
995
- *
996
- * Private methods and variables used in the core internals, but as a user
997
- * of Liveblocks, NEVER USE ANY OF THESE DIRECTLY, because bad things
998
- * will probably happen if you do.
999
- */
1000
- declare type PrivateLiveblocksContextApi = {
1001
- /**
1002
- * @private
1003
- *
1004
- * Returns the current user ID. Can only be used after making a call to a Notifications API.
1005
- */
1006
- useCurrentUserId(): string | null;
1007
- };
1008
- declare type LiveblocksContextBundle<TUserMeta extends BaseUserMeta, TThreadMetadata extends BaseMetadata> = Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & Omit<SharedContextBundle<TUserMeta>, "suspense"> & {
1009
- /**
1010
- * @beta
1011
- *
1012
- * Returns the inbox notifications for the current user.
1013
- *
1014
- * @example
1015
- * const { inboxNotifications, error, isLoading } = useInboxNotifications();
1016
- */
1017
- useInboxNotifications(): InboxNotificationsState;
1018
- /**
1019
- * @beta
1020
- *
1021
- * Returns the number of unread inbox notifications for the current user.
1022
- *
1023
- * @example
1024
- * const { count, error, isLoading } = useUnreadInboxNotificationsCount();
1025
- */
1026
- useUnreadInboxNotificationsCount(): UnreadInboxNotificationsCountState;
1027
- suspense: Resolve<LiveblocksContextBundleCommon<TThreadMetadata> & SharedContextBundle<TUserMeta>["suspense"] & {
1028
- /**
1029
- * @beta
1030
- *
1031
- * Returns the inbox notifications for the current user.
1032
- *
1033
- * @example
1034
- * const { inboxNotifications } = useInboxNotifications();
1035
- */
1036
- useInboxNotifications(): InboxNotificationsStateSuccess;
1037
- /**
1038
- * @beta
1039
- *
1040
- * Returns the number of unread inbox notifications for the current user.
1041
- *
1042
- * @example
1043
- * const { count } = useUnreadInboxNotificationsCount();
1044
- */
1045
- useUnreadInboxNotificationsCount(): UnreadInboxNotificationsCountStateSuccess;
1046
- }>;
1047
- }> & {
1048
- /**
1049
- * @private
1050
- *
1051
- * Private methods and variables used in the core internals, but as a user
1052
- * of Liveblocks, NEVER USE ANY OF THESE DIRECTLY, because bad things
1053
- * will probably happen if you do.
1054
- */
1055
- readonly [kInternal]: PrivateLiveblocksContextApi;
1056
- };
1057
-
1058
- /**
1059
- * @private
1060
- *
1061
- * This is an internal API, use "createLiveblocksContext" instead.
1062
- */
1063
- declare function useLiveblocksContextBundle(): LiveblocksContextBundle<BaseUserMeta, BaseMetadata$1>;
1064
- declare function createLiveblocksContext<TUserMeta extends BaseUserMeta = BaseUserMeta, TThreadMetadata extends BaseMetadata$1 = never>(client: Client): LiveblocksContextBundle<TUserMeta, TThreadMetadata>;
1065
-
1066
- /**
1067
- * @private
1068
- *
1069
- * This is an internal API, use `createRoomContext` instead.
1070
- */
1071
- declare function useRoomContextBundle(): RoomContextBundle<JsonObject, LsonObject, BaseUserMeta, never, BaseMetadata>;
1072
- declare type Options<TUserMeta extends BaseUserMeta> = {
1073
- /**
1074
- * @deprecated Define 'resolveUsers' in 'createClient' from '@liveblocks/client' instead.
1075
- * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1076
- *
1077
- * A function that returns user info from user IDs.
1078
- */
1079
- resolveUsers?: (args: ResolveUsersArgs) => OptionalPromise<(TUserMeta["info"] | undefined)[] | undefined>;
1080
- /**
1081
- * @deprecated Define 'resolveMentionSuggestions' in 'createClient' from '@liveblocks/client' instead.
1082
- * Please refer to our Upgrade Guide to learn more, see https://liveblocks.io/docs/platform/upgrading/1.10.
1083
- *
1084
- * A function that returns a list of user IDs matching a string.
1085
- */
1086
- resolveMentionSuggestions?: (args: ResolveMentionSuggestionsArgs) => OptionalPromise<string[]>;
1087
- };
1088
- declare function createRoomContext<TPresence extends JsonObject, TStorage extends LsonObject = LsonObject, TUserMeta extends BaseUserMeta = BaseUserMeta, TRoomEvent extends Json = never, TThreadMetadata extends BaseMetadata = never>(client: Client, options?: Options<TUserMeta>): RoomContextBundle<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata>;
1089
-
1090
- /**
1091
- * @private
1092
- *
1093
- * This is an internal API, use `createLiveblocksContext` or `createRoomContext` instead.
1094
- */
1095
- declare function useSharedContextBundle(): RoomContextBundle<_liveblocks_core.JsonObject, _liveblocks_core.LsonObject, BaseUserMeta$1, never, _liveblocks_core.BaseMetadata> | LiveblocksContextBundle<BaseUserMeta$1, _liveblocks_core.BaseMetadata>;
1096
-
1097
- export { ClientSideSuspense, type MutationContext, type UseThreadsOptions, createLiveblocksContext, createRoomContext, useLiveblocksContextBundle, useRoomContextBundle, useSharedContextBundle };
3
+ import 'react';
4
+ import '@liveblocks/core';