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