@liveblocks/react 0.16.1 → 0.16.4-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.
- package/{lib/esm → esm}/index.js +9 -13
- package/{lib/esm → esm}/index.mjs +9 -13
- package/{lib/index.d.ts → index.d.ts} +5 -5
- package/{lib/index.js → index.js} +17 -16
- package/package.json +13 -11
package/{lib/esm → esm}/index.js
RENAMED
|
@@ -22,39 +22,35 @@ function useRerender() {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const RoomContext = React.createContext(null);
|
|
25
|
-
function RoomProvider({
|
|
26
|
-
id,
|
|
27
|
-
children,
|
|
28
|
-
defaultPresence,
|
|
29
|
-
defaultStorageRoot
|
|
30
|
-
}) {
|
|
25
|
+
function RoomProvider(props) {
|
|
26
|
+
const { id: roomId, defaultPresence, defaultStorageRoot } = props;
|
|
31
27
|
if (process.env.NODE_ENV !== "production") {
|
|
32
|
-
if (
|
|
28
|
+
if (roomId == null) {
|
|
33
29
|
throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
|
|
34
30
|
}
|
|
35
|
-
if (typeof
|
|
31
|
+
if (typeof roomId !== "string") {
|
|
36
32
|
throw new Error("RoomProvider id property should be a string.");
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
const client = useClient();
|
|
40
|
-
const [room, setRoom] = React.useState(client.enter(
|
|
36
|
+
const [room, setRoom] = React.useState(() => client.enter(roomId, {
|
|
41
37
|
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
42
38
|
defaultStorageRoot,
|
|
43
39
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
44
40
|
}));
|
|
45
41
|
React.useEffect(() => {
|
|
46
|
-
setRoom(client.enter(
|
|
42
|
+
setRoom(client.enter(roomId, {
|
|
47
43
|
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
48
44
|
defaultStorageRoot,
|
|
49
45
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
50
46
|
}));
|
|
51
47
|
return () => {
|
|
52
|
-
client.leave(
|
|
48
|
+
client.leave(roomId);
|
|
53
49
|
};
|
|
54
|
-
}, [client,
|
|
50
|
+
}, [client, roomId]);
|
|
55
51
|
return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
|
|
56
52
|
value: room
|
|
57
|
-
}, children);
|
|
53
|
+
}, props.children);
|
|
58
54
|
}
|
|
59
55
|
function useRoom() {
|
|
60
56
|
const room = React.useContext(RoomContext);
|
|
@@ -22,39 +22,35 @@ function useRerender() {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const RoomContext = React.createContext(null);
|
|
25
|
-
function RoomProvider({
|
|
26
|
-
id,
|
|
27
|
-
children,
|
|
28
|
-
defaultPresence,
|
|
29
|
-
defaultStorageRoot
|
|
30
|
-
}) {
|
|
25
|
+
function RoomProvider(props) {
|
|
26
|
+
const { id: roomId, defaultPresence, defaultStorageRoot } = props;
|
|
31
27
|
if (process.env.NODE_ENV !== "production") {
|
|
32
|
-
if (
|
|
28
|
+
if (roomId == null) {
|
|
33
29
|
throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
|
|
34
30
|
}
|
|
35
|
-
if (typeof
|
|
31
|
+
if (typeof roomId !== "string") {
|
|
36
32
|
throw new Error("RoomProvider id property should be a string.");
|
|
37
33
|
}
|
|
38
34
|
}
|
|
39
35
|
const client = useClient();
|
|
40
|
-
const [room, setRoom] = React.useState(client.enter(
|
|
36
|
+
const [room, setRoom] = React.useState(() => client.enter(roomId, {
|
|
41
37
|
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
42
38
|
defaultStorageRoot,
|
|
43
39
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
44
40
|
}));
|
|
45
41
|
React.useEffect(() => {
|
|
46
|
-
setRoom(client.enter(
|
|
42
|
+
setRoom(client.enter(roomId, {
|
|
47
43
|
defaultPresence: defaultPresence ? defaultPresence() : void 0,
|
|
48
44
|
defaultStorageRoot,
|
|
49
45
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
50
46
|
}));
|
|
51
47
|
return () => {
|
|
52
|
-
client.leave(
|
|
48
|
+
client.leave(roomId);
|
|
53
49
|
};
|
|
54
|
-
}, [client,
|
|
50
|
+
}, [client, roomId]);
|
|
55
51
|
return /* @__PURE__ */ React.createElement(RoomContext.Provider, {
|
|
56
52
|
value: room
|
|
57
|
-
}, children);
|
|
53
|
+
}, props.children);
|
|
58
54
|
}
|
|
59
55
|
function useRoom() {
|
|
60
56
|
const room = React.useContext(RoomContext);
|
|
@@ -16,7 +16,7 @@ declare function LiveblocksProvider(props: LiveblocksProviderProps): JSX.Element
|
|
|
16
16
|
*/
|
|
17
17
|
declare function useClient(): Client;
|
|
18
18
|
|
|
19
|
-
declare type RoomProviderProps<
|
|
19
|
+
declare type RoomProviderProps<TStorage> = {
|
|
20
20
|
/**
|
|
21
21
|
* The id of the room you want to connect to
|
|
22
22
|
*/
|
|
@@ -26,7 +26,7 @@ declare type RoomProviderProps<TStorageRoot> = {
|
|
|
26
26
|
* If ommited, the default presence will be an empty object
|
|
27
27
|
*/
|
|
28
28
|
defaultPresence?: () => Presence;
|
|
29
|
-
defaultStorageRoot?:
|
|
29
|
+
defaultStorageRoot?: TStorage;
|
|
30
30
|
children: React.ReactNode;
|
|
31
31
|
};
|
|
32
32
|
/**
|
|
@@ -34,7 +34,7 @@ declare type RoomProviderProps<TStorageRoot> = {
|
|
|
34
34
|
* When this component is unmounted, the current user leave the room.
|
|
35
35
|
* That means that you can't have 2 RoomProvider with the same room id in your react tree.
|
|
36
36
|
*/
|
|
37
|
-
declare function RoomProvider<
|
|
37
|
+
declare function RoomProvider<TStorage>(props: RoomProviderProps<TStorage>): JSX.Element;
|
|
38
38
|
/**
|
|
39
39
|
* Returns the Room of the nearest RoomProvider above in the React component
|
|
40
40
|
* tree.
|
|
@@ -142,8 +142,8 @@ declare function useEventListener<TEvent extends Json>(callback: ({ connectionId
|
|
|
142
142
|
* const user = useSelf();
|
|
143
143
|
*/
|
|
144
144
|
declare function useSelf<TPresence extends Presence = Presence>(): User<TPresence> | null;
|
|
145
|
-
declare function useStorage<
|
|
146
|
-
root: LiveObject<
|
|
145
|
+
declare function useStorage<TStorage extends Record<string, any>>(): [
|
|
146
|
+
root: LiveObject<TStorage> | null
|
|
147
147
|
];
|
|
148
148
|
/**
|
|
149
149
|
* Returns the LiveMap associated with the provided key. If the LiveMap does not exist, a new empty LiveMap will be created.
|
|
@@ -87,45 +87,46 @@ function useRerender() {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
var RoomContext = React__namespace.createContext(null);
|
|
90
|
-
function RoomProvider(
|
|
91
|
-
var
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
defaultStorageRoot = _ref.defaultStorageRoot;
|
|
90
|
+
function RoomProvider(props) {
|
|
91
|
+
var roomId = props.id,
|
|
92
|
+
defaultPresence = props.defaultPresence,
|
|
93
|
+
defaultStorageRoot = props.defaultStorageRoot;
|
|
95
94
|
|
|
96
95
|
if (process.env.NODE_ENV !== "production") {
|
|
97
|
-
if (
|
|
96
|
+
if (roomId == null) {
|
|
98
97
|
throw new Error("RoomProvider id property is required. For more information: https://liveblocks.io/docs/errors/liveblocks-react/RoomProvider-id-property-is-required");
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
if (typeof
|
|
100
|
+
if (typeof roomId !== "string") {
|
|
102
101
|
throw new Error("RoomProvider id property should be a string.");
|
|
103
102
|
}
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
var client = useClient();
|
|
107
106
|
|
|
108
|
-
var _React$useState = React__namespace.useState(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
+
}),
|
|
113
114
|
room = _React$useState[0],
|
|
114
115
|
setRoom = _React$useState[1];
|
|
115
116
|
|
|
116
117
|
React__namespace.useEffect(function () {
|
|
117
|
-
setRoom(client.enter(
|
|
118
|
+
setRoom(client.enter(roomId, {
|
|
118
119
|
defaultPresence: defaultPresence ? defaultPresence() : undefined,
|
|
119
120
|
defaultStorageRoot: defaultStorageRoot,
|
|
120
121
|
DO_NOT_USE_withoutConnecting: typeof window === "undefined"
|
|
121
122
|
}));
|
|
122
123
|
return function () {
|
|
123
|
-
client.leave(
|
|
124
|
+
client.leave(roomId);
|
|
124
125
|
};
|
|
125
|
-
}, [client,
|
|
126
|
+
}, [client, roomId]);
|
|
126
127
|
return React__namespace.createElement(RoomContext.Provider, {
|
|
127
128
|
value: room
|
|
128
|
-
}, children);
|
|
129
|
+
}, props.children);
|
|
129
130
|
}
|
|
130
131
|
function useRoom() {
|
|
131
132
|
var room = React__namespace.useContext(RoomContext);
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.4-beta1",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively.",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
8
|
+
"**"
|
|
9
9
|
],
|
|
10
10
|
"exports": {
|
|
11
11
|
"./package.json": "./package.json",
|
|
12
12
|
".": {
|
|
13
|
-
"types": "./
|
|
14
|
-
"module": "./
|
|
15
|
-
"import": "./
|
|
16
|
-
"default": "./
|
|
13
|
+
"types": "./index.d.ts",
|
|
14
|
+
"module": "./esm/index.js",
|
|
15
|
+
"import": "./esm/index.mjs",
|
|
16
|
+
"default": "./index.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"keywords": [
|
|
@@ -27,13 +27,15 @@
|
|
|
27
27
|
"url": "https://github.com/liveblocks/liveblocks/issues"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "rollup -c",
|
|
30
|
+
"build": "rollup -c && cp ./package.json ./README.md ./lib",
|
|
31
31
|
"start": "rollup -c -w",
|
|
32
|
-
"
|
|
32
|
+
"lint": "eslint src/",
|
|
33
|
+
"test": "jest --watch",
|
|
34
|
+
"test-ci": "jest"
|
|
33
35
|
},
|
|
34
36
|
"license": "Apache-2.0",
|
|
35
37
|
"peerDependencies": {
|
|
36
|
-
"@liveblocks/client": "0.16.
|
|
38
|
+
"@liveblocks/client": "0.16.4-beta1",
|
|
37
39
|
"react": "^16.14.0 || ^17 || ^18"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|