@liveblocks/react 1.1.0-rc1 → 1.1.0-yjs1
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/dist/index.d.ts +53 -1
- package/dist/index.js +23 -0
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactElement, ReactNode } from 'react';
|
|
2
|
-
import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Others, Json, Room, BroadcastOptions, History, Client } from '@liveblocks/client';
|
|
2
|
+
import { JsonObject, LsonObject, BaseUserMeta, LiveObject, User, Others, Json, Room, Status, BroadcastOptions, LostConnectionEvent, History, Client } from '@liveblocks/client';
|
|
3
3
|
export { Json, JsonObject, shallow } from '@liveblocks/client';
|
|
4
4
|
import { ToImmutable, Resolve, RoomInitializers } from '@liveblocks/core';
|
|
5
5
|
|
|
@@ -88,6 +88,11 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
88
88
|
* tree.
|
|
89
89
|
*/
|
|
90
90
|
useRoom(): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
91
|
+
/**
|
|
92
|
+
* Returns the current connection status for the Room, and triggers
|
|
93
|
+
* a re-render whenever it changes. Can be used to render a status badge.
|
|
94
|
+
*/
|
|
95
|
+
useStatus(): Status;
|
|
91
96
|
/**
|
|
92
97
|
* Returns a function that batches modifications made during the given function.
|
|
93
98
|
* All the modifications are sent to other clients in a single message.
|
|
@@ -104,6 +109,27 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
104
109
|
* broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
|
|
105
110
|
*/
|
|
106
111
|
useBroadcastEvent(): (event: TRoomEvent, options?: BroadcastOptions) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Get informed when reconnecting to the Liveblocks servers is taking
|
|
114
|
+
* longer than usual. This typically is a sign of a client that has lost
|
|
115
|
+
* internet connectivity.
|
|
116
|
+
*
|
|
117
|
+
* This isn't problematic (because the Liveblocks client is still trying to
|
|
118
|
+
* reconnect), but it's typically a good idea to inform users about it if
|
|
119
|
+
* the connection takes too long to recover.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* useLostConnectionListener(event => {
|
|
123
|
+
* if (event === 'lost') {
|
|
124
|
+
* toast.warn('Reconnecting to the Liveblocks servers is taking longer than usual...')
|
|
125
|
+
* } else if (event === 'failed') {
|
|
126
|
+
* toast.warn('Reconnecting to the Liveblocks servers failed.')
|
|
127
|
+
* } else if (event === 'restored') {
|
|
128
|
+
* toast.clear();
|
|
129
|
+
* }
|
|
130
|
+
* })
|
|
131
|
+
*/
|
|
132
|
+
useLostConnectionListener(callback: (event: LostConnectionEvent) => void): void;
|
|
107
133
|
/**
|
|
108
134
|
* useErrorListener is a react hook that lets you react to potential room connection errors.
|
|
109
135
|
*
|
|
@@ -428,6 +454,11 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
428
454
|
* tree.
|
|
429
455
|
*/
|
|
430
456
|
useRoom(): Room<TPresence, TStorage, TUserMeta, TRoomEvent>;
|
|
457
|
+
/**
|
|
458
|
+
* Returns the current connection status for the Room, and triggers
|
|
459
|
+
* a re-render whenever it changes. Can be used to render a status badge.
|
|
460
|
+
*/
|
|
461
|
+
useStatus(): Status;
|
|
431
462
|
/**
|
|
432
463
|
* Returns a function that batches modifications made during the given function.
|
|
433
464
|
* All the modifications are sent to other clients in a single message.
|
|
@@ -444,6 +475,27 @@ declare type RoomContextBundle<TPresence extends JsonObject, TStorage extends Ls
|
|
|
444
475
|
* broadcast({ type: "CUSTOM_EVENT", data: { x: 0, y: 0 } });
|
|
445
476
|
*/
|
|
446
477
|
useBroadcastEvent(): (event: TRoomEvent, options?: BroadcastOptions) => void;
|
|
478
|
+
/**
|
|
479
|
+
* Get informed when reconnecting to the Liveblocks servers is taking
|
|
480
|
+
* longer than usual. This typically is a sign of a client that has lost
|
|
481
|
+
* internet connectivity.
|
|
482
|
+
*
|
|
483
|
+
* This isn't problematic (because the Liveblocks client is still trying to
|
|
484
|
+
* reconnect), but it's typically a good idea to inform users about it if
|
|
485
|
+
* the connection takes too long to recover.
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* useLostConnectionListener(event => {
|
|
489
|
+
* if (event === 'lost') {
|
|
490
|
+
* toast.warn('Reconnecting to the Liveblocks servers is taking longer than usual...')
|
|
491
|
+
* } else if (event === 'failed') {
|
|
492
|
+
* toast.warn('Reconnecting to the Liveblocks servers failed.')
|
|
493
|
+
* } else if (event === 'restored') {
|
|
494
|
+
* toast.clear();
|
|
495
|
+
* }
|
|
496
|
+
* })
|
|
497
|
+
*/
|
|
498
|
+
useLostConnectionListener(callback: (event: LostConnectionEvent) => void): void;
|
|
447
499
|
/**
|
|
448
500
|
* useErrorListener is a react hook that lets you react to potential room connection errors.
|
|
449
501
|
*
|
package/dist/index.js
CHANGED
|
@@ -156,6 +156,12 @@ function createRoomContext(client) {
|
|
|
156
156
|
}
|
|
157
157
|
return room;
|
|
158
158
|
}
|
|
159
|
+
function useStatus() {
|
|
160
|
+
const room = useRoom();
|
|
161
|
+
const subscribe = room.events.status.subscribe;
|
|
162
|
+
const getSnapshot = room.getStatus;
|
|
163
|
+
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
164
|
+
}
|
|
159
165
|
function useMyPresence() {
|
|
160
166
|
const room = useRoom();
|
|
161
167
|
const subscribe = room.events.me.subscribe;
|
|
@@ -240,6 +246,19 @@ function createRoomContext(client) {
|
|
|
240
246
|
[room]
|
|
241
247
|
);
|
|
242
248
|
}
|
|
249
|
+
function useLostConnectionListener(callback) {
|
|
250
|
+
const room = useRoom();
|
|
251
|
+
const savedCallback = React2.useRef(callback);
|
|
252
|
+
React2.useEffect(() => {
|
|
253
|
+
savedCallback.current = callback;
|
|
254
|
+
});
|
|
255
|
+
React2.useEffect(
|
|
256
|
+
() => room.events.lostConnection.subscribe(
|
|
257
|
+
(event) => savedCallback.current(event)
|
|
258
|
+
),
|
|
259
|
+
[room]
|
|
260
|
+
);
|
|
261
|
+
}
|
|
243
262
|
function useErrorListener(callback) {
|
|
244
263
|
const room = useRoom();
|
|
245
264
|
const savedCallback = React2.useRef(callback);
|
|
@@ -488,8 +507,10 @@ function createRoomContext(client) {
|
|
|
488
507
|
RoomContext,
|
|
489
508
|
RoomProvider,
|
|
490
509
|
useRoom,
|
|
510
|
+
useStatus,
|
|
491
511
|
useBatch,
|
|
492
512
|
useBroadcastEvent,
|
|
513
|
+
useLostConnectionListener,
|
|
493
514
|
useErrorListener,
|
|
494
515
|
useEventListener,
|
|
495
516
|
useHistory,
|
|
@@ -515,8 +536,10 @@ function createRoomContext(client) {
|
|
|
515
536
|
RoomContext,
|
|
516
537
|
RoomProvider,
|
|
517
538
|
useRoom,
|
|
539
|
+
useStatus,
|
|
518
540
|
useBatch,
|
|
519
541
|
useBroadcastEvent,
|
|
542
|
+
useLostConnectionListener,
|
|
520
543
|
useErrorListener,
|
|
521
544
|
useEventListener,
|
|
522
545
|
useHistory,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liveblocks/react",
|
|
3
|
-
"version": "1.1.0-
|
|
3
|
+
"version": "1.1.0-yjs1",
|
|
4
4
|
"description": "A set of React hooks and providers to use Liveblocks declaratively. Liveblocks is the all-in-one toolkit to build collaborative products like Figma, Notion, and more.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,15 +13,15 @@
|
|
|
13
13
|
"dev": "tsup --watch",
|
|
14
14
|
"build": "tsup",
|
|
15
15
|
"start": "tsup --watch",
|
|
16
|
-
"format": "eslint --fix src
|
|
17
|
-
"lint": "eslint src
|
|
16
|
+
"format": "(eslint --fix src/ || true) && prettier --write src/",
|
|
17
|
+
"lint": "(eslint src/ || true) && npm run check:exports",
|
|
18
18
|
"check:exports": "tsc scripts/check-factory-exports.ts && node scripts/check-factory-exports.js",
|
|
19
19
|
"test": "jest --silent --verbose --color=always",
|
|
20
20
|
"test:watch": "jest --silent --verbose --color=always --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@liveblocks/client": "1.1.0-
|
|
24
|
-
"@liveblocks/core": "1.1.0-
|
|
23
|
+
"@liveblocks/client": "1.1.0-yjs1",
|
|
24
|
+
"@liveblocks/core": "1.1.0-yjs1",
|
|
25
25
|
"use-sync-external-store": "^1.2.0"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|