@liveblocks/react 0.16.17 → 0.17.0-beta1

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