@liveblocks/react 0.16.0 → 0.16.3

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.
@@ -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 };
@@ -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 };
@@ -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 room of the nearest RoomProvider above in the react component tree
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 };
@@ -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,27 @@ function RoomProvider(_ref) {
105
104
  }
106
105
 
107
106
  var client = useClient();
107
+
108
+ var _React$useState = React__namespace.useState(function () {
109
+ return client.enter(id, {
110
+ defaultPresence: defaultPresence ? defaultPresence() : undefined,
111
+ defaultStorageRoot: defaultStorageRoot,
112
+ DO_NOT_USE_withoutConnecting: typeof window === "undefined"
113
+ });
114
+ }),
115
+ room = _React$useState[0],
116
+ setRoom = _React$useState[1];
117
+
108
118
  React__namespace.useEffect(function () {
119
+ setRoom(client.enter(id, {
120
+ defaultPresence: defaultPresence ? defaultPresence() : undefined,
121
+ defaultStorageRoot: defaultStorageRoot,
122
+ DO_NOT_USE_withoutConnecting: typeof window === "undefined"
123
+ }));
109
124
  return function () {
110
125
  client.leave(id);
111
126
  };
112
127
  }, [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
128
  return React__namespace.createElement(RoomContext.Provider, {
119
129
  value: room
120
130
  }, children);
@@ -222,9 +232,9 @@ function useSelf() {
222
232
  function useStorage() {
223
233
  var room = useRoom();
224
234
 
225
- var _React$useState = React__namespace.useState(null),
226
- root = _React$useState[0],
227
- setState = _React$useState[1];
235
+ var _React$useState2 = React__namespace.useState(null),
236
+ root = _React$useState2[0],
237
+ setState = _React$useState2[1];
228
238
 
229
239
  React__namespace.useEffect(function () {
230
240
  var didCancel = false;
@@ -336,6 +346,7 @@ exports.LiveblocksProvider = LiveblocksProvider;
336
346
  exports.RoomProvider = RoomProvider;
337
347
  exports.useBatch = useBatch;
338
348
  exports.useBroadcastEvent = useBroadcastEvent;
349
+ exports.useClient = useClient;
339
350
  exports.useErrorListener = useErrorListener;
340
351
  exports.useEventListener = useEventListener;
341
352
  exports.useHistory = useHistory;
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@liveblocks/react",
3
- "version": "0.16.0",
3
+ "version": "0.16.3",
4
4
  "description": "A set of React hooks and providers to use Liveblocks declaratively.",
5
- "main": "./lib/index.js",
6
- "types": "./lib/index.d.ts",
5
+ "main": "./index.js",
6
+ "types": "./index.d.ts",
7
7
  "files": [
8
- "lib/**"
8
+ "**"
9
9
  ],
10
10
  "exports": {
11
11
  "./package.json": "./package.json",
12
12
  ".": {
13
- "types": "./lib/index.d.ts",
14
- "module": "./lib/esm/index.js",
15
- "import": "./lib/esm/index.mjs",
16
- "default": "./lib/index.js"
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,13 @@
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
  "test": "jest --watch"
33
33
  },
34
34
  "license": "Apache-2.0",
35
35
  "peerDependencies": {
36
- "@liveblocks/client": "0.16.0",
36
+ "@liveblocks/client": "0.16.3",
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": "^11.2.5",
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",