@liveblocks/react 0.16.17 → 0.17.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.
Files changed (4) hide show
  1. package/index.d.ts +318 -45
  2. package/index.js +565 -259
  3. package/index.mjs +511 -216
  4. package/package.json +12 -11
package/index.mjs CHANGED
@@ -1,230 +1,525 @@
1
1
  import * as React from "react";
2
-
3
2
  import { useReducer } from "react";
4
-
5
3
  import { LiveMap, LiveList, LiveObject } from "@liveblocks/client";
6
-
7
- import { deprecateIf } from "@liveblocks/client/internal";
8
-
4
+ import { errorIf, deprecate } from "@liveblocks/client/internal";
9
5
  const ClientContext = React.createContext(null);
10
-
11
6
  function LiveblocksProvider(props) {
12
- return React.createElement(ClientContext.Provider, {
13
- value: props.client
14
- }, props.children);
7
+ return React.createElement(
8
+ ClientContext.Provider,
9
+ { value: props.client },
10
+ props.children
11
+ );
15
12
  }
16
-
17
13
  function useClient() {
18
- const client = React.useContext(ClientContext);
19
- if (null == client) throw new Error("LiveblocksProvider is missing from the react tree");
20
- return client;
14
+ const client = React.useContext(ClientContext);
15
+ if (null == client)
16
+ throw new Error("LiveblocksProvider is missing from the react tree");
17
+ return client;
21
18
  }
22
-
23
19
  function __awaiter(thisArg, _arguments, P, generator) {
24
- return new (P || (P = Promise))((function(resolve, reject) {
25
- function fulfilled(value) {
26
- try {
27
- step(generator.next(value));
28
- } catch (e) {
29
- reject(e);
30
- }
20
+ return new (P || (P = Promise))(function (resolve, reject) {
21
+ function fulfilled(value) {
22
+ try {
23
+ step(generator.next(value));
24
+ } catch (e) {
25
+ reject(e);
26
+ }
27
+ }
28
+ function rejected(value) {
29
+ try {
30
+ step(generator.throw(value));
31
+ } catch (e) {
32
+ reject(e);
33
+ }
34
+ }
35
+ function step(result) {
36
+ var value;
37
+ result.done
38
+ ? resolve(result.value)
39
+ : ((value = result.value),
40
+ value instanceof P
41
+ ? value
42
+ : new P(function (resolve) {
43
+ resolve(value);
44
+ })).then(fulfilled, rejected);
45
+ }
46
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
47
+ });
48
+ }
49
+ function useRerender() {
50
+ const [, update] = useReducer((x) => x + 1, 0);
51
+ return update;
52
+ }
53
+ function configureRoom(client) {
54
+ let useClient$1;
55
+ useClient$1 = void 0 !== client ? () => client : useClient;
56
+ const RoomContext = React.createContext(null);
57
+ function useRoom() {
58
+ const room = React.useContext(RoomContext);
59
+ if (null == room)
60
+ throw new Error("RoomProvider is missing from the react tree");
61
+ return room;
31
62
  }
32
- function rejected(value) {
33
- try {
34
- step(generator.throw(value));
35
- } catch (e) {
36
- reject(e);
37
- }
63
+ function useStorage() {
64
+ const room = useRoom(),
65
+ [root, setState] = React.useState(null);
66
+ return (
67
+ React.useEffect(() => {
68
+ let didCancel = !1;
69
+ return (
70
+ (function () {
71
+ __awaiter(this, void 0, void 0, function* () {
72
+ const storage = yield room.getStorage();
73
+ didCancel || setState(storage.root);
74
+ });
75
+ })(),
76
+ () => {
77
+ didCancel = !0;
78
+ }
79
+ );
80
+ }, [room]),
81
+ [root]
82
+ );
38
83
  }
39
- function step(result) {
40
- var value;
41
- result.done ? resolve(result.value) : (value = result.value, value instanceof P ? value : new P((function(resolve) {
42
- resolve(value);
43
- }))).then(fulfilled, rejected);
84
+ function deprecated_useMap(key, entries) {
85
+ errorIf(
86
+ entries,
87
+ `Support for initializing entries in useMap() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n const initialStorage = () => ({\n ${JSON.stringify(
88
+ key
89
+ )}: new LiveMap(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
90
+ );
91
+ const value = useStorageValue(
92
+ key,
93
+ new LiveMap(null != entries ? entries : void 0)
94
+ );
95
+ return "ok" === value.status
96
+ ? value.value
97
+ : (errorIf(
98
+ "notfound" === value.status,
99
+ `Key ${JSON.stringify(
100
+ key
101
+ )} was not found in Storage. Starting with 0.18, useMap() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveMap } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
102
+ key
103
+ )}: new LiveMap(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
104
+ ),
105
+ null);
44
106
  }
45
- step((generator = generator.apply(thisArg, _arguments || [])).next());
46
- }));
47
- }
48
-
49
- function useRerender() {
50
- const [, update] = useReducer((x => x + 1), 0);
51
- return update;
52
- }
53
-
54
- const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresence, useUpdateMyPresence: useUpdateMyPresence, useOthers: useOthers, useBroadcastEvent: useBroadcastEvent, useErrorListener: useErrorListener, useEventListener: useEventListener, useSelf: useSelf, useStorage: useStorage, useMap: useMap, useList: useList, useObject: useObject, useUndo: useUndo, useRedo: useRedo, useBatch: useBatch, useHistory: useHistory} = function() {
55
- const RoomContext = React.createContext(null);
56
- function useRoom() {
57
- const room = React.useContext(RoomContext);
58
- if (null == room) throw new Error("RoomProvider is missing from the react tree");
59
- return room;
60
- }
61
- function useStorage() {
62
- const room = useRoom(), [root, setState] = React.useState(null);
63
- return React.useEffect((() => {
64
- let didCancel = !1;
65
- return function() {
66
- __awaiter(this, void 0, void 0, (function*() {
67
- const storage = yield room.getStorage();
68
- didCancel || setState(storage.root);
69
- }));
70
- }(), () => {
71
- didCancel = !0;
72
- };
73
- }), [ room ]), [ root ];
74
- }
75
- function useHistory() {
76
- return useRoom().history;
77
- }
78
- function useStorageValue(key, initialValue) {
79
- const room = useRoom(), [root] = useStorage(), rerender = useRerender();
80
- if (React.useEffect((() => {
81
- if (null == root) return;
82
- let liveValue = root.get(key);
83
- null == liveValue && (liveValue = initialValue, root.set(key, liveValue));
84
- let unsubscribeCrdt = room.subscribe(liveValue, rerender);
85
- const unsubscribeRoot = room.subscribe(root, (function() {
86
- const newCrdt = root.get(key);
87
- newCrdt !== liveValue && (unsubscribeCrdt(), liveValue = newCrdt, unsubscribeCrdt = room.subscribe(liveValue, rerender),
88
- rerender());
89
- }));
90
- return rerender(), () => {
91
- unsubscribeRoot(), unsubscribeCrdt();
92
- };
93
- }), [ root, room ]), null == root) return {
94
- status: "loading"
95
- };
96
- {
97
- const value = root.get(key);
98
- return null == value ? {
99
- status: "notfound"
100
- } : {
101
- status: "ok",
102
- value: value
103
- };
107
+ function deprecated_useList(key, items) {
108
+ errorIf(
109
+ items,
110
+ `Support for initializing items in useList() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
111
+ key
112
+ )}: new LiveList(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
113
+ );
114
+ const value = useStorageValue(key, new LiveList(items));
115
+ return "ok" === value.status
116
+ ? value.value
117
+ : (errorIf(
118
+ "notfound" === value.status,
119
+ `Key ${JSON.stringify(
120
+ key
121
+ )} was not found in Storage. Starting with 0.18, useList() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
122
+ key
123
+ )}: new LiveList(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
124
+ ),
125
+ null);
126
+ }
127
+ function deprecated_useObject(key, initialData) {
128
+ errorIf(
129
+ initialData,
130
+ `Support for initializing data in useObject() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
131
+ key
132
+ )}: new LiveObject(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
133
+ );
134
+ const value = useStorageValue(key, new LiveObject(initialData));
135
+ return "ok" === value.status
136
+ ? value.value
137
+ : (errorIf(
138
+ "notfound" === value.status,
139
+ `Key ${JSON.stringify(
140
+ key
141
+ )} was not found in Storage. Starting with 0.18, useObject() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(
142
+ key
143
+ )}: new LiveObject(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`
144
+ ),
145
+ null);
104
146
  }
105
- }
106
- return {
107
- RoomProvider: function(props) {
108
- const {id: roomId, initialPresence: initialPresence, initialStorage: initialStorage, defaultPresence: defaultPresence, defaultStorageRoot: defaultStorageRoot} = props;
109
- if ("production" !== process.env.NODE_ENV) {
110
- if (null == roomId) throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
111
- if ("string" != typeof roomId) throw new Error("RoomProvider id property should be a string.");
112
- }
113
- deprecateIf(defaultPresence, "RoomProvider's `defaultPresence` prop will be removed in @liveblocks/react 0.18. Please use `initialPresence` instead. For more info, see https://bit.ly/3Niy5aP", "defaultPresence"),
114
- deprecateIf(defaultStorageRoot, "RoomProvider's `defaultStorageRoot` prop will be removed in @liveblocks/react 0.18. Please use `initialStorage` instead. For more info, see https://bit.ly/3Niy5aP", "defaultStorageRoot");
115
- const client = useClient(), [room, setRoom] = React.useState((() => client.enter(roomId, {
116
- initialPresence: initialPresence,
117
- initialStorage: initialStorage,
118
- defaultPresence: defaultPresence,
119
- defaultStorageRoot: defaultStorageRoot,
120
- DO_NOT_USE_withoutConnecting: "undefined" == typeof window
121
- })));
122
- return React.useEffect((() => (setRoom(client.enter(roomId, {
123
- initialPresence: initialPresence,
124
- initialStorage: initialStorage,
125
- defaultPresence: defaultPresence,
126
- defaultStorageRoot: defaultStorageRoot,
127
- DO_NOT_USE_withoutConnecting: "undefined" == typeof window
128
- })), () => {
129
- client.leave(roomId);
130
- })), [ client, roomId ]), React.createElement(RoomContext.Provider, {
131
- value: room
132
- }, props.children);
133
- },
134
- useBatch: function() {
135
- return useRoom().batch;
136
- },
137
- useBroadcastEvent: function() {
138
- const room = useRoom();
139
- return React.useCallback(((event, options = {
140
- shouldQueueEventIfNotReady: !1
141
- }) => {
142
- room.broadcastEvent(event, options);
143
- }), [ room ]);
144
- },
145
- useErrorListener: function(callback) {
146
- const room = useRoom(), savedCallback = React.useRef(callback);
147
- React.useEffect((() => {
148
- savedCallback.current = callback;
149
- })), React.useEffect((() => {
150
- const unsubscribe = room.subscribe("error", (e => savedCallback.current(e)));
151
- return () => {
152
- unsubscribe();
153
- };
154
- }), [ room ]);
155
- },
156
- useEventListener: function(callback) {
157
- const room = useRoom(), savedCallback = React.useRef(callback);
158
- React.useEffect((() => {
159
- savedCallback.current = callback;
160
- })), React.useEffect((() => {
161
- const unsubscribe = room.subscribe("event", (e => savedCallback.current(e)));
162
- return () => {
163
- unsubscribe();
164
- };
165
- }), [ room ]);
166
- },
167
- useHistory: useHistory,
168
- useList: function(key, items) {
169
- deprecateIf(items, `Support for initializing items in useList() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveList(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`);
170
- const value = useStorageValue(key, new LiveList(items));
171
- return "ok" === value.status ? value.value : (deprecateIf("notfound" === value.status, `Key ${JSON.stringify(key)} was not found in Storage. Starting with 0.18, useList() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveList } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveList(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`),
172
- null);
173
- },
174
- useMap: function(key, entries) {
175
- deprecateIf(entries, `Support for initializing entries in useMap() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveMap(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`);
176
- const value = useStorageValue(key, new LiveMap(null != entries ? entries : void 0));
177
- return "ok" === value.status ? value.value : (deprecateIf("notfound" === value.status, `Key ${JSON.stringify(key)} was not found in Storage. Starting with 0.18, useMap() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveMap } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveMap(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`),
178
- null);
179
- },
180
- useMyPresence: function() {
181
- const room = useRoom(), presence = room.getPresence(), rerender = useRerender();
182
- return React.useEffect((() => {
183
- const unsubscribe = room.subscribe("my-presence", rerender);
184
- return () => {
185
- unsubscribe();
186
- };
187
- }), [ room ]), [ presence, React.useCallback(((overrides, options) => room.updatePresence(overrides, options)), [ room ]) ];
188
- },
189
- useObject: function(key, initialData) {
190
- deprecateIf(initialData, `Support for initializing data in useObject() directly will be removed in @liveblocks/react 0.18.\n\nInstead, please initialize this data where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveObject(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`);
191
- const value = useStorageValue(key, new LiveObject(initialData));
192
- return "ok" === value.status ? value.value : (deprecateIf("notfound" === value.status, `Key ${JSON.stringify(key)} was not found in Storage. Starting with 0.18, useObject() will no longer automatically create this key.\n\nInstead, please initialize your storage where you set up your RoomProvider:\n\n import { LiveObject } from "@liveblocks/client";\n\n const initialStorage = () => ({\n ${JSON.stringify(key)}: new LiveObject(...),\n ...\n });\n\n <RoomProvider initialStorage={initialStorage}>\n ...\n </RoomProvider>\n\nPlease see https://bit.ly/3Niy5aP for details.`),
193
- null);
194
- },
195
- useOthers: function() {
196
- const room = useRoom(), rerender = useRerender();
197
- return React.useEffect((() => {
198
- const unsubscribe = room.subscribe("others", rerender);
199
- return () => {
200
- unsubscribe();
201
- };
202
- }), [ room ]), room.getOthers();
203
- },
204
- useRedo: function() {
205
- return useHistory().redo;
206
- },
207
- useRoom: useRoom,
208
- useSelf: function() {
209
- const room = useRoom(), rerender = useRerender();
210
- return React.useEffect((() => {
211
- const unsubscribePresence = room.subscribe("my-presence", rerender), unsubscribeConnection = room.subscribe("connection", rerender);
212
- return () => {
213
- unsubscribePresence(), unsubscribeConnection();
214
- };
215
- }), [ room ]), room.getSelf();
216
- },
217
- useStorage: useStorage,
218
- useUndo: function() {
219
- return useHistory().undo;
220
- },
221
- useUpdateMyPresence: function() {
222
- const room = useRoom();
223
- return React.useCallback(((overrides, options) => {
224
- room.updatePresence(overrides, options);
225
- }), [ room ]);
147
+ function useHistory() {
148
+ return useRoom().history;
226
149
  }
227
- };
228
- }();
229
-
230
- export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
150
+ function useStorageValue(key, initialValue) {
151
+ const room = useRoom(),
152
+ [root] = useStorage(),
153
+ rerender = useRerender();
154
+ if (
155
+ (React.useEffect(() => {
156
+ if (null == root) return;
157
+ let liveValue = root.get(key);
158
+ null == liveValue &&
159
+ ((liveValue = initialValue), root.set(key, liveValue));
160
+ let unsubscribeCrdt = room.subscribe(liveValue, rerender);
161
+ const unsubscribeRoot = room.subscribe(root, function () {
162
+ const newCrdt = root.get(key);
163
+ newCrdt !== liveValue &&
164
+ (unsubscribeCrdt(),
165
+ (liveValue = newCrdt),
166
+ (unsubscribeCrdt = room.subscribe(liveValue, rerender)),
167
+ rerender());
168
+ });
169
+ return (
170
+ rerender(),
171
+ () => {
172
+ unsubscribeRoot(), unsubscribeCrdt();
173
+ }
174
+ );
175
+ }, [root, room]),
176
+ null == root)
177
+ )
178
+ return { status: "loading" };
179
+ {
180
+ const value = root.get(key);
181
+ return null == value
182
+ ? { status: "notfound" }
183
+ : { status: "ok", value: value };
184
+ }
185
+ }
186
+ return {
187
+ RoomProvider: function (props) {
188
+ const {
189
+ id: roomId,
190
+ initialPresence: initialPresence,
191
+ initialStorage: initialStorage,
192
+ defaultPresence: defaultPresence,
193
+ defaultStorageRoot: defaultStorageRoot,
194
+ } = props;
195
+ if ("production" !== process.env.NODE_ENV) {
196
+ if (null == roomId)
197
+ throw new Error(
198
+ "RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required"
199
+ );
200
+ if ("string" != typeof roomId)
201
+ throw new Error("RoomProvider id property should be a string.");
202
+ }
203
+ errorIf(
204
+ defaultPresence,
205
+ "RoomProvider's `defaultPresence` prop will be removed in @liveblocks/react 0.18. Please use `initialPresence` instead. For more info, see https://bit.ly/3Niy5aP"
206
+ ),
207
+ errorIf(
208
+ defaultStorageRoot,
209
+ "RoomProvider's `defaultStorageRoot` prop will be removed in @liveblocks/react 0.18. Please use `initialStorage` instead. For more info, see https://bit.ly/3Niy5aP"
210
+ );
211
+ const _client = useClient$1(),
212
+ [room, setRoom] = React.useState(() =>
213
+ _client.enter(roomId, {
214
+ initialPresence: initialPresence,
215
+ initialStorage: initialStorage,
216
+ defaultPresence: defaultPresence,
217
+ defaultStorageRoot: defaultStorageRoot,
218
+ DO_NOT_USE_withoutConnecting: "undefined" == typeof window,
219
+ })
220
+ );
221
+ return (
222
+ React.useEffect(
223
+ () => (
224
+ setRoom(
225
+ _client.enter(roomId, {
226
+ initialPresence: initialPresence,
227
+ initialStorage: initialStorage,
228
+ defaultPresence: defaultPresence,
229
+ defaultStorageRoot: defaultStorageRoot,
230
+ DO_NOT_USE_withoutConnecting: "undefined" == typeof window,
231
+ })
232
+ ),
233
+ () => {
234
+ _client.leave(roomId);
235
+ }
236
+ ),
237
+ [_client, roomId]
238
+ ),
239
+ React.createElement(
240
+ RoomContext.Provider,
241
+ { value: room },
242
+ props.children
243
+ )
244
+ );
245
+ },
246
+ useBatch: function () {
247
+ return useRoom().batch;
248
+ },
249
+ useBroadcastEvent: function () {
250
+ const room = useRoom();
251
+ return React.useCallback(
252
+ (event, options = { shouldQueueEventIfNotReady: !1 }) => {
253
+ room.broadcastEvent(event, options);
254
+ },
255
+ [room]
256
+ );
257
+ },
258
+ useErrorListener: function (callback) {
259
+ const room = useRoom(),
260
+ savedCallback = React.useRef(callback);
261
+ React.useEffect(() => {
262
+ savedCallback.current = callback;
263
+ }),
264
+ React.useEffect(() => {
265
+ const unsubscribe = room.subscribe("error", (e) =>
266
+ savedCallback.current(e)
267
+ );
268
+ return () => {
269
+ unsubscribe();
270
+ };
271
+ }, [room]);
272
+ },
273
+ useEventListener: function (callback) {
274
+ const room = useRoom(),
275
+ savedCallback = React.useRef(callback);
276
+ React.useEffect(() => {
277
+ savedCallback.current = callback;
278
+ }),
279
+ React.useEffect(() => {
280
+ const unsubscribe = room.subscribe("event", (eventData) => {
281
+ savedCallback.current(eventData);
282
+ });
283
+ return () => {
284
+ unsubscribe();
285
+ };
286
+ }, [room]);
287
+ },
288
+ useHistory: useHistory,
289
+ useList: function (key) {
290
+ return deprecated_useList(key);
291
+ },
292
+ deprecated_useList: deprecated_useList,
293
+ useMap: function (key) {
294
+ return deprecated_useMap(key);
295
+ },
296
+ deprecated_useMap: deprecated_useMap,
297
+ useMyPresence: function () {
298
+ const room = useRoom(),
299
+ presence = room.getPresence(),
300
+ rerender = useRerender();
301
+ return (
302
+ React.useEffect(() => {
303
+ const unsubscribe = room.subscribe("my-presence", rerender);
304
+ return () => {
305
+ unsubscribe();
306
+ };
307
+ }, [room]),
308
+ [
309
+ presence,
310
+ React.useCallback(
311
+ (overrides, options) => room.updatePresence(overrides, options),
312
+ [room]
313
+ ),
314
+ ]
315
+ );
316
+ },
317
+ useObject: function (key) {
318
+ return deprecated_useObject(key);
319
+ },
320
+ deprecated_useObject: deprecated_useObject,
321
+ useOthers: function () {
322
+ const room = useRoom(),
323
+ rerender = useRerender();
324
+ return (
325
+ React.useEffect(() => {
326
+ const unsubscribe = room.subscribe("others", rerender);
327
+ return () => {
328
+ unsubscribe();
329
+ };
330
+ }, [room]),
331
+ room.getOthers()
332
+ );
333
+ },
334
+ useRedo: function () {
335
+ return useHistory().redo;
336
+ },
337
+ useRoom: useRoom,
338
+ useSelf: function () {
339
+ const room = useRoom(),
340
+ rerender = useRerender();
341
+ return (
342
+ React.useEffect(() => {
343
+ const unsubscribePresence = room.subscribe("my-presence", rerender),
344
+ unsubscribeConnection = room.subscribe("connection", rerender);
345
+ return () => {
346
+ unsubscribePresence(), unsubscribeConnection();
347
+ };
348
+ }, [room]),
349
+ room.getSelf()
350
+ );
351
+ },
352
+ useStorage: useStorage,
353
+ useUndo: function () {
354
+ return useHistory().undo;
355
+ },
356
+ useUpdateMyPresence: function () {
357
+ const room = useRoom();
358
+ return React.useCallback(
359
+ (overrides, options) => {
360
+ room.updatePresence(overrides, options);
361
+ },
362
+ [room]
363
+ );
364
+ },
365
+ };
366
+ }
367
+ const _hooks = configureRoom();
368
+ function RoomProvider(props) {
369
+ return (
370
+ deprecate(
371
+ "Please use `configureRoom()` instead of importing `RoomProvider` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
372
+ ),
373
+ _hooks.RoomProvider(props)
374
+ );
375
+ }
376
+ function useBatch() {
377
+ return (
378
+ deprecate(
379
+ "Please use `configureRoom()` instead of importing `useBatch` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
380
+ ),
381
+ _hooks.useBatch()
382
+ );
383
+ }
384
+ function useBroadcastEvent() {
385
+ return (
386
+ deprecate(
387
+ "Please use `configureRoom()` instead of importing `useBroadcastEvent` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
388
+ ),
389
+ _hooks.useBroadcastEvent()
390
+ );
391
+ }
392
+ function useErrorListener(callback) {
393
+ return (
394
+ deprecate(
395
+ "Please use `configureRoom()` instead of importing `useErrorListener` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
396
+ ),
397
+ _hooks.useErrorListener(callback)
398
+ );
399
+ }
400
+ function useEventListener(callback) {
401
+ return (
402
+ deprecate(
403
+ "Please use `configureRoom()` instead of importing `useEventListener` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
404
+ ),
405
+ _hooks.useEventListener(callback)
406
+ );
407
+ }
408
+ function useHistory() {
409
+ return (
410
+ deprecate(
411
+ "Please use `configureRoom()` instead of importing `useHistory` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
412
+ ),
413
+ _hooks.useHistory()
414
+ );
415
+ }
416
+ function useList(key, items) {
417
+ return (
418
+ deprecate(
419
+ "Please use `configureRoom()` instead of importing `useList` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
420
+ ),
421
+ _hooks.deprecated_useList(key, items)
422
+ );
423
+ }
424
+ function useMap(key, entries) {
425
+ return (
426
+ deprecate(
427
+ "Please use `configureRoom()` instead of importing `useMap` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
428
+ ),
429
+ _hooks.deprecated_useMap(key, entries)
430
+ );
431
+ }
432
+ function useMyPresence() {
433
+ return (
434
+ deprecate(
435
+ "Please use `configureRoom()` instead of importing `useMyPresence` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
436
+ ),
437
+ _hooks.useMyPresence()
438
+ );
439
+ }
440
+ function useObject(key, initialData) {
441
+ return (
442
+ deprecate(
443
+ "Please use `configureRoom()` instead of importing `useObject` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
444
+ ),
445
+ _hooks.deprecated_useObject(key, initialData)
446
+ );
447
+ }
448
+ function useOthers() {
449
+ return (
450
+ deprecate(
451
+ "Please use `configureRoom()` instead of importing `useOthers` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
452
+ ),
453
+ _hooks.useOthers()
454
+ );
455
+ }
456
+ function useRedo() {
457
+ return (
458
+ deprecate(
459
+ "Please use `configureRoom()` instead of importing `useRedo` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
460
+ ),
461
+ _hooks.useRedo()
462
+ );
463
+ }
464
+ function useRoom() {
465
+ return (
466
+ deprecate(
467
+ "Please use `configureRoom()` instead of importing `useRoom` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
468
+ ),
469
+ _hooks.useRoom()
470
+ );
471
+ }
472
+ function useSelf() {
473
+ return (
474
+ deprecate(
475
+ "Please use `configureRoom()` instead of importing `useSelf` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
476
+ ),
477
+ _hooks.useSelf()
478
+ );
479
+ }
480
+ function useStorage() {
481
+ return (
482
+ deprecate(
483
+ "Please use `configureRoom()` instead of importing `useStorage` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
484
+ ),
485
+ _hooks.useStorage()
486
+ );
487
+ }
488
+ function useUndo() {
489
+ return (
490
+ deprecate(
491
+ "Please use `configureRoom()` instead of importing `useUndo` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
492
+ ),
493
+ _hooks.useUndo()
494
+ );
495
+ }
496
+ function useUpdateMyPresence() {
497
+ return (
498
+ deprecate(
499
+ "Please use `configureRoom()` instead of importing `useUpdateMyPresence` from `@liveblocks/react` directly. See https://gist.github.com/nvie/5e718902c51ea7dad93cd6952fe1af03 for details."
500
+ ),
501
+ _hooks.useUpdateMyPresence()
502
+ );
503
+ }
504
+ export {
505
+ LiveblocksProvider,
506
+ RoomProvider,
507
+ configureRoom,
508
+ useBatch,
509
+ useBroadcastEvent,
510
+ useClient,
511
+ useErrorListener,
512
+ useEventListener,
513
+ useHistory,
514
+ useList,
515
+ useMap,
516
+ useMyPresence,
517
+ useObject,
518
+ useOthers,
519
+ useRedo,
520
+ useRoom,
521
+ useSelf,
522
+ useStorage,
523
+ useUndo,
524
+ useUpdateMyPresence,
525
+ };