@liveblocks/react 0.16.13 → 0.16.16
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 +16 -15
- package/index.js +9 -9
- package/index.mjs +10 -12
- package/package.json +10 -8
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import { Client } from '@liveblocks/client';
|
|
2
3
|
export { Json, JsonObject } from '@liveblocks/client';
|
|
3
4
|
import * as React from 'react';
|
|
@@ -20,38 +21,38 @@ declare function useClient(): Client;
|
|
|
20
21
|
declare const RoomProvider: <TStorage>(props: {
|
|
21
22
|
id: string;
|
|
22
23
|
children: React.ReactNode;
|
|
23
|
-
initialPresence?:
|
|
24
|
+
initialPresence?: Record<string, unknown> | ((roomId: string) => Record<string, unknown>) | undefined;
|
|
24
25
|
initialStorage?: TStorage | ((roomId: string) => TStorage) | undefined;
|
|
25
|
-
defaultPresence?: (() =>
|
|
26
|
+
defaultPresence?: (() => Record<string, unknown>) | undefined;
|
|
26
27
|
defaultStorageRoot?: TStorage | undefined;
|
|
27
28
|
}) => JSX.Element;
|
|
28
29
|
declare const useRoom: () => _liveblocks_client_shared.R;
|
|
29
|
-
declare const useMyPresence: <T extends
|
|
30
|
+
declare const useMyPresence: <T extends Record<string, unknown>>() => [T, (overrides: Partial<T>, options?: {
|
|
30
31
|
addToHistory: boolean;
|
|
31
32
|
} | undefined) => void];
|
|
32
|
-
declare const useUpdateMyPresence: <T extends
|
|
33
|
+
declare const useUpdateMyPresence: <T extends Record<string, unknown>>() => (overrides: Partial<T>, options?: {
|
|
33
34
|
addToHistory: boolean;
|
|
34
35
|
} | undefined) => void;
|
|
35
|
-
declare const useOthers: <T extends
|
|
36
|
+
declare const useOthers: <T extends Record<string, unknown>>() => _liveblocks_client_shared.O<T>;
|
|
36
37
|
declare const useBroadcastEvent: () => (event: any, options?: _liveblocks_client_shared.B | undefined) => void;
|
|
37
38
|
declare const useErrorListener: (callback: (err: Error) => void) => void;
|
|
38
|
-
declare const useEventListener: (callback: ({ connectionId, event, }: {
|
|
39
|
+
declare const useEventListener: <TEvent extends _liveblocks_client_shared.J>(callback: ({ connectionId, event, }: {
|
|
39
40
|
connectionId: number;
|
|
40
|
-
event:
|
|
41
|
+
event: TEvent;
|
|
41
42
|
}) => void) => void;
|
|
42
|
-
declare const useSelf: <TPresence extends
|
|
43
|
-
declare const useStorage: <TStorage extends Record<string, any>>() => [root: _liveblocks_client_shared.
|
|
43
|
+
declare const useSelf: <TPresence extends Record<string, unknown> = Record<string, unknown>>() => _liveblocks_client_shared.U<TPresence> | null;
|
|
44
|
+
declare const useStorage: <TStorage extends Record<string, any>>() => [root: _liveblocks_client_shared.L<TStorage> | null];
|
|
44
45
|
declare const useMap: {
|
|
45
|
-
<TKey extends string, TValue extends _liveblocks_client_shared.
|
|
46
|
-
<TKey_1 extends string, TValue_1 extends _liveblocks_client_shared.
|
|
46
|
+
<TKey extends string, TValue extends _liveblocks_client_shared.e>(key: string): _liveblocks_client_shared.b<TKey, TValue> | null;
|
|
47
|
+
<TKey_1 extends string, TValue_1 extends _liveblocks_client_shared.e>(key: string, entries: readonly (readonly [TKey_1, TValue_1])[] | null): _liveblocks_client_shared.b<TKey_1, TValue_1> | null;
|
|
47
48
|
};
|
|
48
49
|
declare const useList: {
|
|
49
|
-
<TValue extends _liveblocks_client_shared.
|
|
50
|
-
<TValue_1 extends _liveblocks_client_shared.
|
|
50
|
+
<TValue extends _liveblocks_client_shared.e>(key: string): _liveblocks_client_shared.c<TValue> | null;
|
|
51
|
+
<TValue_1 extends _liveblocks_client_shared.e>(key: string, items: TValue_1[]): _liveblocks_client_shared.c<TValue_1> | null;
|
|
51
52
|
};
|
|
52
53
|
declare const useObject: {
|
|
53
|
-
<TData extends _liveblocks_client_shared.
|
|
54
|
-
<TData_1 extends _liveblocks_client_shared.
|
|
54
|
+
<TData extends _liveblocks_client_shared.f>(key: string): _liveblocks_client_shared.L<TData> | null;
|
|
55
|
+
<TData_1 extends _liveblocks_client_shared.f>(key: string, initialData: TData_1): _liveblocks_client_shared.L<TData_1> | null;
|
|
55
56
|
};
|
|
56
57
|
declare const useUndo: () => () => void;
|
|
57
58
|
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.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
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
|
-
savedCallback.current(e);
|
|
191
|
+
return 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.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
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.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
203
|
null);
|
|
204
204
|
},
|
|
205
205
|
useMap: function(key, entries) {
|
|
206
|
-
internal.
|
|
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
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.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
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.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
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.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
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 { deprecateIf } 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
|
+
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"),
|
|
114
|
+
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");
|
|
115
115
|
const client = useClient(), [room, setRoom] = React.useState((() => client.enter(roomId, {
|
|
116
116
|
initialPresence: initialPresence,
|
|
117
117
|
initialStorage: initialStorage,
|
|
@@ -158,9 +158,7 @@ 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 =>
|
|
162
|
-
savedCallback.current(e);
|
|
163
|
-
}));
|
|
161
|
+
const unsubscribe = room.subscribe("event", (e => savedCallback.current(e)));
|
|
164
162
|
return () => {
|
|
165
163
|
unsubscribe();
|
|
166
164
|
};
|
|
@@ -168,15 +166,15 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
168
166
|
},
|
|
169
167
|
useHistory: useHistory,
|
|
170
168
|
useList: function(key, items) {
|
|
171
|
-
|
|
169
|
+
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.`);
|
|
172
170
|
const value = useStorageValue(key, new LiveList(items));
|
|
173
|
-
return "ok" === value.status ? value.value : (
|
|
171
|
+
return "ok" === value.status ? value.value : (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.`),
|
|
174
172
|
null);
|
|
175
173
|
},
|
|
176
174
|
useMap: function(key, entries) {
|
|
177
|
-
|
|
175
|
+
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.`);
|
|
178
176
|
const value = useStorageValue(key, new LiveMap(null != entries ? entries : void 0));
|
|
179
|
-
return "ok" === value.status ? value.value : (
|
|
177
|
+
return "ok" === value.status ? value.value : (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.`),
|
|
180
178
|
null);
|
|
181
179
|
},
|
|
182
180
|
useMyPresence: function() {
|
|
@@ -189,9 +187,9 @@ const {RoomProvider: RoomProvider, useRoom: useRoom, useMyPresence: useMyPresenc
|
|
|
189
187
|
}), [ room ]), [ presence, React.useCallback(((overrides, options) => room.updatePresence(overrides, options)), [ room ]) ];
|
|
190
188
|
},
|
|
191
189
|
useObject: function(key, initialData) {
|
|
192
|
-
|
|
190
|
+
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.`);
|
|
193
191
|
const value = useStorageValue(key, new LiveObject(initialData));
|
|
194
|
-
return "ok" === value.status ? value.value : (
|
|
192
|
+
return "ok" === value.status ? value.value : (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.`),
|
|
195
193
|
null);
|
|
196
194
|
},
|
|
197
195
|
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.16",
|
|
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",
|
|
27
|
+
"test-ci": "jest"
|
|
28
28
|
},
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@liveblocks/client": "0.16.
|
|
31
|
+
"@liveblocks/client": "0.16.16",
|
|
32
32
|
"react": "^16.14.0 || ^17 || ^18"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -42,9 +42,11 @@
|
|
|
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
|
-
"@
|
|
45
|
+
"@types/jest": "^26.0.20",
|
|
46
|
+
"@types/react": "^16.14.0",
|
|
47
|
+
"@types/react-dom": "^17.0.14",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
49
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
48
50
|
"eslint": "^8.12.0",
|
|
49
51
|
"eslint-plugin-import": "^2.26.0",
|
|
50
52
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
@@ -55,7 +57,7 @@
|
|
|
55
57
|
"rollup-plugin-command": "^1.1.3",
|
|
56
58
|
"rollup-plugin-dts": "^4.2.0",
|
|
57
59
|
"rollup-plugin-terser": "^7.0.2",
|
|
58
|
-
"typescript": "^4.
|
|
60
|
+
"typescript": "^4.1.5",
|
|
59
61
|
"whatwg-fetch": "^3.6.2"
|
|
60
62
|
},
|
|
61
63
|
"repository": {
|