@liveblocks/react 1.3.5 → 1.4.0-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.
- package/dist/index.d.mts +59 -41
- package/dist/index.d.ts +59 -41
- package/dist/index.js +122 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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
|
|
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
|
|
82
|
-
user?: never;
|
|
89
|
+
declare type UserStateLoading = {
|
|
83
90
|
isLoading: true;
|
|
91
|
+
user?: never;
|
|
84
92
|
error?: never;
|
|
85
|
-
}
|
|
86
|
-
|
|
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
|
|
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: (
|
|
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
|
*/
|
|
@@ -472,6 +476,26 @@ declare type RoomContextBundleShared<TPresence extends JsonObject, TStorage exte
|
|
|
472
476
|
* deleteComment({ threadId: "th_xxx", commentId: "cm_xxx" })
|
|
473
477
|
*/
|
|
474
478
|
useDeleteComment(): (options: DeleteCommentOptions) => void;
|
|
479
|
+
/**
|
|
480
|
+
* @beta
|
|
481
|
+
*
|
|
482
|
+
* Returns a function that adds a reaction from a comment.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const addReaction = useAddReaction();
|
|
486
|
+
* addReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
|
|
487
|
+
*/
|
|
488
|
+
useAddReaction(): (options: CommentReactionOptions) => void;
|
|
489
|
+
/**
|
|
490
|
+
* @beta
|
|
491
|
+
*
|
|
492
|
+
* Returns a function that removes a reaction on a comment.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* const removeReaction = useRemoveReaction();
|
|
496
|
+
* removeReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
|
|
497
|
+
*/
|
|
498
|
+
useRemoveReaction(): (options: CommentReactionOptions) => void;
|
|
475
499
|
};
|
|
476
500
|
declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json, TThreadMetadata extends BaseMetadata> = Resolve<RoomContextBundleShared<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata> & {
|
|
477
501
|
/**
|
|
@@ -534,7 +558,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
534
558
|
* @example
|
|
535
559
|
* const { threads, error, isLoading } = useThreads();
|
|
536
560
|
*/
|
|
537
|
-
useThreads():
|
|
561
|
+
useThreads(): ThreadsState<TThreadMetadata>;
|
|
538
562
|
/**
|
|
539
563
|
* @beta
|
|
540
564
|
*
|
|
@@ -651,18 +675,18 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
651
675
|
* Returns the threads within the current room.
|
|
652
676
|
*
|
|
653
677
|
* @example
|
|
654
|
-
* const threads = useThreads();
|
|
678
|
+
* const { threads } = useThreads();
|
|
655
679
|
*/
|
|
656
|
-
useThreads():
|
|
680
|
+
useThreads(): ThreadsStateSuccess<TThreadMetadata>;
|
|
657
681
|
/**
|
|
658
682
|
* @beta
|
|
659
683
|
*
|
|
660
684
|
* Returns user info from a given user ID.
|
|
661
685
|
*
|
|
662
686
|
* @example
|
|
663
|
-
* const { user
|
|
687
|
+
* const { user } = useUser("user-id");
|
|
664
688
|
*/
|
|
665
|
-
useUser(userId: string):
|
|
689
|
+
useUser(userId: string): UserStateSuccess<TUserMeta["info"]>;
|
|
666
690
|
/**
|
|
667
691
|
* Returns the LiveList associated with the provided key. The hook triggers
|
|
668
692
|
* a re-render if the LiveList is updated, however it does not triggers
|
|
@@ -749,10 +773,7 @@ declare function useRoomContextBundle(): {
|
|
|
749
773
|
useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
|
|
750
774
|
useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
|
|
751
775
|
useErrorListener: (callback: (err: Error) => void) => void;
|
|
752
|
-
useEventListener: (callback: (
|
|
753
|
-
connectionId: number;
|
|
754
|
-
event: never;
|
|
755
|
-
}) => void) => void;
|
|
776
|
+
useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
|
|
756
777
|
useHistory: () => History;
|
|
757
778
|
useUndo: () => () => void;
|
|
758
779
|
useRedo: () => () => void;
|
|
@@ -784,6 +805,8 @@ declare function useRoomContextBundle(): {
|
|
|
784
805
|
useCreateComment: () => (options: CreateCommentOptions) => CommentData;
|
|
785
806
|
useEditComment: () => (options: EditCommentOptions) => void;
|
|
786
807
|
useDeleteComment: () => (options: DeleteCommentOptions) => void;
|
|
808
|
+
useAddReaction: () => (options: CommentReactionOptions) => void;
|
|
809
|
+
useRemoveReaction: () => (options: CommentReactionOptions) => void;
|
|
787
810
|
useStorage: <T_4>(selector: (root: {
|
|
788
811
|
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
812
|
readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
|
|
@@ -1079,7 +1102,7 @@ declare function useRoomContextBundle(): {
|
|
|
1079
1102
|
(): User<JsonObject, BaseUserMeta> | null;
|
|
1080
1103
|
<T_5>(selector: (me: User<JsonObject, BaseUserMeta>) => T_5, isEqual?: ((prev: T_5, curr: T_5) => boolean) | undefined): T_5 | null;
|
|
1081
1104
|
};
|
|
1082
|
-
useThreads: () =>
|
|
1105
|
+
useThreads: () => ThreadsState<BaseMetadata>;
|
|
1083
1106
|
useUser: (userId: string) => UserState<{
|
|
1084
1107
|
[key: string]: Json | undefined;
|
|
1085
1108
|
name?: string | undefined;
|
|
@@ -1104,10 +1127,7 @@ declare function useRoomContextBundle(): {
|
|
|
1104
1127
|
useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
|
|
1105
1128
|
useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
|
|
1106
1129
|
useErrorListener: (callback: (err: Error) => void) => void;
|
|
1107
|
-
useEventListener: (callback: (
|
|
1108
|
-
connectionId: number;
|
|
1109
|
-
event: never;
|
|
1110
|
-
}) => void) => void;
|
|
1130
|
+
useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
|
|
1111
1131
|
useHistory: () => History;
|
|
1112
1132
|
useUndo: () => () => void;
|
|
1113
1133
|
useRedo: () => () => void;
|
|
@@ -1139,6 +1159,8 @@ declare function useRoomContextBundle(): {
|
|
|
1139
1159
|
useCreateComment: () => (options: CreateCommentOptions) => CommentData;
|
|
1140
1160
|
useEditComment: () => (options: EditCommentOptions) => void;
|
|
1141
1161
|
useDeleteComment: () => (options: DeleteCommentOptions) => void;
|
|
1162
|
+
useAddReaction: () => (options: CommentReactionOptions) => void;
|
|
1163
|
+
useRemoveReaction: () => (options: CommentReactionOptions) => void;
|
|
1142
1164
|
useStorage: <T_6>(selector: (root: {
|
|
1143
1165
|
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
1166
|
readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
|
|
@@ -1434,16 +1456,12 @@ declare function useRoomContextBundle(): {
|
|
|
1434
1456
|
(): User<JsonObject, BaseUserMeta>;
|
|
1435
1457
|
<T_7>(selector: (me: User<JsonObject, BaseUserMeta>) => T_7, isEqual?: ((prev: T_7, curr: T_7) => boolean) | undefined): T_7;
|
|
1436
1458
|
};
|
|
1437
|
-
useThreads: () =>
|
|
1438
|
-
useUser: (userId: string) => {
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
} | undefined;
|
|
1444
|
-
isLoading: false;
|
|
1445
|
-
error?: undefined;
|
|
1446
|
-
};
|
|
1459
|
+
useThreads: () => ThreadsStateSuccess<BaseMetadata>;
|
|
1460
|
+
useUser: (userId: string) => UserStateSuccess<{
|
|
1461
|
+
[key: string]: Json | undefined;
|
|
1462
|
+
name?: string | undefined;
|
|
1463
|
+
avatar?: string | undefined;
|
|
1464
|
+
} | undefined>;
|
|
1447
1465
|
useList: <TKey_3 extends string>(key: TKey_3) => _liveblocks_core.Lson | undefined;
|
|
1448
1466
|
useMap: <TKey_4 extends string>(key: TKey_4) => _liveblocks_core.Lson | undefined;
|
|
1449
1467
|
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
|
|
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
|
|
82
|
-
user?: never;
|
|
89
|
+
declare type UserStateLoading = {
|
|
83
90
|
isLoading: true;
|
|
91
|
+
user?: never;
|
|
84
92
|
error?: never;
|
|
85
|
-
}
|
|
86
|
-
|
|
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
|
|
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: (
|
|
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
|
*/
|
|
@@ -472,6 +476,26 @@ declare type RoomContextBundleShared<TPresence extends JsonObject, TStorage exte
|
|
|
472
476
|
* deleteComment({ threadId: "th_xxx", commentId: "cm_xxx" })
|
|
473
477
|
*/
|
|
474
478
|
useDeleteComment(): (options: DeleteCommentOptions) => void;
|
|
479
|
+
/**
|
|
480
|
+
* @beta
|
|
481
|
+
*
|
|
482
|
+
* Returns a function that adds a reaction from a comment.
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* const addReaction = useAddReaction();
|
|
486
|
+
* addReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
|
|
487
|
+
*/
|
|
488
|
+
useAddReaction(): (options: CommentReactionOptions) => void;
|
|
489
|
+
/**
|
|
490
|
+
* @beta
|
|
491
|
+
*
|
|
492
|
+
* Returns a function that removes a reaction on a comment.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* const removeReaction = useRemoveReaction();
|
|
496
|
+
* removeReaction({ threadId: "th_xxx", commentId: "cm_xxx", emoji: "👍" })
|
|
497
|
+
*/
|
|
498
|
+
useRemoveReaction(): (options: CommentReactionOptions) => void;
|
|
475
499
|
};
|
|
476
500
|
declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends LsonObject, TUserMeta extends BaseUserMeta, TRoomEvent extends Json, TThreadMetadata extends BaseMetadata> = Resolve<RoomContextBundleShared<TPresence, TStorage, TUserMeta, TRoomEvent, TThreadMetadata> & {
|
|
477
501
|
/**
|
|
@@ -534,7 +558,7 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
534
558
|
* @example
|
|
535
559
|
* const { threads, error, isLoading } = useThreads();
|
|
536
560
|
*/
|
|
537
|
-
useThreads():
|
|
561
|
+
useThreads(): ThreadsState<TThreadMetadata>;
|
|
538
562
|
/**
|
|
539
563
|
* @beta
|
|
540
564
|
*
|
|
@@ -651,18 +675,18 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
651
675
|
* Returns the threads within the current room.
|
|
652
676
|
*
|
|
653
677
|
* @example
|
|
654
|
-
* const threads = useThreads();
|
|
678
|
+
* const { threads } = useThreads();
|
|
655
679
|
*/
|
|
656
|
-
useThreads():
|
|
680
|
+
useThreads(): ThreadsStateSuccess<TThreadMetadata>;
|
|
657
681
|
/**
|
|
658
682
|
* @beta
|
|
659
683
|
*
|
|
660
684
|
* Returns user info from a given user ID.
|
|
661
685
|
*
|
|
662
686
|
* @example
|
|
663
|
-
* const { user
|
|
687
|
+
* const { user } = useUser("user-id");
|
|
664
688
|
*/
|
|
665
|
-
useUser(userId: string):
|
|
689
|
+
useUser(userId: string): UserStateSuccess<TUserMeta["info"]>;
|
|
666
690
|
/**
|
|
667
691
|
* Returns the LiveList associated with the provided key. The hook triggers
|
|
668
692
|
* a re-render if the LiveList is updated, however it does not triggers
|
|
@@ -749,10 +773,7 @@ declare function useRoomContextBundle(): {
|
|
|
749
773
|
useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
|
|
750
774
|
useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
|
|
751
775
|
useErrorListener: (callback: (err: Error) => void) => void;
|
|
752
|
-
useEventListener: (callback: (
|
|
753
|
-
connectionId: number;
|
|
754
|
-
event: never;
|
|
755
|
-
}) => void) => void;
|
|
776
|
+
useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
|
|
756
777
|
useHistory: () => History;
|
|
757
778
|
useUndo: () => () => void;
|
|
758
779
|
useRedo: () => () => void;
|
|
@@ -784,6 +805,8 @@ declare function useRoomContextBundle(): {
|
|
|
784
805
|
useCreateComment: () => (options: CreateCommentOptions) => CommentData;
|
|
785
806
|
useEditComment: () => (options: EditCommentOptions) => void;
|
|
786
807
|
useDeleteComment: () => (options: DeleteCommentOptions) => void;
|
|
808
|
+
useAddReaction: () => (options: CommentReactionOptions) => void;
|
|
809
|
+
useRemoveReaction: () => (options: CommentReactionOptions) => void;
|
|
787
810
|
useStorage: <T_4>(selector: (root: {
|
|
788
811
|
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
812
|
readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
|
|
@@ -1079,7 +1102,7 @@ declare function useRoomContextBundle(): {
|
|
|
1079
1102
|
(): User<JsonObject, BaseUserMeta> | null;
|
|
1080
1103
|
<T_5>(selector: (me: User<JsonObject, BaseUserMeta>) => T_5, isEqual?: ((prev: T_5, curr: T_5) => boolean) | undefined): T_5 | null;
|
|
1081
1104
|
};
|
|
1082
|
-
useThreads: () =>
|
|
1105
|
+
useThreads: () => ThreadsState<BaseMetadata>;
|
|
1083
1106
|
useUser: (userId: string) => UserState<{
|
|
1084
1107
|
[key: string]: Json | undefined;
|
|
1085
1108
|
name?: string | undefined;
|
|
@@ -1104,10 +1127,7 @@ declare function useRoomContextBundle(): {
|
|
|
1104
1127
|
useBroadcastEvent: () => (event: never, options?: BroadcastOptions | undefined) => void;
|
|
1105
1128
|
useLostConnectionListener: (callback: (event: LostConnectionEvent) => void) => void;
|
|
1106
1129
|
useErrorListener: (callback: (err: Error) => void) => void;
|
|
1107
|
-
useEventListener: (callback: (
|
|
1108
|
-
connectionId: number;
|
|
1109
|
-
event: never;
|
|
1110
|
-
}) => void) => void;
|
|
1130
|
+
useEventListener: (callback: (data: RoomEventMessage<JsonObject, BaseUserMeta, never>) => void) => void;
|
|
1111
1131
|
useHistory: () => History;
|
|
1112
1132
|
useUndo: () => () => void;
|
|
1113
1133
|
useRedo: () => () => void;
|
|
@@ -1139,6 +1159,8 @@ declare function useRoomContextBundle(): {
|
|
|
1139
1159
|
useCreateComment: () => (options: CreateCommentOptions) => CommentData;
|
|
1140
1160
|
useEditComment: () => (options: EditCommentOptions) => void;
|
|
1141
1161
|
useDeleteComment: () => (options: DeleteCommentOptions) => void;
|
|
1162
|
+
useAddReaction: () => (options: CommentReactionOptions) => void;
|
|
1163
|
+
useRemoveReaction: () => (options: CommentReactionOptions) => void;
|
|
1142
1164
|
useStorage: <T_6>(selector: (root: {
|
|
1143
1165
|
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
1166
|
readonly [x: string]: _liveblocks_core.JsonScalar | _liveblocks_core.JsonArray | any | undefined;
|
|
@@ -1434,16 +1456,12 @@ declare function useRoomContextBundle(): {
|
|
|
1434
1456
|
(): User<JsonObject, BaseUserMeta>;
|
|
1435
1457
|
<T_7>(selector: (me: User<JsonObject, BaseUserMeta>) => T_7, isEqual?: ((prev: T_7, curr: T_7) => boolean) | undefined): T_7;
|
|
1436
1458
|
};
|
|
1437
|
-
useThreads: () =>
|
|
1438
|
-
useUser: (userId: string) => {
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
} | undefined;
|
|
1444
|
-
isLoading: false;
|
|
1445
|
-
error?: undefined;
|
|
1446
|
-
};
|
|
1459
|
+
useThreads: () => ThreadsStateSuccess<BaseMetadata>;
|
|
1460
|
+
useUser: (userId: string) => UserStateSuccess<{
|
|
1461
|
+
[key: string]: Json | undefined;
|
|
1462
|
+
name?: string | undefined;
|
|
1463
|
+
avatar?: string | undefined;
|
|
1464
|
+
} | undefined>;
|
|
1447
1465
|
useList: <TKey_3 extends string>(key: TKey_3) => _liveblocks_core.Lson | undefined;
|
|
1448
1466
|
useMap: <TKey_4 extends string>(key: TKey_4) => _liveblocks_core.Lson | undefined;
|
|
1449
1467
|
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.
|
|
8
|
+
var PKG_VERSION = "1.4.0-test1";
|
|
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
|
|
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',
|
|
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',
|
|
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 = {
|