@liveblocks/react 0.16.12 → 0.16.13
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 +15 -16
- package/index.js +9 -9
- package/index.mjs +12 -10
- package/package.json +8 -10
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { Client } from '@liveblocks/client';
|
|
3
2
|
export { Json, JsonObject } from '@liveblocks/client';
|
|
4
3
|
import * as React from 'react';
|
|
@@ -21,38 +20,38 @@ declare function useClient(): Client;
|
|
|
21
20
|
declare const RoomProvider: <TStorage>(props: {
|
|
22
21
|
id: string;
|
|
23
22
|
children: React.ReactNode;
|
|
24
|
-
initialPresence?:
|
|
23
|
+
initialPresence?: _liveblocks_client_shared.P | ((roomId: string) => _liveblocks_client_shared.P) | undefined;
|
|
25
24
|
initialStorage?: TStorage | ((roomId: string) => TStorage) | undefined;
|
|
26
|
-
defaultPresence?: (() =>
|
|
25
|
+
defaultPresence?: (() => _liveblocks_client_shared.P) | undefined;
|
|
27
26
|
defaultStorageRoot?: TStorage | undefined;
|
|
28
27
|
}) => JSX.Element;
|
|
29
28
|
declare const useRoom: () => _liveblocks_client_shared.R;
|
|
30
|
-
declare const useMyPresence: <T extends
|
|
29
|
+
declare const useMyPresence: <T extends _liveblocks_client_shared.P>() => [T, (overrides: Partial<T>, options?: {
|
|
31
30
|
addToHistory: boolean;
|
|
32
31
|
} | undefined) => void];
|
|
33
|
-
declare const useUpdateMyPresence: <T extends
|
|
32
|
+
declare const useUpdateMyPresence: <T extends _liveblocks_client_shared.P>() => (overrides: Partial<T>, options?: {
|
|
34
33
|
addToHistory: boolean;
|
|
35
34
|
} | undefined) => void;
|
|
36
|
-
declare const useOthers: <T extends
|
|
35
|
+
declare const useOthers: <T extends _liveblocks_client_shared.P>() => _liveblocks_client_shared.O<T>;
|
|
37
36
|
declare const useBroadcastEvent: () => (event: any, options?: _liveblocks_client_shared.B | undefined) => void;
|
|
38
37
|
declare const useErrorListener: (callback: (err: Error) => void) => void;
|
|
39
|
-
declare const useEventListener:
|
|
38
|
+
declare const useEventListener: (callback: ({ connectionId, event, }: {
|
|
40
39
|
connectionId: number;
|
|
41
|
-
event:
|
|
40
|
+
event: _liveblocks_client_shared.J;
|
|
42
41
|
}) => void) => void;
|
|
43
|
-
declare const useSelf: <TPresence extends
|
|
44
|
-
declare const useStorage: <TStorage extends Record<string, any>>() => [root: _liveblocks_client_shared.
|
|
42
|
+
declare const useSelf: <TPresence extends _liveblocks_client_shared.P = _liveblocks_client_shared.P>() => _liveblocks_client_shared.U<TPresence> | null;
|
|
43
|
+
declare const useStorage: <TStorage extends Record<string, any>>() => [root: _liveblocks_client_shared.c<TStorage> | null];
|
|
45
44
|
declare const useMap: {
|
|
46
|
-
<TKey extends string, TValue extends _liveblocks_client_shared.
|
|
47
|
-
<TKey_1 extends string, TValue_1 extends _liveblocks_client_shared.
|
|
45
|
+
<TKey extends string, TValue extends _liveblocks_client_shared.f>(key: string): _liveblocks_client_shared.b<TKey, TValue> | null;
|
|
46
|
+
<TKey_1 extends string, TValue_1 extends _liveblocks_client_shared.f>(key: string, entries: readonly (readonly [TKey_1, TValue_1])[] | null): _liveblocks_client_shared.b<TKey_1, TValue_1> | null;
|
|
48
47
|
};
|
|
49
48
|
declare const useList: {
|
|
50
|
-
<TValue extends _liveblocks_client_shared.
|
|
51
|
-
<TValue_1 extends _liveblocks_client_shared.
|
|
49
|
+
<TValue extends _liveblocks_client_shared.f>(key: string): _liveblocks_client_shared.L<TValue> | null;
|
|
50
|
+
<TValue_1 extends _liveblocks_client_shared.f>(key: string, items: TValue_1[]): _liveblocks_client_shared.L<TValue_1> | null;
|
|
52
51
|
};
|
|
53
52
|
declare const useObject: {
|
|
54
|
-
<TData extends _liveblocks_client_shared.
|
|
55
|
-
<TData_1 extends _liveblocks_client_shared.
|
|
53
|
+
<TData extends _liveblocks_client_shared.g>(key: string): _liveblocks_client_shared.c<TData> | null;
|
|
54
|
+
<TData_1 extends _liveblocks_client_shared.g>(key: string, initialData: TData_1): _liveblocks_client_shared.c<TData_1> | null;
|
|
56
55
|
};
|
|
57
56
|
declare const useUndo: () => () => void;
|
|
58
57
|
declare const useRedo: () => () => void;
|
package/index.js
CHANGED
|
@@ -133,8 +133,8 @@ var _create = function() {
|
|
|
133
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
134
|
if ("string" != typeof roomId) throw new Error("RoomProvider id property should be a string.");
|
|
135
135
|
}
|
|
136
|
-
internal.
|
|
137
|
-
internal.
|
|
136
|
+
internal.errorIf(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"),
|
|
137
|
+
internal.errorIf(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");
|
|
138
138
|
var client = useClient(), _React$useState = React__namespace.useState((function() {
|
|
139
139
|
return client.enter(roomId, {
|
|
140
140
|
initialPresence: initialPresence,
|
|
@@ -188,7 +188,7 @@ var _create = function() {
|
|
|
188
188
|
savedCallback.current = callback;
|
|
189
189
|
})), React__namespace.useEffect((function() {
|
|
190
190
|
var unsubscribe = room.subscribe("event", (function(e) {
|
|
191
|
-
|
|
191
|
+
savedCallback.current(e);
|
|
192
192
|
}));
|
|
193
193
|
return function() {
|
|
194
194
|
unsubscribe();
|
|
@@ -197,15 +197,15 @@ var _create = function() {
|
|
|
197
197
|
},
|
|
198
198
|
useHistory: useHistory,
|
|
199
199
|
useList: function(key, items) {
|
|
200
|
-
internal.
|
|
200
|
+
internal.errorIf(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
201
|
var value = useStorageValue(key, new client.LiveList(items));
|
|
202
|
-
return "ok" === value.status ? value.value : (internal.
|
|
202
|
+
return "ok" === value.status ? value.value : (internal.errorIf("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
203
|
null);
|
|
204
204
|
},
|
|
205
205
|
useMap: function(key, entries) {
|
|
206
|
-
internal.
|
|
206
|
+
internal.errorIf(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
207
|
var value = useStorageValue(key, new client.LiveMap(null != entries ? entries : void 0));
|
|
208
|
-
return "ok" === value.status ? value.value : (internal.
|
|
208
|
+
return "ok" === value.status ? value.value : (internal.errorIf("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
209
|
null);
|
|
210
210
|
},
|
|
211
211
|
useMyPresence: function() {
|
|
@@ -220,9 +220,9 @@ var _create = function() {
|
|
|
220
220
|
}), [ room ]) ];
|
|
221
221
|
},
|
|
222
222
|
useObject: function(key, initialData) {
|
|
223
|
-
internal.
|
|
223
|
+
internal.errorIf(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
224
|
var value = useStorageValue(key, new client.LiveObject(initialData));
|
|
225
|
-
return "ok" === value.status ? value.value : (internal.
|
|
225
|
+
return "ok" === value.status ? value.value : (internal.errorIf("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
226
|
null);
|
|
227
227
|
},
|
|
228
228
|
useOthers: function() {
|
package/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { useReducer } from "react";
|
|
|
4
4
|
|
|
5
5
|
import { LiveMap, LiveList, LiveObject } from "@liveblocks/client";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { errorIf } from "@liveblocks/client/internal";
|
|
8
8
|
|
|
9
9
|
const ClientContext = React.createContext(null);
|
|
10
10
|
|
|
@@ -110,8 +110,8 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
110
110
|
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");
|
|
111
111
|
if ("string" != typeof roomId) throw new Error("RoomProvider id property should be a string.");
|
|
112
112
|
}
|
|
113
|
-
|
|
114
|
-
|
|
113
|
+
errorIf(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"),
|
|
114
|
+
errorIf(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");
|
|
115
115
|
const client = useClient(), [room, setRoom] = React.useState((() => client.enter(roomId, {
|
|
116
116
|
initialPresence: initialPresence,
|
|
117
117
|
initialStorage: initialStorage,
|
|
@@ -158,7 +158,9 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
158
158
|
React.useEffect((() => {
|
|
159
159
|
savedCallback.current = callback;
|
|
160
160
|
})), React.useEffect((() => {
|
|
161
|
-
const unsubscribe = room.subscribe("event", (e =>
|
|
161
|
+
const unsubscribe = room.subscribe("event", (e => {
|
|
162
|
+
savedCallback.current(e);
|
|
163
|
+
}));
|
|
162
164
|
return () => {
|
|
163
165
|
unsubscribe();
|
|
164
166
|
};
|
|
@@ -166,15 +168,15 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
166
168
|
},
|
|
167
169
|
useHistory: useHistory,
|
|
168
170
|
useList: function(key, items) {
|
|
169
|
-
|
|
171
|
+
errorIf(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.`);
|
|
170
172
|
const value = useStorageValue(key, new LiveList(items));
|
|
171
|
-
return "ok" === value.status ? value.value : (
|
|
173
|
+
return "ok" === value.status ? value.value : (errorIf("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.`),
|
|
172
174
|
null);
|
|
173
175
|
},
|
|
174
176
|
useMap: function(key, entries) {
|
|
175
|
-
|
|
177
|
+
errorIf(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.`);
|
|
176
178
|
const value = useStorageValue(key, new LiveMap(null != entries ? entries : void 0));
|
|
177
|
-
return "ok" === value.status ? value.value : (
|
|
179
|
+
return "ok" === value.status ? value.value : (errorIf("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.`),
|
|
178
180
|
null);
|
|
179
181
|
},
|
|
180
182
|
useMyPresence: function() {
|
|
@@ -187,9 +189,9 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
187
189
|
}), [ room ]), [ presence, React.useCallback(((overrides, options) => room.updatePresence(overrides, options)), [ room ]) ];
|
|
188
190
|
},
|
|
189
191
|
useObject: function(key, initialData) {
|
|
190
|
-
|
|
192
|
+
errorIf(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.`);
|
|
191
193
|
const value = useStorageValue(key, new LiveObject(initialData));
|
|
192
|
-
return "ok" === value.status ? value.value : (
|
|
194
|
+
return "ok" === value.status ? value.value : (errorIf("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.`),
|
|
193
195
|
null);
|
|
194
196
|
},
|
|
195
197
|
useOthers: function() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.13",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"module": "./index.mjs",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
"start": "rollup -c -w",
|
|
24
24
|
"format": "eslint --fix src/ && prettier --write src/",
|
|
25
25
|
"lint": "eslint src/",
|
|
26
|
-
"test": "jest --watch",
|
|
27
|
-
"test-ci": "jest"
|
|
26
|
+
"test": "jest --watch --silent --verbose",
|
|
27
|
+
"test-ci": "jest --silent --verbose"
|
|
28
28
|
},
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@liveblocks/client": "0.16.
|
|
31
|
+
"@liveblocks/client": "0.16.13",
|
|
32
32
|
"react": "^16.14.0 || ^17 || ^18"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -42,11 +42,9 @@
|
|
|
42
42
|
"@rollup/plugin-typescript": "^8.3.1",
|
|
43
43
|
"@testing-library/jest-dom": "^5.11.9",
|
|
44
44
|
"@testing-library/react": "^13.1.1",
|
|
45
|
-
"@types/jest": "^26.0.
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
49
|
-
"@typescript-eslint/parser": "^5.18.0",
|
|
45
|
+
"@types/jest": "^26.0.24",
|
|
46
|
+
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
47
|
+
"@typescript-eslint/parser": "^5.26.0",
|
|
50
48
|
"eslint": "^8.12.0",
|
|
51
49
|
"eslint-plugin-import": "^2.26.0",
|
|
52
50
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
@@ -57,7 +55,7 @@
|
|
|
57
55
|
"rollup-plugin-command": "^1.1.3",
|
|
58
56
|
"rollup-plugin-dts": "^4.2.0",
|
|
59
57
|
"rollup-plugin-terser": "^7.0.2",
|
|
60
|
-
"typescript": "^4.
|
|
58
|
+
"typescript": "^4.7.2",
|
|
61
59
|
"whatwg-fetch": "^3.6.2"
|
|
62
60
|
},
|
|
63
61
|
"repository": {
|