@liveblocks/react 1.3.6 → 1.4.0

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,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
2
  import { ReactElement, ReactNode } from 'react';
3
3
  import * as _liveblocks_core from '@liveblocks/core';
4
- import { CommentBody, BaseMetadata, ThreadData, Resolve, ToImmutable, CommentData, RoomInitializers } from '@liveblocks/core';
4
+ import { CommentBody, BaseMetadata, ThreadData, Resolve, ToImmutable, RoomEventMessage, CommentData, RoomInitializers } from '@liveblocks/core';
5
5
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Others, Json, Room, Status, BroadcastOptions, LostConnectionEvent, History, Client } from '@liveblocks/client';
6
6
  export { Json, JsonObject, shallow } from '@liveblocks/client';
7
7
 
@@ -57,19 +57,27 @@ declare type DeleteCommentOptions = {
57
57
  threadId: string;
58
58
  commentId: string;
59
59
  };
60
- declare type RoomThreads<TThreadMetadata extends BaseMetadata> = {
60
+ declare type CommentReactionOptions = {
61
+ threadId: string;
62
+ commentId: string;
63
+ emoji: string;
64
+ };
65
+ declare type ThreadsStateLoading = {
61
66
  isLoading: true;
62
67
  threads?: never;
63
68
  error?: never;
64
- } | {
69
+ };
70
+ declare type ThreadsStateError = {
65
71
  isLoading: false;
66
72
  threads?: never;
67
73
  error: Error;
68
- } | {
74
+ };
75
+ declare type ThreadsStateSuccess<TThreadMetadata extends BaseMetadata> = {
69
76
  isLoading: false;
70
77
  threads: ThreadData<TThreadMetadata>[];
71
78
  error?: never;
72
79
  };
80
+ declare type ThreadsState<TThreadMetadata extends BaseMetadata> = ThreadsStateLoading | ThreadsStateError | ThreadsStateSuccess<TThreadMetadata>;
73
81
 
74
82
  declare type ResolveUserOptions = {
75
83
  userId: string;
@@ -78,23 +86,22 @@ declare type ResolveMentionSuggestionsOptions = {
78
86
  roomId: string;
79
87
  text: string;
80
88
  };
81
- declare type UserState<T> = {
82
- user?: never;
89
+ declare type UserStateLoading = {
83
90
  isLoading: true;
91
+ user?: never;
84
92
  error?: never;
85
- } | {
86
- user?: T;
93
+ };
94
+ declare type UserStateError = {
87
95
  isLoading: false;
88
- error?: never;
89
- } | {
90
96
  user?: never;
91
- isLoading: false;
92
97
  error: Error;
93
98
  };
94
- declare type UserStateSuspense<T> = Resolve<Extract<UserState<T>, {
99
+ declare type UserStateSuccess<T> = {
95
100
  isLoading: false;
101
+ user: T;
96
102
  error?: never;
97
- }>>;
103
+ };
104
+ declare type UserState<T> = UserStateLoading | UserStateError | UserStateSuccess<T>;
98
105
  declare type RoomProviderProps<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<{
99
106
  /**
100
107
  * The id of the room you want to connect to
@@ -218,10 +225,7 @@ declare type RoomContextBundleShared<TPresence extends JsonObject, TStorage exte
218
225
  * }
219
226
  * });
220
227
  */
221
- useEventListener(callback: (eventData: {
222
- connectionId: number;
223
- event: TRoomEvent;
224
- }) => void): void;
228
+ useEventListener(callback: (data: RoomEventMessage<TPresence, TUserMeta, TRoomEvent>) => void): void;
225
229
  /**
226
230
  * Returns the room.history
227
231
  */
@@ -534,7 +538,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
534
538
  * @example
535
539
  * const { threads, error, isLoading } = useThreads();
536
540
  */
537
- useThreads(): RoomThreads<TThreadMetadata>;
541
+ useThreads(): ThreadsState<TThreadMetadata>;
538
542
  /**
539
543
  * @beta
540
544
  *
@@ -651,18 +655,18 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
651
655
  * Returns the threads within the current room.
652
656
  *
653
657
  * @example
654
- * const threads = useThreads();
658
+ * const { threads } = useThreads();
655
659
  */
656
- useThreads(): ThreadData<TThreadMetadata>[];
660
+ useThreads(): ThreadsStateSuccess<TThreadMetadata>;
657
661
  /**
658
662
  * @beta
659
663
  *
660
664
  * Returns user info from a given user ID.
661
665
  *
662
666
  * @example
663
- * const { user, error, isLoading } = useUser("user-id");
667
+ * const { user } = useUser("user-id");
664
668
  */
665
- useUser(userId: string): UserStateSuspense<TUserMeta["info"]>;
669
+ useUser(userId: string): UserStateSuccess<TUserMeta["info"]>;
666
670
  /**
667
671
  * Returns the LiveList associated with the provided key. The hook triggers
668
672
  * a re-render if the LiveList is updated, however it does not triggers
@@ -749,10 +753,7 @@ declare function useRoomContextBundle(): {
749
753
  useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
750
754
  useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
751
755
  useErrorListener: (callback: (err: Error) => void) => void;
752
- useEventListener: (callback: (eventData: {
753
- connectionId: number;
754
- event: never;
755
- }) => void) => void;
756
+ useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
756
757
  useHistory: () => History;
757
758
  useUndo: () => () => void;
758
759
  useRedo: () => () => void;
@@ -784,6 +785,8 @@ declare function useRoomContextBundle(): {
784
785
  useCreateComment: () => (options: CreateCommentOptions) => CommentData;
785
786
  useEditComment: () => (options: EditCommentOptions) => void;
786
787
  useDeleteComment: () => (options: DeleteCommentOptions) => void;
788
+ useAddReaction: () => (options: CommentReactionOptions) => void;
789
+ useRemoveReaction: () => (options: CommentReactionOptions) => void;
787
790
  useStorage: <T_4>(selector: (root: {
788
791
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | any | {
789
792
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
@@ -1079,7 +1082,7 @@ declare function useRoomContextBundle(): {
1079
1082
  (): User<JsonObject, BaseUserMeta> | null;
1080
1083
  <T_5>(selector: (me: User<JsonObject, BaseUserMeta>) => T_5, isEqual?: ((prev: T_5, curr: T_5) => boolean) | undefined): T_5 | null;
1081
1084
  };
1082
- useThreads: () => RoomThreads<BaseMetadata>;
1085
+ useThreads: () => ThreadsState<BaseMetadata>;
1083
1086
  useUser: (userId: string) => UserState<{
1084
1087
  [key: string]: Json | undefined;
1085
1088
  name?: string | undefined;
@@ -1104,10 +1107,7 @@ declare function useRoomContextBundle(): {
1104
1107
  useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
1105
1108
  useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
1106
1109
  useErrorListener: (callback: (err: Error) => void) => void;
1107
- useEventListener: (callback: (eventData: {
1108
- connectionId: number;
1109
- event: never;
1110
- }) => void) => void;
1110
+ useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
1111
1111
  useHistory: () => History;
1112
1112
  useUndo: () => () => void;
1113
1113
  useRedo: () => () => void;
@@ -1139,6 +1139,8 @@ declare function useRoomContextBundle(): {
1139
1139
  useCreateComment: () => (options: CreateCommentOptions) => CommentData;
1140
1140
  useEditComment: () => (options: EditCommentOptions) => void;
1141
1141
  useDeleteComment: () => (options: DeleteCommentOptions) => void;
1142
+ useAddReaction: () => (options: CommentReactionOptions) => void;
1143
+ useRemoveReaction: () => (options: CommentReactionOptions) => void;
1142
1144
  useStorage: <T_6>(selector: (root: {
1143
1145
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | any | {
1144
1146
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
@@ -1434,16 +1436,12 @@ declare function useRoomContextBundle(): {
1434
1436
  (): User<JsonObject, BaseUserMeta>;
1435
1437
  <T_7>(selector: (me: User<JsonObject, BaseUserMeta>) => T_7, isEqual?: ((prev: T_7, curr: T_7) => boolean) | undefined): T_7;
1436
1438
  };
1437
- useThreads: () => _liveblocks_core.ThreadData<BaseMetadata>[];
1438
- useUser: (userId: string) => {
1439
- user?: {
1440
- [key: string]: Json | undefined;
1441
- name?: string | undefined;
1442
- avatar?: string | undefined;
1443
- } | undefined;
1444
- isLoading: false;
1445
- error?: undefined;
1446
- };
1439
+ useThreads: () => ThreadsStateSuccess<BaseMetadata>;
1440
+ useUser: (userId: string) => UserStateSuccess<{
1441
+ [key: string]: Json | undefined;
1442
+ name?: string | undefined;
1443
+ avatar?: string | undefined;
1444
+ } | undefined>;
1447
1445
  useList: <TKey_3 extends string>(key: TKey_3) => _liveblocks_core.Lson | undefined;
1448
1446
  useMap: <TKey_4 extends string>(key: TKey_4) => _liveblocks_core.Lson | undefined;
1449
1447
  useObject: <TKey_5 extends string>(key: TKey_5) => _liveblocks_core.Lson | undefined;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
2
  import { ReactElement, ReactNode } from 'react';
3
3
  import * as _liveblocks_core from '@liveblocks/core';
4
- import { CommentBody, BaseMetadata, ThreadData, Resolve, ToImmutable, CommentData, RoomInitializers } from '@liveblocks/core';
4
+ import { CommentBody, BaseMetadata, ThreadData, Resolve, ToImmutable, RoomEventMessage, CommentData, RoomInitializers } from '@liveblocks/core';
5
5
  import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Others, Json, Room, Status, BroadcastOptions, LostConnectionEvent, History, Client } from '@liveblocks/client';
6
6
  export { Json, JsonObject, shallow } from '@liveblocks/client';
7
7
 
@@ -57,19 +57,27 @@ declare type DeleteCommentOptions = {
57
57
  threadId: string;
58
58
  commentId: string;
59
59
  };
60
- declare type RoomThreads<TThreadMetadata extends BaseMetadata> = {
60
+ declare type CommentReactionOptions = {
61
+ threadId: string;
62
+ commentId: string;
63
+ emoji: string;
64
+ };
65
+ declare type ThreadsStateLoading = {
61
66
  isLoading: true;
62
67
  threads?: never;
63
68
  error?: never;
64
- } | {
69
+ };
70
+ declare type ThreadsStateError = {
65
71
  isLoading: false;
66
72
  threads?: never;
67
73
  error: Error;
68
- } | {
74
+ };
75
+ declare type ThreadsStateSuccess<TThreadMetadata extends BaseMetadata> = {
69
76
  isLoading: false;
70
77
  threads: ThreadData<TThreadMetadata>[];
71
78
  error?: never;
72
79
  };
80
+ declare type ThreadsState<TThreadMetadata extends BaseMetadata> = ThreadsStateLoading | ThreadsStateError | ThreadsStateSuccess<TThreadMetadata>;
73
81
 
74
82
  declare type ResolveUserOptions = {
75
83
  userId: string;
@@ -78,23 +86,22 @@ declare type ResolveMentionSuggestionsOptions = {
78
86
  roomId: string;
79
87
  text: string;
80
88
  };
81
- declare type UserState<T> = {
82
- user?: never;
89
+ declare type UserStateLoading = {
83
90
  isLoading: true;
91
+ user?: never;
84
92
  error?: never;
85
- } | {
86
- user?: T;
93
+ };
94
+ declare type UserStateError = {
87
95
  isLoading: false;
88
- error?: never;
89
- } | {
90
96
  user?: never;
91
- isLoading: false;
92
97
  error: Error;
93
98
  };
94
- declare type UserStateSuspense<T> = Resolve<Extract<UserState<T>, {
99
+ declare type UserStateSuccess<T> = {
95
100
  isLoading: false;
101
+ user: T;
96
102
  error?: never;
97
- }>>;
103
+ };
104
+ declare type UserState<T> = UserStateLoading | UserStateError | UserStateSuccess<T>;
98
105
  declare type RoomProviderProps<TPresence extends JsonObject, TStorage extends LsonObject> = Resolve<{
99
106
  /**
100
107
  * The id of the room you want to connect to
@@ -218,10 +225,7 @@ declare type RoomContextBundleShared<TPresence extends JsonObject, TStorage exte
218
225
  * }
219
226
  * });
220
227
  */
221
- useEventListener(callback: (eventData: {
222
- connectionId: number;
223
- event: TRoomEvent;
224
- }) => void): void;
228
+ useEventListener(callback: (data: RoomEventMessage<TPresence, TUserMeta, TRoomEvent>) => void): void;
225
229
  /**
226
230
  * Returns the room.history
227
231
  */
@@ -534,7 +538,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
534
538
  * @example
535
539
  * const { threads, error, isLoading } = useThreads();
536
540
  */
537
- useThreads(): RoomThreads<TThreadMetadata>;
541
+ useThreads(): ThreadsState<TThreadMetadata>;
538
542
  /**
539
543
  * @beta
540
544
  *
@@ -651,18 +655,18 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
651
655
  * Returns the threads within the current room.
652
656
  *
653
657
  * @example
654
- * const threads = useThreads();
658
+ * const { threads } = useThreads();
655
659
  */
656
- useThreads(): ThreadData<TThreadMetadata>[];
660
+ useThreads(): ThreadsStateSuccess<TThreadMetadata>;
657
661
  /**
658
662
  * @beta
659
663
  *
660
664
  * Returns user info from a given user ID.
661
665
  *
662
666
  * @example
663
- * const { user, error, isLoading } = useUser("user-id");
667
+ * const { user } = useUser("user-id");
664
668
  */
665
- useUser(userId: string): UserStateSuspense<TUserMeta["info"]>;
669
+ useUser(userId: string): UserStateSuccess<TUserMeta["info"]>;
666
670
  /**
667
671
  * Returns the LiveList associated with the provided key. The hook triggers
668
672
  * a re-render if the LiveList is updated, however it does not triggers
@@ -749,10 +753,7 @@ declare function useRoomContextBundle(): {
749
753
  useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
750
754
  useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
751
755
  useErrorListener: (callback: (err: Error) => void) => void;
752
- useEventListener: (callback: (eventData: {
753
- connectionId: number;
754
- event: never;
755
- }) => void) => void;
756
+ useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
756
757
  useHistory: () => History;
757
758
  useUndo: () => () => void;
758
759
  useRedo: () => () => void;
@@ -784,6 +785,8 @@ declare function useRoomContextBundle(): {
784
785
  useCreateComment: () => (options: CreateCommentOptions) => CommentData;
785
786
  useEditComment: () => (options: EditCommentOptions) => void;
786
787
  useDeleteComment: () => (options: DeleteCommentOptions) => void;
788
+ useAddReaction: () => (options: CommentReactionOptions) => void;
789
+ useRemoveReaction: () => (options: CommentReactionOptions) => void;
787
790
  useStorage: <T_4>(selector: (root: {
788
791
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | any | {
789
792
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
@@ -1079,7 +1082,7 @@ declare function useRoomContextBundle(): {
1079
1082
  (): User<JsonObject, BaseUserMeta> | null;
1080
1083
  <T_5>(selector: (me: User<JsonObject, BaseUserMeta>) => T_5, isEqual?: ((prev: T_5, curr: T_5) => boolean) | undefined): T_5 | null;
1081
1084
  };
1082
- useThreads: () => RoomThreads<BaseMetadata>;
1085
+ useThreads: () => ThreadsState<BaseMetadata>;
1083
1086
  useUser: (userId: string) => UserState<{
1084
1087
  [key: string]: Json | undefined;
1085
1088
  name?: string | undefined;
@@ -1104,10 +1107,7 @@ declare function useRoomContextBundle(): {
1104
1107
  useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
1105
1108
  useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
1106
1109
  useErrorListener: (callback: (err: Error) => void) => void;
1107
- useEventListener: (callback: (eventData: {
1108
- connectionId: number;
1109
- event: never;
1110
- }) => void) => void;
1110
+ useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
1111
1111
  useHistory: () => History;
1112
1112
  useUndo: () => () => void;
1113
1113
  useRedo: () => () => void;
@@ -1139,6 +1139,8 @@ declare function useRoomContextBundle(): {
1139
1139
  useCreateComment: () => (options: CreateCommentOptions) => CommentData;
1140
1140
  useEditComment: () => (options: EditCommentOptions) => void;
1141
1141
  useDeleteComment: () => (options: DeleteCommentOptions) => void;
1142
+ useAddReaction: () => (options: CommentReactionOptions) => void;
1143
+ useRemoveReaction: () => (options: CommentReactionOptions) => void;
1142
1144
  useStorage: <T_6>(selector: (root: {
1143
1145
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | ReadonlyMap<string, _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | readonly (_liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | any | any | {
1144
1146
  readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
@@ -1434,16 +1436,12 @@ declare function useRoomContextBundle(): {
1434
1436
  (): User<JsonObject, BaseUserMeta>;
1435
1437
  <T_7>(selector: (me: User<JsonObject, BaseUserMeta>) => T_7, isEqual?: ((prev: T_7, curr: T_7) => boolean) | undefined): T_7;
1436
1438
  };
1437
- useThreads: () => _liveblocks_core.ThreadData<BaseMetadata>[];
1438
- useUser: (userId: string) => {
1439
- user?: {
1440
- [key: string]: Json | undefined;
1441
- name?: string | undefined;
1442
- avatar?: string | undefined;
1443
- } | undefined;
1444
- isLoading: false;
1445
- error?: undefined;
1446
- };
1439
+ useThreads: () => ThreadsStateSuccess<BaseMetadata>;
1440
+ useUser: (userId: string) => UserStateSuccess<{
1441
+ [key: string]: Json | undefined;
1442
+ name?: string | undefined;
1443
+ avatar?: string | undefined;
1444
+ } | undefined>;
1447
1445
  useList: <TKey_3 extends string>(key: TKey_3) => _liveblocks_core.Lson | undefined;
1448
1446
  useMap: <TKey_4 extends string>(key: TKey_4) => _liveblocks_core.Lson | undefined;
1449
1447
  useObject: <TKey_5 extends string>(key: TKey_5) => _liveblocks_core.Lson | undefined;
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var _core = require('@liveblocks/core');
5
5
 
6
6
  // src/version.ts
7
7
  var PKG_NAME = "@liveblocks/react";
8
- var PKG_VERSION = "1.3.6";
8
+ var PKG_VERSION = "1.4.0";
9
9
  var PKG_FORMAT = "cjs";
10
10
 
11
11
  // src/ClientSideSuspense.tsx
@@ -32,8 +32,6 @@ var _withselectorjs = require('use-sync-external-store/shim/with-selector.js');
32
32
 
33
33
  // src/comments/CommentsRoom.ts
34
34
 
35
-
36
-
37
35
  var _nanoid = require('nanoid');
38
36
 
39
37
  var _indexjs = require('use-sync-external-store/shim/index.js');
@@ -79,6 +77,22 @@ var DeleteCommentError = class extends Error {
79
77
  this.name = "DeleteCommentError";
80
78
  }
81
79
  };
80
+ var AddReactionError = class extends Error {
81
+ constructor(cause, context) {
82
+ super("Add reaction failed.");
83
+ this.cause = cause;
84
+ this.context = context;
85
+ this.name = "AddReactionError";
86
+ }
87
+ };
88
+ var RemoveReactionError = class extends Error {
89
+ constructor(cause, context) {
90
+ super("Remove reaction failed.");
91
+ this.cause = cause;
92
+ this.context = context;
93
+ this.name = "RemoveReactionError";
94
+ }
95
+ };
82
96
 
83
97
  // src/comments/CommentsRoom.ts
84
98
  var POLLING_INTERVAL_REALTIME = 3e4;
@@ -288,7 +302,8 @@ function createCommentsRoom(room, errorEventSource) {
288
302
  type: "comment",
289
303
  createdAt: now,
290
304
  userId: getCurrentUserId(),
291
- body
305
+ body,
306
+ reactions: []
292
307
  };
293
308
  const optimisticData = threads.map(
294
309
  (thread) => thread.id === threadId ? {
@@ -461,12 +476,84 @@ function createCommentsRoom(room, errorEventSource) {
461
476
  if (cache.error) {
462
477
  throw cache.error;
463
478
  }
464
- return cache.threads;
479
+ return {
480
+ threads: cache.threads,
481
+ isLoading: false
482
+ };
483
+ }
484
+ function addReaction({
485
+ threadId,
486
+ commentId,
487
+ emoji
488
+ }) {
489
+ const threads = getThreads();
490
+ const now = (/* @__PURE__ */ new Date()).toISOString();
491
+ const optimisticData = threads.map(
492
+ (thread) => thread.id === threadId ? {
493
+ ...thread,
494
+ comments: thread.comments.map(
495
+ (comment) => comment.id === commentId ? {
496
+ ...comment,
497
+ reactions: [
498
+ ...comment.reactions,
499
+ { emoji, userId: getCurrentUserId(), createdAt: now }
500
+ ]
501
+ } : comment
502
+ )
503
+ } : thread
504
+ );
505
+ mutate(room.addReaction({ threadId, commentId, emoji }), {
506
+ optimisticData
507
+ }).catch((err) => {
508
+ errorEventSource.notify(
509
+ new AddReactionError(err, {
510
+ roomId: room.id,
511
+ threadId,
512
+ commentId,
513
+ emoji
514
+ })
515
+ );
516
+ });
517
+ }
518
+ function removeReaction({
519
+ threadId,
520
+ commentId,
521
+ emoji
522
+ }) {
523
+ const threads = getThreads();
524
+ const optimisticData = threads.map(
525
+ (thread) => thread.id === threadId ? {
526
+ ...thread,
527
+ comments: thread.comments.map((comment) => {
528
+ const reactionIndex = comment.reactions.findIndex(
529
+ (reaction) => reaction.emoji === emoji && reaction.userId === getCurrentUserId()
530
+ );
531
+ return comment.id === commentId ? {
532
+ ...comment,
533
+ reactions: reactionIndex < 0 ? comment.reactions : comment.reactions.slice(0, reactionIndex).concat(comment.reactions.slice(reactionIndex + 1))
534
+ } : comment;
535
+ })
536
+ } : thread
537
+ );
538
+ mutate(room.removeReaction({ threadId, commentId, emoji }), {
539
+ optimisticData
540
+ }).catch((err) => {
541
+ errorEventSource.notify(
542
+ new RemoveReactionError(err, {
543
+ roomId: room.id,
544
+ threadId,
545
+ commentId,
546
+ emoji
547
+ })
548
+ );
549
+ });
465
550
  }
466
551
  return {
467
552
  useThreads,
468
553
  useThreadsSuspense,
469
554
  editThreadMetadata,
555
+ addReaction,
556
+ removeReaction,
470
557
  createThread,
471
558
  createComment,
472
559
  editComment,
@@ -561,6 +648,9 @@ function useAsyncCache(cache, key, options) {
561
648
  if (state.isLoading && _optionalChain([frozenOptions, 'optionalAccess', _10 => _10.keepPreviousDataWhileLoading]) && typeof state.data === "undefined" && _optionalChain([previousData, 'access', _11 => _11.current, 'optionalAccess', _12 => _12.key]) !== key && typeof _optionalChain([previousData, 'access', _13 => _13.current, 'optionalAccess', _14 => _14.data]) !== "undefined") {
562
649
  data = previousData.current.data;
563
650
  }
651
+ if (_optionalChain([frozenOptions, 'optionalAccess', _15 => _15.suspense]) && state.error) {
652
+ throw state.error;
653
+ }
564
654
  return {
565
655
  isLoading: state.isLoading,
566
656
  data,
@@ -935,7 +1025,7 @@ function createRoomContext(client, options) {
935
1025
  function onRootChange() {
936
1026
  const newValue = root.get(key);
937
1027
  if (newValue !== curr) {
938
- _optionalChain([unsubCurr, 'optionalCall', _15 => _15()]);
1028
+ _optionalChain([unsubCurr, 'optionalCall', _16 => _16()]);
939
1029
  curr = newValue;
940
1030
  subscribeToCurr();
941
1031
  rerender();
@@ -946,7 +1036,7 @@ function createRoomContext(client, options) {
946
1036
  const unsubscribeRoot = room.subscribe(root, onRootChange);
947
1037
  return () => {
948
1038
  unsubscribeRoot();
949
- _optionalChain([unsubCurr, 'optionalCall', _16 => _16()]);
1039
+ _optionalChain([unsubCurr, 'optionalCall', _17 => _17()]);
950
1040
  };
951
1041
  }, [rootOrNull, room, key, rerender]);
952
1042
  if (rootOrNull === null) {
@@ -1113,6 +1203,26 @@ function createRoomContext(client, options) {
1113
1203
  [room]
1114
1204
  );
1115
1205
  }
1206
+ function useAddReaction() {
1207
+ const room = useRoom();
1208
+ React2.useEffect(() => {
1209
+ warnIfBetaCommentsHook();
1210
+ }, []);
1211
+ return React2.useCallback(
1212
+ (options2) => getCommentsRoom(room).addReaction(options2),
1213
+ [room]
1214
+ );
1215
+ }
1216
+ function useRemoveReaction() {
1217
+ const room = useRoom();
1218
+ React2.useEffect(() => {
1219
+ warnIfBetaCommentsHook();
1220
+ }, []);
1221
+ return React2.useCallback(
1222
+ (options2) => getCommentsRoom(room).removeReaction(options2),
1223
+ [room]
1224
+ );
1225
+ }
1116
1226
  function useCreateComment() {
1117
1227
  const room = useRoom();
1118
1228
  React2.useEffect(() => {
@@ -1179,7 +1289,6 @@ function createRoomContext(client, options) {
1179
1289
  React2.useEffect(() => warnIfNoResolveUser(usersCache), []);
1180
1290
  return {
1181
1291
  user: state.data,
1182
- error: state.error,
1183
1292
  isLoading: false
1184
1293
  };
1185
1294
  }
@@ -1238,6 +1347,8 @@ function createRoomContext(client, options) {
1238
1347
  useCreateComment,
1239
1348
  useEditComment,
1240
1349
  useDeleteComment,
1350
+ useAddReaction,
1351
+ useRemoveReaction,
1241
1352
  suspense: {
1242
1353
  RoomContext,
1243
1354
  RoomProvider,
@@ -1273,7 +1384,9 @@ function createRoomContext(client, options) {
1273
1384
  useEditThreadMetadata,
1274
1385
  useCreateComment,
1275
1386
  useEditComment,
1276
- useDeleteComment
1387
+ useDeleteComment,
1388
+ useAddReaction,
1389
+ useRemoveReaction
1277
1390
  }
1278
1391
  };
1279
1392
  const internalBundle = {