@liveblocks/react 0.16.0 → 0.16.1
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/lib/esm/index.js +19 -13
- package/lib/esm/index.mjs +19 -13
- package/lib/index.d.ts +11 -4
- package/lib/index.js +35 -26
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useReducer } from 'react';
|
|
4
|
-
|
|
5
|
-
function useRerender() {
|
|
6
|
-
const [, update] = useReducer((x) => x + 1, 0);
|
|
7
|
-
return update;
|
|
8
|
-
}
|
|
3
|
+
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client';
|
|
9
4
|
|
|
10
5
|
const ClientContext = React.createContext(null);
|
|
11
|
-
const RoomContext = React.createContext(null);
|
|
12
6
|
function LiveblocksProvider(props) {
|
|
13
7
|
return /* @__PURE__ */ React.createElement(ClientContext.Provider, {
|
|
14
8
|
value: props.client
|
|
@@ -21,6 +15,13 @@ function useClient() {
|
|
|
21
15
|
}
|
|
22
16
|
return client;
|
|
23
17
|
}
|
|
18
|
+
|
|
19
|
+
function useRerender() {
|
|
20
|
+
const [, update] = useReducer((x) => x + 1, 0);
|
|
21
|
+
return update;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const RoomContext = React.createContext(null);
|
|
24
25
|
function RoomProvider({
|
|
25
26
|
id,
|
|
26
27
|
children,
|
|
@@ -36,16 +37,21 @@ function RoomProvider({
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
const client = useClient();
|
|
40
|
+
const [room, setRoom] = React.useState(client.enter(id, {
|
|
41
|
+
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
42
|
+
defaultStorageRoot,
|
|
43
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
44
|
+
}));
|
|
39
45
|
React.useEffect(() => {
|
|
46
|
+
setRoom(client.enter(id, {
|
|
47
|
+
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
48
|
+
defaultStorageRoot,
|
|
49
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
50
|
+
}));
|
|
40
51
|
return () => {
|
|
41
52
|
client.leave(id);
|
|
42
53
|
};
|
|
43
54
|
}, [client, id]);
|
|
44
|
-
const room = client.getRoom(id) || client.enter(id, {
|
|
45
|
-
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
46
|
-
defaultStorageRoot,
|
|
47
|
-
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
48
|
-
});
|
|
49
55
|
return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
|
|
50
56
|
value: room
|
|
51
57
|
}, children);
|
|
@@ -207,4 +213,4 @@ function useCrdt(key, initialCrdt) {
|
|
|
207
213
|
return (_a = root == null ? void 0 : root.get(key)) != null ? _a : null;
|
|
208
214
|
}
|
|
209
215
|
|
|
210
|
-
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
|
216
|
+
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
package/lib/esm/index.mjs
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client';
|
|
2
1
|
import * as React from 'react';
|
|
3
2
|
import { useReducer } from 'react';
|
|
4
|
-
|
|
5
|
-
function useRerender() {
|
|
6
|
-
const [, update] = useReducer((x) => x + 1, 0);
|
|
7
|
-
return update;
|
|
8
|
-
}
|
|
3
|
+
import { LiveMap, LiveList, LiveObject } from '@liveblocks/client';
|
|
9
4
|
|
|
10
5
|
const ClientContext = React.createContext(null);
|
|
11
|
-
const RoomContext = React.createContext(null);
|
|
12
6
|
function LiveblocksProvider(props) {
|
|
13
7
|
return /* @__PURE__ */ React.createElement(ClientContext.Provider, {
|
|
14
8
|
value: props.client
|
|
@@ -21,6 +15,13 @@ function useClient() {
|
|
|
21
15
|
}
|
|
22
16
|
return client;
|
|
23
17
|
}
|
|
18
|
+
|
|
19
|
+
function useRerender() {
|
|
20
|
+
const [, update] = useReducer((x) => x + 1, 0);
|
|
21
|
+
return update;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const RoomContext = React.createContext(null);
|
|
24
25
|
function RoomProvider({
|
|
25
26
|
id,
|
|
26
27
|
children,
|
|
@@ -36,16 +37,21 @@ function RoomProvider({
|
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
const client = useClient();
|
|
40
|
+
const [room, setRoom] = React.useState(client.enter(id, {
|
|
41
|
+
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
42
|
+
defaultStorageRoot,
|
|
43
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
44
|
+
}));
|
|
39
45
|
React.useEffect(() => {
|
|
46
|
+
setRoom(client.enter(id, {
|
|
47
|
+
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
48
|
+
defaultStorageRoot,
|
|
49
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
50
|
+
}));
|
|
40
51
|
return () => {
|
|
41
52
|
client.leave(id);
|
|
42
53
|
};
|
|
43
54
|
}, [client, id]);
|
|
44
|
-
const room = client.getRoom(id) || client.enter(id, {
|
|
45
|
-
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
46
|
-
defaultStorageRoot,
|
|
47
|
-
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
48
|
-
});
|
|
49
55
|
return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
|
|
50
56
|
value: room
|
|
51
57
|
}, children);
|
|
@@ -207,4 +213,4 @@ function useCrdt(key, initialCrdt) {
|
|
|
207
213
|
return (_a = root == null ? void 0 : root.get(key)) != null ? _a : null;
|
|
208
214
|
}
|
|
209
215
|
|
|
210
|
-
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
|
216
|
+
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Room, Presence, Others, BroadcastOptions, Json, User, LiveObject, Lson, LiveMap, LiveList, LsonObject, History, Client } from '@liveblocks/client';
|
|
2
|
-
export { Json, JsonObject } from '@liveblocks/client';
|
|
3
1
|
import * as React from 'react';
|
|
2
|
+
import { Client, Room, Presence, Others, BroadcastOptions, Json, User, LiveObject, Lson, LiveMap, LiveList, LsonObject, History } from '@liveblocks/client';
|
|
3
|
+
export { Json, JsonObject } from '@liveblocks/client';
|
|
4
4
|
|
|
5
5
|
declare type LiveblocksProviderProps = {
|
|
6
6
|
children: React.ReactNode;
|
|
@@ -10,6 +10,12 @@ declare type LiveblocksProviderProps = {
|
|
|
10
10
|
* Makes the Liveblocks client available in the component hierarchy below.
|
|
11
11
|
*/
|
|
12
12
|
declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the Client of the nearest LiveblocksProvider above in the React
|
|
15
|
+
* component tree.
|
|
16
|
+
*/
|
|
17
|
+
declare function useClient(): Client;
|
|
18
|
+
|
|
13
19
|
declare type RoomProviderProps<TStorageRoot> = {
|
|
14
20
|
/**
|
|
15
21
|
* The id of the room you want to connect to
|
|
@@ -30,7 +36,8 @@ declare type RoomProviderProps<TStorageRoot> = {
|
|
|
30
36
|
*/
|
|
31
37
|
declare function RoomProvider<TStorageRoot>({ id, children, defaultPresence, defaultStorageRoot, }: RoomProviderProps<TStorageRoot>): JSX.Element;
|
|
32
38
|
/**
|
|
33
|
-
* Returns the
|
|
39
|
+
* Returns the Room of the nearest RoomProvider above in the React component
|
|
40
|
+
* tree.
|
|
34
41
|
*/
|
|
35
42
|
declare function useRoom(): Room;
|
|
36
43
|
/**
|
|
@@ -201,4 +208,4 @@ declare function useBatch(): (callback: () => void) => void;
|
|
|
201
208
|
*/
|
|
202
209
|
declare function useHistory(): History;
|
|
203
210
|
|
|
204
|
-
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
|
211
|
+
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useClient, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var client = require('@liveblocks/client');
|
|
6
5
|
var React = require('react');
|
|
6
|
+
var client = require('@liveblocks/client');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
9
9
|
if (e && e.__esModule) return e;
|
|
@@ -25,6 +25,22 @@ function _interopNamespace(e) {
|
|
|
25
25
|
|
|
26
26
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
27
27
|
|
|
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
|
+
function useClient() {
|
|
35
|
+
var client = React__namespace.useContext(ClientContext);
|
|
36
|
+
|
|
37
|
+
if (client == null) {
|
|
38
|
+
throw new Error("LiveblocksProvider is missing from the react tree");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return client;
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
29
45
|
try {
|
|
30
46
|
var info = gen[key](arg);
|
|
@@ -70,24 +86,7 @@ function useRerender() {
|
|
|
70
86
|
return update;
|
|
71
87
|
}
|
|
72
88
|
|
|
73
|
-
var ClientContext = React__namespace.createContext(null);
|
|
74
89
|
var RoomContext = React__namespace.createContext(null);
|
|
75
|
-
function LiveblocksProvider(props) {
|
|
76
|
-
return React__namespace.createElement(ClientContext.Provider, {
|
|
77
|
-
value: props.client
|
|
78
|
-
}, props.children);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function useClient() {
|
|
82
|
-
var client = React__namespace.useContext(ClientContext);
|
|
83
|
-
|
|
84
|
-
if (client == null) {
|
|
85
|
-
throw new Error("LiveblocksProvider is missing from the react tree");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return client;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
90
|
function RoomProvider(_ref) {
|
|
92
91
|
var id = _ref.id,
|
|
93
92
|
children = _ref.children,
|
|
@@ -105,16 +104,25 @@ function RoomProvider(_ref) {
|
|
|
105
104
|
}
|
|
106
105
|
|
|
107
106
|
var client = useClient();
|
|
107
|
+
|
|
108
|
+
var _React$useState = React__namespace.useState(client.enter(id, {
|
|
109
|
+
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
110
|
+
defaultStorageRoot: defaultStorageRoot,
|
|
111
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
112
|
+
})),
|
|
113
|
+
room = _React$useState[0],
|
|
114
|
+
setRoom = _React$useState[1];
|
|
115
|
+
|
|
108
116
|
React__namespace.useEffect(function () {
|
|
117
|
+
setRoom(client.enter(id, {
|
|
118
|
+
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
119
|
+
defaultStorageRoot: defaultStorageRoot,
|
|
120
|
+
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
121
|
+
}));
|
|
109
122
|
return function () {
|
|
110
123
|
client.leave(id);
|
|
111
124
|
};
|
|
112
125
|
}, [client, id]);
|
|
113
|
-
var room = client.getRoom(id) || client.enter(id, {
|
|
114
|
-
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
115
|
-
defaultStorageRoot: defaultStorageRoot,
|
|
116
|
-
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
117
|
-
});
|
|
118
126
|
return React__namespace.createElement(RoomContext.Provider, {
|
|
119
127
|
value: room
|
|
120
128
|
}, children);
|
|
@@ -222,9 +230,9 @@ function useSelf() {
|
|
|
222
230
|
function useStorage() {
|
|
223
231
|
var room = useRoom();
|
|
224
232
|
|
|
225
|
-
var _React$
|
|
226
|
-
root = _React$
|
|
227
|
-
setState = _React$
|
|
233
|
+
var _React$useState2 = React__namespace.useState(null),
|
|
234
|
+
root = _React$useState2[0],
|
|
235
|
+
setState = _React$useState2[1];
|
|
228
236
|
|
|
229
237
|
React__namespace.useEffect(function () {
|
|
230
238
|
var didCancel = false;
|
|
@@ -336,6 +344,7 @@ exports.LiveblocksProvider = LiveblocksProvider;
|
|
|
336
344
|
exports.RoomProvider = RoomProvider;
|
|
337
345
|
exports.useBatch = useBatch;
|
|
338
346
|
exports.useBroadcastEvent = useBroadcastEvent;
|
|
347
|
+
exports.useClient = useClient;
|
|
339
348
|
exports.useErrorListener = useErrorListener;
|
|
340
349
|
exports.useEventListener = useEventListener;
|
|
341
350
|
exports.useHistory = useHistory;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@liveblocks/client": "0.16.
|
|
36
|
+
"@liveblocks/client": "0.16.1",
|
|
37
37
|
"react": "^16.14.0 || ^17 || ^18"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@rollup/plugin-node-resolve": "^11.2.1",
|
|
46
46
|
"@rollup/plugin-typescript": "^8.3.1",
|
|
47
47
|
"@testing-library/jest-dom": "^5.11.9",
|
|
48
|
-
"@testing-library/react": "^
|
|
48
|
+
"@testing-library/react": "^13.1.1",
|
|
49
49
|
"@types/jest": "^26.0.20",
|
|
50
50
|
"@types/react": "^16.14.0",
|
|
51
51
|
"@types/react-dom": "^17.0.14",
|