@liveblocks/react 0.16.4-beta2 → 0.16.6
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/index.d.ts +39 -188
- package/index.js +241 -331
- package/index.mjs +215 -394
- package/package.json +10 -9
package/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import { Client
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Client } from '@liveblocks/client';
|
|
3
3
|
export { Json, JsonObject } from '@liveblocks/client';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as _liveblocks_client_shared from '@liveblocks/client/shared';
|
|
4
6
|
|
|
5
7
|
declare type LiveblocksProviderProps = {
|
|
6
8
|
children: React.ReactNode;
|
|
@@ -16,196 +18,45 @@ declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element
|
|
|
16
18
|
*/
|
|
17
19
|
declare function useClient(): Client;
|
|
18
20
|
|
|
19
|
-
declare
|
|
20
|
-
/**
|
|
21
|
-
* The id of the room you want to connect to
|
|
22
|
-
*/
|
|
21
|
+
declare const RoomProvider: <TStorage>(props: {
|
|
23
22
|
id: string;
|
|
24
|
-
/**
|
|
25
|
-
* A callback that let you initialize the default presence when entering the room.
|
|
26
|
-
* If ommited, the default presence will be an empty object
|
|
27
|
-
*/
|
|
28
|
-
defaultPresence?: () => Presence;
|
|
29
|
-
defaultStorageRoot?: TStorage;
|
|
30
23
|
children: React.ReactNode;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
declare
|
|
38
|
-
/**
|
|
39
|
-
* Returns the Room of the nearest RoomProvider above in the React component
|
|
40
|
-
* tree.
|
|
41
|
-
*/
|
|
42
|
-
declare function useRoom(): Room;
|
|
43
|
-
/**
|
|
44
|
-
* Returns the presence of the current user of the current room, and a function to update it.
|
|
45
|
-
* It is different from the setState function returned by the useState hook from React.
|
|
46
|
-
* You don't need to pass the full presence object to update it.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* import { useMyPresence } from "@liveblocks/react";
|
|
50
|
-
*
|
|
51
|
-
* const [myPresence, updateMyPresence] = useMyPresence();
|
|
52
|
-
* updateMyPresence({ x: 0 });
|
|
53
|
-
* updateMyPresence({ y: 0 });
|
|
54
|
-
*
|
|
55
|
-
* // At the next render, "myPresence" will be equal to "{ x: 0, y: 0 }"
|
|
56
|
-
*/
|
|
57
|
-
declare function useMyPresence<T extends Presence>(): [
|
|
58
|
-
T,
|
|
59
|
-
(overrides: Partial<T>, options?: {
|
|
60
|
-
addToHistory: boolean;
|
|
61
|
-
}) => void
|
|
62
|
-
];
|
|
63
|
-
/**
|
|
64
|
-
* useUpdateMyPresence is similar to useMyPresence but it only returns the function to update the current user presence.
|
|
65
|
-
* 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.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* import { useUpdateMyPresence } from "@liveblocks/react";
|
|
69
|
-
*
|
|
70
|
-
* const updateMyPresence = useUpdateMyPresence();
|
|
71
|
-
* updateMyPresence({ x: 0 });
|
|
72
|
-
* updateMyPresence({ y: 0 });
|
|
73
|
-
*
|
|
74
|
-
* // At the next render, the presence of the current user will be equal to "{ x: 0, y: 0 }"
|
|
75
|
-
*/
|
|
76
|
-
declare function useUpdateMyPresence<T extends Presence>(): (overrides: Partial<T>, options?: {
|
|
24
|
+
initialPresence?: Record<string, unknown> | ((roomId: string) => Record<string, unknown>) | undefined;
|
|
25
|
+
initialStorage?: TStorage | ((roomId: string) => TStorage) | undefined;
|
|
26
|
+
defaultPresence?: (() => Record<string, unknown>) | undefined;
|
|
27
|
+
defaultStorageRoot?: TStorage | undefined;
|
|
28
|
+
}) => JSX.Element;
|
|
29
|
+
declare const useRoom: () => _liveblocks_client_shared.R;
|
|
30
|
+
declare const useMyPresence: <T extends Record<string, unknown>>() => [T, (overrides: Partial<T>, options?: {
|
|
77
31
|
addToHistory: boolean;
|
|
78
|
-
}) => void;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* // Example to map all cursors in jsx
|
|
88
|
-
* {
|
|
89
|
-
* others.map(({ connectionId, presence }) => {
|
|
90
|
-
* if(presence == null || presence.cursor == null) {
|
|
91
|
-
* return null;
|
|
92
|
-
* }
|
|
93
|
-
* return <Cursor key={connectionId} cursor={presence.cursor} />
|
|
94
|
-
* })
|
|
95
|
-
* }
|
|
96
|
-
*/
|
|
97
|
-
declare function useOthers<T extends Presence>(): Others<T>;
|
|
98
|
-
/**
|
|
99
|
-
* Returns a callback that lets you broadcast custom events to other users in the room
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* import { useBroadcastEvent } from "@liveblocks/react";
|
|
103
|
-
*
|
|
104
|
-
* const broadcast = useBroadcastEvent();
|
|
105
|
-
*
|
|
106
|
-
* broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
|
|
107
|
-
*/
|
|
108
|
-
declare function useBroadcastEvent(): (event: any, options?: BroadcastOptions) => void;
|
|
109
|
-
/**
|
|
110
|
-
* useErrorListener is a react hook that lets you react to potential room connection errors.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* import { useErrorListener } from "@liveblocks/react";
|
|
114
|
-
*
|
|
115
|
-
* useErrorListener(er => {
|
|
116
|
-
* console.error(er);
|
|
117
|
-
* })
|
|
118
|
-
*/
|
|
119
|
-
declare function useErrorListener(callback: (err: Error) => void): void;
|
|
120
|
-
/**
|
|
121
|
-
* useEventListener is a react hook that lets you react to event broadcasted by other users in the room.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* import { useEventListener } from "@liveblocks/react";
|
|
125
|
-
*
|
|
126
|
-
* useEventListener(({ connectionId, event }) => {
|
|
127
|
-
* if (event.type === "CUSTOM_EVENT") {
|
|
128
|
-
* // Do something
|
|
129
|
-
* }
|
|
130
|
-
* });
|
|
131
|
-
*/
|
|
132
|
-
declare function useEventListener<TEvent extends Json>(callback: ({ connectionId, event, }: {
|
|
32
|
+
} | undefined) => void];
|
|
33
|
+
declare const useUpdateMyPresence: <T extends Record<string, unknown>>() => (overrides: Partial<T>, options?: {
|
|
34
|
+
addToHistory: boolean;
|
|
35
|
+
} | undefined) => void;
|
|
36
|
+
declare const useOthers: <T extends Record<string, unknown>>() => _liveblocks_client_shared.O<T>;
|
|
37
|
+
declare const useBroadcastEvent: () => (event: any, options?: _liveblocks_client_shared.B | undefined) => void;
|
|
38
|
+
declare const useErrorListener: (callback: (err: Error) => void) => void;
|
|
39
|
+
declare const useEventListener: <TEvent extends _liveblocks_client_shared.J>(callback: ({ connectionId, event, }: {
|
|
133
40
|
connectionId: number;
|
|
134
41
|
event: TEvent;
|
|
135
|
-
}) => void)
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* @returns null while the storage is loading, otherwise, returns the LiveMap associated to the storage
|
|
155
|
-
*
|
|
156
|
-
* @example
|
|
157
|
-
* const emptyMap = useMap("mapA");
|
|
158
|
-
* const mapWithItems = useMap("mapB", [["keyA", "valueA"], ["keyB", "valueB"]]);
|
|
159
|
-
*/
|
|
160
|
-
declare function useMap<TKey extends string, TValue extends Lson>(key: string, entries?: readonly (readonly [TKey, TValue])[] | null | undefined): LiveMap<TKey, TValue> | null;
|
|
161
|
-
/**
|
|
162
|
-
* Returns the LiveList associated with the provided key. If the LiveList does not exist, a new LiveList will be created.
|
|
163
|
-
* The hook triggers a re-render if the LiveList is updated, however it does not triggers a re-render if a nested CRDT is updated.
|
|
164
|
-
*
|
|
165
|
-
* @param key The storage key associated with the LiveList
|
|
166
|
-
* @param items Optional items that are used to create the LiveList for the first time
|
|
167
|
-
* @returns null while the storage is loading, otherwise, returns the LiveList associated to the storage
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* const emptyList = useList("listA");
|
|
171
|
-
* const listWithItems = useList("listB", ["a", "b", "c"]);
|
|
172
|
-
*/
|
|
173
|
-
declare function useList<TValue extends Lson>(key: string, items?: TValue[] | undefined): LiveList<TValue> | null;
|
|
174
|
-
/**
|
|
175
|
-
* Returns the LiveObject associated with the provided key. If the LiveObject does not exist, it will be created with the initialData parameter.
|
|
176
|
-
* 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.
|
|
177
|
-
*
|
|
178
|
-
* @param key The storage key associated with the LiveObject
|
|
179
|
-
* @param initialData Optional data that is used to create the LiveObject for the first time
|
|
180
|
-
* @returns null while the storage is loading, otherwise, returns the LveObject associated to the storage
|
|
181
|
-
*
|
|
182
|
-
* @example
|
|
183
|
-
* const object = useObject("obj", {
|
|
184
|
-
* company: "Liveblocks",
|
|
185
|
-
* website: "https://liveblocks.io"
|
|
186
|
-
* });
|
|
187
|
-
*/
|
|
188
|
-
declare function useObject<TData extends LsonObject>(key: string, initialData?: TData): LiveObject<TData> | null;
|
|
189
|
-
/**
|
|
190
|
-
* Returns a function that undoes the last operation executed by the current client.
|
|
191
|
-
* It does not impact operations made by other clients.
|
|
192
|
-
*/
|
|
193
|
-
declare function useUndo(): () => void;
|
|
194
|
-
/**
|
|
195
|
-
* Returns a function that redoes the last operation executed by the current client.
|
|
196
|
-
* It does not impact operations made by other clients.
|
|
197
|
-
*/
|
|
198
|
-
declare function useRedo(): () => void;
|
|
199
|
-
/**
|
|
200
|
-
* Returns a function that batches modifications made during the given function.
|
|
201
|
-
* All the modifications are sent to other clients in a single message.
|
|
202
|
-
* All the modifications are merged in a single history item (undo/redo).
|
|
203
|
-
* All the subscribers are called only after the batch is over.
|
|
204
|
-
*/
|
|
205
|
-
declare function useBatch(): (callback: () => void) => void;
|
|
206
|
-
/**
|
|
207
|
-
* Returns the room.history
|
|
208
|
-
*/
|
|
209
|
-
declare function useHistory(): History;
|
|
42
|
+
}) => void) => void;
|
|
43
|
+
declare const useSelf: <TPresence extends Record<string, unknown> = Record<string, unknown>>() => _liveblocks_client_shared.U<TPresence> | null;
|
|
44
|
+
declare const useStorage: <TStorage extends Record<string, any>>() => [root: _liveblocks_client_shared.L<TStorage> | null];
|
|
45
|
+
declare const useMap: {
|
|
46
|
+
<TKey extends string, TValue extends _liveblocks_client_shared.e>(key: string): _liveblocks_client_shared.b<TKey, TValue> | null;
|
|
47
|
+
<TKey_1 extends string, TValue_1 extends _liveblocks_client_shared.e>(key: string, entries: readonly (readonly [TKey_1, TValue_1])[] | null): _liveblocks_client_shared.b<TKey_1, TValue_1> | null;
|
|
48
|
+
};
|
|
49
|
+
declare const useList: {
|
|
50
|
+
<TValue extends _liveblocks_client_shared.e>(key: string): _liveblocks_client_shared.c<TValue> | null;
|
|
51
|
+
<TValue_1 extends _liveblocks_client_shared.e>(key: string, items: TValue_1[]): _liveblocks_client_shared.c<TValue_1> | null;
|
|
52
|
+
};
|
|
53
|
+
declare const useObject: {
|
|
54
|
+
<TData extends _liveblocks_client_shared.f>(key: string): _liveblocks_client_shared.L<TData> | null;
|
|
55
|
+
<TData_1 extends _liveblocks_client_shared.f>(key: string, initialData: TData_1): _liveblocks_client_shared.L<TData_1> | null;
|
|
56
|
+
};
|
|
57
|
+
declare const useUndo: () => () => void;
|
|
58
|
+
declare const useRedo: () => () => void;
|
|
59
|
+
declare const useBatch: () => (callback: () => void) => void;
|
|
60
|
+
declare const useHistory: () => _liveblocks_client_shared.H;
|
|
210
61
|
|
|
211
62
|
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|