@liveblocks/react 0.16.4-beta1 → 0.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +39 -188
- package/index.js +241 -331
- package/index.mjs +230 -0
- package/package.json +15 -20
- package/esm/index.js +0 -212
- package/esm/index.mjs +0 -212
package/index.js
CHANGED
|
@@ -1,362 +1,272 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports,
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: !0
|
|
5
|
+
});
|
|
4
6
|
|
|
5
|
-
var React = require(
|
|
6
|
-
var client = require('@liveblocks/client');
|
|
7
|
+
var React = require("react"), client = require("@liveblocks/client"), internal = require("@liveblocks/client/internal");
|
|
7
8
|
|
|
8
9
|
function _interopNamespace(e) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
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
21
|
}
|
|
22
|
-
|
|
23
|
-
return Object.freeze(n);
|
|
22
|
+
})), n.default = e, Object.freeze(n);
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
var React__namespace =
|
|
25
|
+
var React__namespace = _interopNamespace(React), ClientContext = React__namespace.createContext(null);
|
|
27
26
|
|
|
28
|
-
var ClientContext = React__namespace.createContext(null);
|
|
29
|
-
function LiveblocksProvider(props) {
|
|
30
|
-
return React__namespace.createElement(ClientContext.Provider, {
|
|
31
|
-
value: props.client
|
|
32
|
-
}, props.children);
|
|
33
|
-
}
|
|
34
27
|
function useClient() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error("LiveblocksProvider is missing from the react tree");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return client;
|
|
28
|
+
var client = React__namespace.useContext(ClientContext);
|
|
29
|
+
if (null == client) throw new Error("LiveblocksProvider is missing from the react tree");
|
|
30
|
+
return client;
|
|
42
31
|
}
|
|
43
32
|
|
|
44
33
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (info.done) {
|
|
54
|
-
resolve(value);
|
|
55
|
-
} else {
|
|
56
|
-
Promise.resolve(value).then(_next, _throw);
|
|
57
|
-
}
|
|
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);
|
|
58
40
|
}
|
|
59
41
|
|
|
60
42
|
function _asyncToGenerator(fn) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
_next(undefined);
|
|
76
|
-
});
|
|
77
|
-
};
|
|
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
|
+
};
|
|
78
56
|
}
|
|
79
57
|
|
|
80
58
|
function useRerender() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
update = _useReducer[1];
|
|
85
|
-
|
|
86
|
-
return update;
|
|
59
|
+
return React.useReducer((function(x) {
|
|
60
|
+
return x + 1;
|
|
61
|
+
}), 0)[1];
|
|
87
62
|
}
|
|
88
63
|
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
defaultPresence = props.defaultPresence,
|
|
93
|
-
defaultStorageRoot = props.defaultStorageRoot;
|
|
94
|
-
|
|
95
|
-
if (process.env.NODE_ENV !== "production") {
|
|
96
|
-
if (roomId == null) {
|
|
97
|
-
throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (typeof roomId !== "string") {
|
|
101
|
-
throw new Error("RoomProvider id property should be a string.");
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
var client = useClient();
|
|
106
|
-
|
|
107
|
-
var _React$useState = React__namespace.useState(function () {
|
|
108
|
-
return client.enter(roomId, {
|
|
109
|
-
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
110
|
-
defaultStorageRoot: defaultStorageRoot,
|
|
111
|
-
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
112
|
-
});
|
|
113
|
-
}),
|
|
114
|
-
room = _React$useState[0],
|
|
115
|
-
setRoom = _React$useState[1];
|
|
116
|
-
|
|
117
|
-
React__namespace.useEffect(function () {
|
|
118
|
-
setRoom(client.enter(roomId, {
|
|
119
|
-
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
120
|
-
defaultStorageRoot: defaultStorageRoot,
|
|
121
|
-
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
122
|
-
}));
|
|
123
|
-
return function () {
|
|
124
|
-
client.leave(roomId);
|
|
125
|
-
};
|
|
126
|
-
}, [client, roomId]);
|
|
127
|
-
return React__namespace.createElement(RoomContext.Provider, {
|
|
128
|
-
value: room
|
|
129
|
-
}, props.children);
|
|
130
|
-
}
|
|
131
|
-
function useRoom() {
|
|
64
|
+
var _create = function() {
|
|
65
|
+
var RoomContext = React__namespace.createContext(null);
|
|
66
|
+
function useRoom() {
|
|
132
67
|
var room = React__namespace.useContext(RoomContext);
|
|
133
|
-
|
|
134
|
-
if (room == null) {
|
|
135
|
-
throw new Error("RoomProvider is missing from the react tree");
|
|
136
|
-
}
|
|
137
|
-
|
|
68
|
+
if (null == room) throw new Error("RoomProvider is missing from the react tree");
|
|
138
69
|
return room;
|
|
139
|
-
}
|
|
140
|
-
function
|
|
141
|
-
var room = useRoom();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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();
|
|
89
|
+
}
|
|
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();
|
|
148
116
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
117
|
+
}
|
|
118
|
+
}), [ root, room ]), null == root) return {
|
|
119
|
+
status: "loading"
|
|
120
|
+
};
|
|
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);
|
|
168
156
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
room.broadcastEvent(event, options);
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
React__namespace.useEffect(function () {
|
|
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() {
|
|
188
175
|
savedCallback.current = callback;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
var unsubscribe = room.subscribe("error", listener);
|
|
196
|
-
return function () {
|
|
197
|
-
unsubscribe();
|
|
176
|
+
})), React__namespace.useEffect((function() {
|
|
177
|
+
var unsubscribe = room.subscribe("error", (function(e) {
|
|
178
|
+
return savedCallback.current(e);
|
|
179
|
+
}));
|
|
180
|
+
return function() {
|
|
181
|
+
unsubscribe();
|
|
198
182
|
};
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
function
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
React__namespace.useEffect(function () {
|
|
183
|
+
}), [ room ]);
|
|
184
|
+
},
|
|
185
|
+
useEventListener: function(callback) {
|
|
186
|
+
var room = useRoom(), savedCallback = React__namespace.useRef(callback);
|
|
187
|
+
React__namespace.useEffect((function() {
|
|
205
188
|
savedCallback.current = callback;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
189
|
+
})), React__namespace.useEffect((function() {
|
|
190
|
+
var unsubscribe = room.subscribe("event", (function(e) {
|
|
191
|
+
return savedCallback.current(e);
|
|
192
|
+
}));
|
|
193
|
+
return function() {
|
|
194
|
+
unsubscribe();
|
|
210
195
|
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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();
|
|
215
217
|
};
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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();
|
|
227
234
|
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
function fetchStorage() {
|
|
242
|
-
return _fetchStorage.apply(this, arguments);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function _fetchStorage() {
|
|
246
|
-
_fetchStorage = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
|
247
|
-
var storage;
|
|
248
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
249
|
-
while (1) {
|
|
250
|
-
switch (_context.prev = _context.next) {
|
|
251
|
-
case 0:
|
|
252
|
-
_context.next = 2;
|
|
253
|
-
return room.getStorage();
|
|
254
|
-
|
|
255
|
-
case 2:
|
|
256
|
-
storage = _context.sent;
|
|
257
|
-
|
|
258
|
-
if (!didCancel) {
|
|
259
|
-
setState(storage.root);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
case 4:
|
|
263
|
-
case "end":
|
|
264
|
-
return _context.stop();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}, _callee);
|
|
268
|
-
}));
|
|
269
|
-
return _fetchStorage.apply(this, arguments);
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
fetchStorage();
|
|
273
|
-
return function () {
|
|
274
|
-
didCancel = true;
|
|
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();
|
|
275
247
|
};
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
function
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
function
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
function
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
function useCrdt(key, initialCrdt) {
|
|
302
|
-
var _root$get;
|
|
303
|
-
|
|
304
|
-
var room = useRoom();
|
|
305
|
-
|
|
306
|
-
var _useStorage = useStorage(),
|
|
307
|
-
root = _useStorage[0];
|
|
308
|
-
|
|
309
|
-
var rerender = useRerender();
|
|
310
|
-
React__namespace.useEffect(function () {
|
|
311
|
-
if (root == null) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
var crdt = root.get(key);
|
|
316
|
-
|
|
317
|
-
if (crdt == null) {
|
|
318
|
-
crdt = initialCrdt;
|
|
319
|
-
root.set(key, crdt);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
function onRootChange() {
|
|
323
|
-
var newCrdt = root.get(key);
|
|
324
|
-
|
|
325
|
-
if (newCrdt !== crdt) {
|
|
326
|
-
unsubscribeCrdt();
|
|
327
|
-
crdt = newCrdt;
|
|
328
|
-
unsubscribeCrdt = room.subscribe(crdt, rerender);
|
|
329
|
-
rerender();
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
var unsubscribeCrdt = room.subscribe(crdt, rerender);
|
|
334
|
-
var unsubscribeRoot = room.subscribe(root, onRootChange);
|
|
335
|
-
rerender();
|
|
336
|
-
return function () {
|
|
337
|
-
unsubscribeRoot();
|
|
338
|
-
unsubscribeCrdt();
|
|
339
|
-
};
|
|
340
|
-
}, [root, room]);
|
|
341
|
-
return (_root$get = root == null ? void 0 : root.get(key)) != null ? _root$get : null;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
exports.LiveblocksProvider = LiveblocksProvider;
|
|
345
|
-
exports.RoomProvider = RoomProvider;
|
|
346
|
-
exports.useBatch = useBatch;
|
|
347
|
-
exports.useBroadcastEvent = useBroadcastEvent;
|
|
348
|
-
exports.useClient = useClient;
|
|
349
|
-
exports.useErrorListener = useErrorListener;
|
|
350
|
-
exports.useEventListener = useEventListener;
|
|
351
|
-
exports.useHistory = useHistory;
|
|
352
|
-
exports.useList = useList;
|
|
353
|
-
exports.useMap = useMap;
|
|
354
|
-
exports.useMyPresence = useMyPresence;
|
|
355
|
-
exports.useObject = useObject;
|
|
356
|
-
exports.useOthers = useOthers;
|
|
357
|
-
exports.useRedo = useRedo;
|
|
358
|
-
exports.useRoom = useRoom;
|
|
359
|
-
exports.useSelf = useSelf;
|
|
360
|
-
exports.useStorage = useStorage;
|
|
361
|
-
exports.useUndo = useUndo;
|
|
362
|
-
exports.useUpdateMyPresence = useUpdateMyPresence;
|
|
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;
|