@liveblocks/react 0.16.16 → 0.17.0-beta2

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.
Files changed (4) hide show
  1. package/index.d.ts +311 -45
  2. package/index.js +570 -259
  3. package/index.mjs +516 -216
  4. package/package.json +12 -11
package/index.d.ts CHANGED
@@ -1,62 +1,328 @@
1
1
  /// <reference types="react" />
2
- import { Client } from '@liveblocks/client';
3
- export { Json, JsonObject } from '@liveblocks/client';
4
- import * as React from 'react';
5
- import * as _liveblocks_client_shared from '@liveblocks/client/shared';
2
+ import {
3
+ Client,
4
+ JsonObject,
5
+ LsonObject,
6
+ BaseUserMeta,
7
+ Json,
8
+ BroadcastOptions,
9
+ History,
10
+ Others,
11
+ Room,
12
+ User,
13
+ LiveObject,
14
+ Lson,
15
+ LiveList,
16
+ LiveMap,
17
+ } from "@liveblocks/client";
18
+ export { Json, JsonObject } from "@liveblocks/client";
19
+ import * as React from "react";
20
+ import { Resolve, RoomInitializers } from "@liveblocks/client/internal";
6
21
 
7
22
  declare type LiveblocksProviderProps = {
8
- children: React.ReactNode;
9
- client: Client;
23
+ children: React.ReactNode;
24
+ client: Client;
10
25
  };
11
26
  /**
12
27
  * Makes the Liveblocks client available in the component hierarchy below.
28
+ *
29
+ * @deprecated LiveblocksProvider is no longer needed in your component tree if
30
+ * you set up your Liveblocks context using `createRoomContext()`. See
31
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for
32
+ * details.
13
33
  */
14
- declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element;
34
+ declare function LiveblocksProvider(
35
+ props: LiveblocksProviderProps
36
+ ): JSX.Element;
15
37
  /**
16
38
  * Returns the Client of the nearest LiveblocksProvider above in the React
17
39
  * component tree.
18
40
  */
19
41
  declare function useClient(): Client;
20
42
 
21
- declare const RoomProvider: <TStorage>(props: {
43
+ declare type RoomProviderProps<
44
+ TPresence extends JsonObject,
45
+ TStorage extends LsonObject
46
+ > = Resolve<
47
+ {
48
+ /**
49
+ * The id of the room you want to connect to
50
+ */
22
51
  id: string;
23
52
  children: React.ReactNode;
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?: {
31
- addToHistory: boolean;
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, }: {
40
- connectionId: number;
41
- event: TEvent;
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;
53
+ } & RoomInitializers<TPresence, TStorage>
54
+ >;
55
+ declare function createRoomContext<
56
+ TPresence extends JsonObject,
57
+ TStorage extends LsonObject = LsonObject,
58
+ TUserMeta extends BaseUserMeta = BaseUserMeta,
59
+ TRoomEvent extends Json = never
60
+ >(
61
+ client: Client
62
+ ): {
63
+ RoomProvider: (props: RoomProviderProps<TPresence, TStorage>) => JSX.Element;
64
+ useBatch: () => (callback: () => void) => void;
65
+ useBroadcastEvent: () => (
66
+ event: TRoomEvent,
67
+ options?: BroadcastOptions
68
+ ) => void;
69
+ useErrorListener: (callback: (err: Error) => void) => void;
70
+ useEventListener: (
71
+ callback: (eventData: { connectionId: number; event: TRoomEvent }) => void
72
+ ) => void;
73
+ useHistory: () => History;
74
+ useList: <TKey extends Extract<keyof TStorage, string>>(
75
+ key: TKey
76
+ ) => TStorage[TKey] | null;
77
+ useMap: <TKey_1 extends Extract<keyof TStorage, string>>(
78
+ key: TKey_1
79
+ ) => TStorage[TKey_1] | null;
80
+ useMyPresence: () => [
81
+ TPresence,
82
+ (
83
+ overrides: Partial<TPresence>,
84
+ options?: {
85
+ addToHistory: boolean;
86
+ }
87
+ ) => void
88
+ ];
89
+ useObject: <TKey_2 extends Extract<keyof TStorage, string>>(
90
+ key: TKey_2
91
+ ) => TStorage[TKey_2] | null;
92
+ useOthers: () => Others<TPresence, TUserMeta>;
93
+ useRedo: () => () => void;
94
+ useRoom: () => Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
95
+ useSelf: () => User<TPresence, TUserMeta> | null;
96
+ useStorage: () => [root: LiveObject<TStorage> | null];
97
+ useUndo: () => () => void;
98
+ useUpdateMyPresence: () => (
99
+ overrides: Partial<TPresence>,
100
+ options?: {
101
+ addToHistory: boolean;
102
+ }
103
+ ) => void;
104
+ deprecated_useList: {
105
+ <TValue extends Lson>(key: string): LiveList<TValue> | null;
106
+ <TValue_1 extends Lson>(
107
+ key: string,
108
+ items: TValue_1[]
109
+ ): LiveList<TValue_1> | null;
110
+ };
111
+ deprecated_useMap: {
112
+ <TKey_3 extends string, TValue_2 extends Lson>(key: string): LiveMap<
113
+ TKey_3,
114
+ TValue_2
115
+ > | null;
116
+ <TKey_4 extends string, TValue_3 extends Lson>(
117
+ key: string,
118
+ entries: readonly (readonly [TKey_4, TValue_3])[] | null
119
+ ): LiveMap<TKey_4, TValue_3> | null;
120
+ };
121
+ deprecated_useObject: {
122
+ <TData extends LsonObject>(key: string): LiveObject<TData> | null;
123
+ <TData_1 extends LsonObject>(
124
+ key: string,
125
+ initialData: TData_1
126
+ ): LiveObject<TData_1> | null;
127
+ };
52
128
  };
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;
61
129
 
62
- export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
130
+ /**
131
+ * NOTE:
132
+ * This file is AUTOGENERATED!
133
+ *
134
+ * Do not update it manually.
135
+ */
136
+
137
+ /**
138
+ * @deprecated Please use `createRoomContext()` instead of importing
139
+ * `RoomProvider` from `@liveblocks/react` directly. See
140
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
141
+ */
142
+ declare function RoomProvider<
143
+ TPresence extends JsonObject,
144
+ TStorage extends LsonObject
145
+ >(props: RoomProviderProps<TPresence, TStorage>): JSX.Element;
146
+ /**
147
+ * @deprecated Please use `createRoomContext()` instead of importing
148
+ * `useBatch` from `@liveblocks/react` directly. See
149
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
150
+ */
151
+ declare function useBatch(): (callback: () => void) => void;
152
+ /**
153
+ * @deprecated Please use `createRoomContext()` instead of importing
154
+ * `useBroadcastEvent` from `@liveblocks/react` directly. See
155
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
156
+ */
157
+ declare function useBroadcastEvent<TRoomEvent extends Json>(): (
158
+ event: TRoomEvent,
159
+ options?: BroadcastOptions
160
+ ) => void;
161
+ /**
162
+ * @deprecated Please use `createRoomContext()` instead of importing
163
+ * `useErrorListener` from `@liveblocks/react` directly. See
164
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
165
+ */
166
+ declare function useErrorListener(callback: (err: Error) => void): void;
167
+ /**
168
+ * @deprecated Please use `createRoomContext()` instead of importing
169
+ * `useEventListener` from `@liveblocks/react` directly. See
170
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
171
+ */
172
+ declare function useEventListener<TRoomEvent extends Json>(
173
+ callback: (eventData: { connectionId: number; event: TRoomEvent }) => void
174
+ ): void;
175
+ /**
176
+ * @deprecated Please use `createRoomContext()` instead of importing
177
+ * `useHistory` from `@liveblocks/react` directly. See
178
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
179
+ */
180
+ declare function useHistory(): History;
181
+ /**
182
+ * @deprecated Please use `createRoomContext()` instead of importing
183
+ * `useMyPresence` from `@liveblocks/react` directly. See
184
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
185
+ */
186
+ declare function useMyPresence<TPresence extends JsonObject>(): [
187
+ TPresence,
188
+ (
189
+ overrides: Partial<TPresence>,
190
+ options?: {
191
+ addToHistory: boolean;
192
+ }
193
+ ) => void
194
+ ];
195
+ /**
196
+ * @deprecated Please use `createRoomContext()` instead of importing
197
+ * `useOthers` from `@liveblocks/react` directly. See
198
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
199
+ */
200
+ declare function useOthers<
201
+ TPresence extends JsonObject,
202
+ TUserMeta extends BaseUserMeta
203
+ >(): Others<TPresence, TUserMeta>;
204
+ /**
205
+ * @deprecated Please use `createRoomContext()` instead of importing
206
+ * `useRedo` from `@liveblocks/react` directly. See
207
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
208
+ */
209
+ declare function useRedo(): () => void;
210
+ /**
211
+ * @deprecated Please use `createRoomContext()` instead of importing
212
+ * `useRoom` from `@liveblocks/react` directly. See
213
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
214
+ */
215
+ declare function useRoom<
216
+ TPresence extends JsonObject,
217
+ TStorage extends LsonObject,
218
+ TUserMeta extends BaseUserMeta,
219
+ TRoomEvent extends Json
220
+ >(): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
221
+ /**
222
+ * @deprecated Please use `createRoomContext()` instead of importing
223
+ * `useSelf` from `@liveblocks/react` directly. See
224
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
225
+ */
226
+ declare function useSelf<
227
+ TPresence extends JsonObject,
228
+ TUserMeta extends BaseUserMeta
229
+ >(): User<TPresence, TUserMeta> | null;
230
+ /**
231
+ * @deprecated Please use `createRoomContext()` instead of importing
232
+ * `useStorage` from `@liveblocks/react` directly. See
233
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
234
+ */
235
+ declare function useStorage<TStorage extends LsonObject>(): [
236
+ root: LiveObject<TStorage> | null
237
+ ];
238
+ /**
239
+ * @deprecated Please use `createRoomContext()` instead of importing
240
+ * `useUndo` from `@liveblocks/react` directly. See
241
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
242
+ */
243
+ declare function useUndo(): () => void;
244
+ /**
245
+ * @deprecated Please use `createRoomContext()` instead of importing
246
+ * `useUpdateMyPresence` from `@liveblocks/react` directly. See
247
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
248
+ */
249
+ declare function useUpdateMyPresence<TPresence extends JsonObject>(): (
250
+ overrides: Partial<TPresence>,
251
+ options?: {
252
+ addToHistory: boolean;
253
+ }
254
+ ) => void;
255
+ /**
256
+ * @deprecated Please use `createRoomContext()` instead of importing
257
+ * `useList` from `@liveblocks/react` directly. See
258
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
259
+ */
260
+ declare function useList<TValue extends Lson>(
261
+ key: string
262
+ ): LiveList<TValue> | null;
263
+ /**
264
+ * @deprecated Please use `createRoomContext()` instead of importing
265
+ * `useList` from `@liveblocks/react` directly. See
266
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
267
+ */
268
+ declare function useList<TValue extends Lson>(
269
+ key: string,
270
+ items: TValue[]
271
+ ): LiveList<TValue> | null;
272
+ /**
273
+ * @deprecated Please use `createRoomContext()` instead of importing
274
+ * `useMap` from `@liveblocks/react` directly. See
275
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
276
+ */
277
+ declare function useMap<TKey extends string, TValue extends Lson>(
278
+ key: string
279
+ ): LiveMap<TKey, TValue> | null;
280
+ /**
281
+ * @deprecated Please use `createRoomContext()` instead of importing
282
+ * `useMap` from `@liveblocks/react` directly. See
283
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
284
+ */
285
+ declare function useMap<TKey extends string, TValue extends Lson>(
286
+ key: string,
287
+ entries: readonly (readonly [TKey, TValue])[] | null
288
+ ): LiveMap<TKey, TValue> | null;
289
+ /**
290
+ * @deprecated Please use `createRoomContext()` instead of importing
291
+ * `useObject` from `@liveblocks/react` directly. See
292
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
293
+ */
294
+ declare function useObject<TData extends LsonObject>(
295
+ key: string
296
+ ): LiveObject<TData> | null;
297
+ /**
298
+ * @deprecated Please use `createRoomContext()` instead of importing
299
+ * `useObject` from `@liveblocks/react` directly. See
300
+ * https://liveblocks.io/docs/guides/upgrading#upgrading-from-0-16-to-0-17 for details.
301
+ */
302
+ declare function useObject<TData extends LsonObject>(
303
+ key: string,
304
+ initialData: TData
305
+ ): LiveObject<TData> | null;
306
+
307
+ export {
308
+ LiveblocksProvider,
309
+ RoomProvider,
310
+ createRoomContext,
311
+ useBatch,
312
+ useBroadcastEvent,
313
+ useClient,
314
+ useErrorListener,
315
+ useEventListener,
316
+ useHistory,
317
+ useList,
318
+ useMap,
319
+ useMyPresence,
320
+ useObject,
321
+ useOthers,
322
+ useRedo,
323
+ useRoom,
324
+ useSelf,
325
+ useStorage,
326
+ useUndo,
327
+ useUpdateMyPresence,
328
+ };