@liveblocks/react 0.15.10 → 0.16.0
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/README.md +15 -3
- package/lib/esm/index.js +4 -10
- package/lib/esm/index.mjs +4 -10
- package/lib/index.d.ts +9 -13
- package/lib/index.js +7 -25
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<a href="https://liveblocks.io">
|
|
3
|
-
<img src="https://
|
|
3
|
+
<img src="https://raw.githubusercontent.com/liveblocks/liveblocks/main/.github/assets/header.svg" alt="Liveblocks" />
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# `@liveblocks/react`
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<p>
|
|
10
|
+
<a href="https://npmjs.org/package/@liveblocks/react">
|
|
11
|
+
<img src="https://img.shields.io/npm/v/@liveblocks/react?style=flat&label=npm&color=c33" alt="NPM" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://bundlephobia.com/package/@liveblocks/react">
|
|
14
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@liveblocks/react?style=flat&label=size&color=09f" alt="Size" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/liveblocks/liveblocks/blob/main/LICENSE">
|
|
17
|
+
<img src="https://img.shields.io/github/license/liveblocks/liveblocks?style=flat&label=license&color=f80" alt="License" />
|
|
18
|
+
</a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
A set of [React](https://reactjs.org/) hooks and providers to use [Liveblocks](https://liveblocks.io) declaratively.
|
|
10
22
|
|
|
11
23
|
## Installation
|
|
12
24
|
|
package/lib/esm/index.js
CHANGED
|
@@ -60,12 +60,9 @@ function useRoom() {
|
|
|
60
60
|
function useMyPresence() {
|
|
61
61
|
const room = useRoom();
|
|
62
62
|
const presence = room.getPresence();
|
|
63
|
-
const
|
|
63
|
+
const rerender = useRerender();
|
|
64
64
|
React.useEffect(() => {
|
|
65
|
-
|
|
66
|
-
update((x) => x + 1);
|
|
67
|
-
}
|
|
68
|
-
const unsubscribe = room.subscribe("my-presence", onMyPresenceChange);
|
|
65
|
+
const unsubscribe = room.subscribe("my-presence", rerender);
|
|
69
66
|
return () => {
|
|
70
67
|
unsubscribe();
|
|
71
68
|
};
|
|
@@ -81,12 +78,9 @@ function useUpdateMyPresence() {
|
|
|
81
78
|
}
|
|
82
79
|
function useOthers() {
|
|
83
80
|
const room = useRoom();
|
|
84
|
-
const
|
|
81
|
+
const rerender = useRerender();
|
|
85
82
|
React.useEffect(() => {
|
|
86
|
-
|
|
87
|
-
update((x) => x + 1);
|
|
88
|
-
}
|
|
89
|
-
const unsubscribe = room.subscribe("others", onOthersChange);
|
|
83
|
+
const unsubscribe = room.subscribe("others", rerender);
|
|
90
84
|
return () => {
|
|
91
85
|
unsubscribe();
|
|
92
86
|
};
|
package/lib/esm/index.mjs
CHANGED
|
@@ -60,12 +60,9 @@ function useRoom() {
|
|
|
60
60
|
function useMyPresence() {
|
|
61
61
|
const room = useRoom();
|
|
62
62
|
const presence = room.getPresence();
|
|
63
|
-
const
|
|
63
|
+
const rerender = useRerender();
|
|
64
64
|
React.useEffect(() => {
|
|
65
|
-
|
|
66
|
-
update((x) => x + 1);
|
|
67
|
-
}
|
|
68
|
-
const unsubscribe = room.subscribe("my-presence", onMyPresenceChange);
|
|
65
|
+
const unsubscribe = room.subscribe("my-presence", rerender);
|
|
69
66
|
return () => {
|
|
70
67
|
unsubscribe();
|
|
71
68
|
};
|
|
@@ -81,12 +78,9 @@ function useUpdateMyPresence() {
|
|
|
81
78
|
}
|
|
82
79
|
function useOthers() {
|
|
83
80
|
const room = useRoom();
|
|
84
|
-
const
|
|
81
|
+
const rerender = useRerender();
|
|
85
82
|
React.useEffect(() => {
|
|
86
|
-
|
|
87
|
-
update((x) => x + 1);
|
|
88
|
-
}
|
|
89
|
-
const unsubscribe = room.subscribe("others", onOthersChange);
|
|
83
|
+
const unsubscribe = room.subscribe("others", rerender);
|
|
90
84
|
return () => {
|
|
91
85
|
unsubscribe();
|
|
92
86
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Room, Presence, Others, BroadcastOptions, User, LiveObject, LiveMap, LiveList, Client } from '@liveblocks/client';
|
|
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';
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
|
|
4
5
|
declare type LiveblocksProviderProps = {
|
|
@@ -108,7 +109,7 @@ declare function useBroadcastEvent(): (event: any, options?: BroadcastOptions) =
|
|
|
108
109
|
* console.error(er);
|
|
109
110
|
* })
|
|
110
111
|
*/
|
|
111
|
-
declare function useErrorListener(callback: (
|
|
112
|
+
declare function useErrorListener(callback: (err: Error) => void): void;
|
|
112
113
|
/**
|
|
113
114
|
* useEventListener is a react hook that lets you react to event broadcasted by other users in the room.
|
|
114
115
|
*
|
|
@@ -121,7 +122,7 @@ declare function useErrorListener(callback: (er: Error) => void): void;
|
|
|
121
122
|
* }
|
|
122
123
|
* });
|
|
123
124
|
*/
|
|
124
|
-
declare function useEventListener<TEvent>(callback: ({ connectionId, event, }: {
|
|
125
|
+
declare function useEventListener<TEvent extends Json>(callback: ({ connectionId, event, }: {
|
|
125
126
|
connectionId: number;
|
|
126
127
|
event: TEvent;
|
|
127
128
|
}) => void): void;
|
|
@@ -149,7 +150,7 @@ declare function useStorage<TRoot extends Record<string, any>>(): [
|
|
|
149
150
|
* const emptyMap = useMap("mapA");
|
|
150
151
|
* const mapWithItems = useMap("mapB", [["keyA", "valueA"], ["keyB", "valueB"]]);
|
|
151
152
|
*/
|
|
152
|
-
declare function useMap<TKey extends string, TValue>(key: string, entries?: readonly (readonly [TKey, TValue])[] | null | undefined): LiveMap<TKey, TValue> | null;
|
|
153
|
+
declare function useMap<TKey extends string, TValue extends Lson>(key: string, entries?: readonly (readonly [TKey, TValue])[] | null | undefined): LiveMap<TKey, TValue> | null;
|
|
153
154
|
/**
|
|
154
155
|
* Returns the LiveList associated with the provided key. If the LiveList does not exist, a new LiveList will be created.
|
|
155
156
|
* The hook triggers a re-render if the LiveList is updated, however it does not triggers a re-render if a nested CRDT is updated.
|
|
@@ -162,7 +163,7 @@ declare function useMap<TKey extends string, TValue>(key: string, entries?: read
|
|
|
162
163
|
* const emptyList = useList("listA");
|
|
163
164
|
* const listWithItems = useList("listB", ["a", "b", "c"]);
|
|
164
165
|
*/
|
|
165
|
-
declare function useList<TValue>(key: string, items?: TValue[] | undefined): LiveList<TValue> | null;
|
|
166
|
+
declare function useList<TValue extends Lson>(key: string, items?: TValue[] | undefined): LiveList<TValue> | null;
|
|
166
167
|
/**
|
|
167
168
|
* Returns the LiveObject associated with the provided key. If the LiveObject does not exist, it will be created with the initialData parameter.
|
|
168
169
|
* The hook triggers a re-render if the LiveObject is updated, however it does not triggers a re-render if a nested CRDT is updated.
|
|
@@ -177,7 +178,7 @@ declare function useList<TValue>(key: string, items?: TValue[] | undefined): Liv
|
|
|
177
178
|
* website: "https://liveblocks.io"
|
|
178
179
|
* });
|
|
179
180
|
*/
|
|
180
|
-
declare function useObject<TData>(key: string, initialData?: TData): LiveObject<TData> | null;
|
|
181
|
+
declare function useObject<TData extends LsonObject>(key: string, initialData?: TData): LiveObject<TData> | null;
|
|
181
182
|
/**
|
|
182
183
|
* Returns a function that undoes the last operation executed by the current client.
|
|
183
184
|
* It does not impact operations made by other clients.
|
|
@@ -194,15 +195,10 @@ declare function useRedo(): () => void;
|
|
|
194
195
|
* All the modifications are merged in a single history item (undo/redo).
|
|
195
196
|
* All the subscribers are called only after the batch is over.
|
|
196
197
|
*/
|
|
197
|
-
declare function useBatch(): (
|
|
198
|
+
declare function useBatch(): (callback: () => void) => void;
|
|
198
199
|
/**
|
|
199
200
|
* Returns the room.history
|
|
200
201
|
*/
|
|
201
|
-
declare function useHistory():
|
|
202
|
-
undo: () => void;
|
|
203
|
-
redo: () => void;
|
|
204
|
-
pause: () => void;
|
|
205
|
-
resume: () => void;
|
|
206
|
-
};
|
|
202
|
+
declare function useHistory(): History;
|
|
207
203
|
|
|
208
204
|
export { LiveblocksProvider, RoomProvider, useBatch, useBroadcastEvent, useErrorListener, useEventListener, useHistory, useList, useMap, useMyPresence, useObject, useOthers, useRedo, useRoom, useSelf, useStorage, useUndo, useUpdateMyPresence };
|
package/lib/index.js
CHANGED
|
@@ -131,18 +131,9 @@ function useRoom() {
|
|
|
131
131
|
function useMyPresence() {
|
|
132
132
|
var room = useRoom();
|
|
133
133
|
var presence = room.getPresence();
|
|
134
|
-
|
|
135
|
-
var _React$useState = React__namespace.useState(0),
|
|
136
|
-
update = _React$useState[1];
|
|
137
|
-
|
|
134
|
+
var rerender = useRerender();
|
|
138
135
|
React__namespace.useEffect(function () {
|
|
139
|
-
|
|
140
|
-
update(function (x) {
|
|
141
|
-
return x + 1;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
var unsubscribe = room.subscribe("my-presence", onMyPresenceChange);
|
|
136
|
+
var unsubscribe = room.subscribe("my-presence", rerender);
|
|
146
137
|
return function () {
|
|
147
138
|
unsubscribe();
|
|
148
139
|
};
|
|
@@ -160,18 +151,9 @@ function useUpdateMyPresence() {
|
|
|
160
151
|
}
|
|
161
152
|
function useOthers() {
|
|
162
153
|
var room = useRoom();
|
|
163
|
-
|
|
164
|
-
var _React$useState2 = React__namespace.useState(0),
|
|
165
|
-
update = _React$useState2[1];
|
|
166
|
-
|
|
154
|
+
var rerender = useRerender();
|
|
167
155
|
React__namespace.useEffect(function () {
|
|
168
|
-
|
|
169
|
-
update(function (x) {
|
|
170
|
-
return x + 1;
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
var unsubscribe = room.subscribe("others", onOthersChange);
|
|
156
|
+
var unsubscribe = room.subscribe("others", rerender);
|
|
175
157
|
return function () {
|
|
176
158
|
unsubscribe();
|
|
177
159
|
};
|
|
@@ -240,9 +222,9 @@ function useSelf() {
|
|
|
240
222
|
function useStorage() {
|
|
241
223
|
var room = useRoom();
|
|
242
224
|
|
|
243
|
-
var _React$
|
|
244
|
-
root = _React$
|
|
245
|
-
setState = _React$
|
|
225
|
+
var _React$useState = React__namespace.useState(null),
|
|
226
|
+
root = _React$useState[0],
|
|
227
|
+
setState = _React$useState[1];
|
|
246
228
|
|
|
247
229
|
React__namespace.useEffect(function () {
|
|
248
230
|
var didCancel = false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "0.16.0",
|
|
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",
|
|
7
7
|
"files": [
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"license": "Apache-2.0",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@liveblocks/client": "0.
|
|
37
|
-
"react": "^16.14.0 || ^17"
|
|
36
|
+
"@liveblocks/client": "0.16.0",
|
|
37
|
+
"react": "^16.14.0 || ^17 || ^18"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@babel/core": "^7.12.16",
|
|
@@ -49,9 +49,12 @@
|
|
|
49
49
|
"@types/jest": "^26.0.20",
|
|
50
50
|
"@types/react": "^16.14.0",
|
|
51
51
|
"@types/react-dom": "^17.0.14",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.18.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.18.0",
|
|
52
54
|
"babel-core": "^6.26.3",
|
|
53
55
|
"babel-jest": "^26.6.3",
|
|
54
56
|
"babel-runtime": "^6.26.0",
|
|
57
|
+
"eslint": "^8.12.0",
|
|
55
58
|
"jest": "^26.6.3",
|
|
56
59
|
"msw": "^0.27.1",
|
|
57
60
|
"react-error-boundary": "^3.1.1",
|
|
@@ -66,4 +69,4 @@
|
|
|
66
69
|
"url": "https://github.com/liveblocks/liveblocks.git",
|
|
67
70
|
"directory": "packages/liveblocks-react"
|
|
68
71
|
}
|
|
69
|
-
}
|
|
72
|
+
}
|