@pluv/react 0.1.3 → 0.2.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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +12 -0
- package/README.md +6 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/index.mjs +6 -6
- package/package.json +3 -3
- package/src/createRoomBundle.tsx +17 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/react@0.
|
|
2
|
+
> @pluv/react@0.2.0 build /home/runner/work/pluv/pluv/packages/react
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts --external react
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[32mESM[39m [1mdist/index.mjs [22m[32m7.70 KB[39m
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m9.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 61ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m9.70 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 69ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5341ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.92 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @pluv/react
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 95b5ef8: breaking: update PluvRoom.broadcast api
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [95b5ef8]
|
|
12
|
+
- @pluv/client@0.2.0
|
|
13
|
+
- @pluv/types@0.1.2
|
|
14
|
+
|
|
3
15
|
## 0.1.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
<img src="https://img.shields.io/badge/docs-coming%20soon!-blue" alt="Docs coming soon!" />
|
|
27
27
|
</p>
|
|
28
28
|
|
|
29
|
-
<
|
|
29
|
+
<p align="center">
|
|
30
|
+
<img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
|
|
31
|
+
</p>
|
|
30
32
|
|
|
31
33
|
## `@pluv/react`
|
|
32
34
|
|
|
@@ -130,12 +132,9 @@ export const MyRoom: FC<Record<string, never>> = () => {
|
|
|
130
132
|
return (
|
|
131
133
|
<button
|
|
132
134
|
onClick={() => {
|
|
133
|
-
broadcast({
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// TypeScript will require that message is typed as string
|
|
137
|
-
message: "Hello world!",
|
|
138
|
-
}
|
|
135
|
+
broadcast("SEND_MESSAGE", {
|
|
136
|
+
// TypeScript will require that message is typed as string
|
|
137
|
+
message: "Hello world!",
|
|
139
138
|
});
|
|
140
139
|
}}
|
|
141
140
|
type="button"
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PluvRoomDebug, WebSocketConnection, UserInfo, PluvRoom, InferYjsSharedTypeJson, PluvClient } from '@pluv/client';
|
|
2
2
|
export { AbstractType, ConnectionState, createClient, y } from '@pluv/client';
|
|
3
3
|
import * as _pluv_types from '@pluv/types';
|
|
4
|
-
import { JsonObject, InputZodLike, IOLike,
|
|
4
|
+
import { JsonObject, InputZodLike, IOLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
|
|
5
5
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
6
6
|
import { ReactNode, FC, Dispatch } from 'react';
|
|
7
7
|
import { AbstractType } from 'yjs';
|
|
@@ -30,7 +30,7 @@ interface SubscriptionHookOptions<T extends unknown> {
|
|
|
30
30
|
type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
|
|
31
31
|
interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> {
|
|
32
32
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
33
|
-
usePluvBroadcast: <
|
|
33
|
+
usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => void;
|
|
34
34
|
usePluvConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
|
|
35
35
|
usePluvEvent: <TType extends keyof InferIOOutput<TIO>>(type: TType, callback: (data: Id<IOEventMessage<TIO, TType>>) => void) => void;
|
|
36
36
|
usePluvMyPresence: <T extends unknown = TPresence>(selector?: (myPresence: TPresence) => T, options?: SubscriptionHookOptions<Id<T> | null>) => [
|
package/dist/index.js
CHANGED
|
@@ -112,8 +112,8 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
112
112
|
const usePluvBroadcast = () => {
|
|
113
113
|
const room = usePluvRoom();
|
|
114
114
|
return (0, import_react3.useCallback)(
|
|
115
|
-
(
|
|
116
|
-
room.broadcast(
|
|
115
|
+
(event, data) => {
|
|
116
|
+
room.broadcast(event, data);
|
|
117
117
|
},
|
|
118
118
|
[room]
|
|
119
119
|
);
|
|
@@ -174,10 +174,10 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
174
174
|
(value) => {
|
|
175
175
|
const oldMyPresence = room.getMyPresence();
|
|
176
176
|
const presence = typeof value === "function" ? value(oldMyPresence) : value;
|
|
177
|
-
room.broadcast(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
room.broadcast(
|
|
178
|
+
"$UPDATE_PRESENCE",
|
|
179
|
+
{ presence }
|
|
180
|
+
);
|
|
181
181
|
},
|
|
182
182
|
[room]
|
|
183
183
|
);
|
package/dist/index.mjs
CHANGED
|
@@ -79,8 +79,8 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
79
79
|
const usePluvBroadcast = () => {
|
|
80
80
|
const room = usePluvRoom();
|
|
81
81
|
return useCallback2(
|
|
82
|
-
(
|
|
83
|
-
room.broadcast(
|
|
82
|
+
(event, data) => {
|
|
83
|
+
room.broadcast(event, data);
|
|
84
84
|
},
|
|
85
85
|
[room]
|
|
86
86
|
);
|
|
@@ -141,10 +141,10 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
141
141
|
(value) => {
|
|
142
142
|
const oldMyPresence = room.getMyPresence();
|
|
143
143
|
const presence = typeof value === "function" ? value(oldMyPresence) : value;
|
|
144
|
-
room.broadcast(
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
144
|
+
room.broadcast(
|
|
145
|
+
"$UPDATE_PRESENCE",
|
|
146
|
+
{ presence }
|
|
147
|
+
);
|
|
148
148
|
},
|
|
149
149
|
[room]
|
|
150
150
|
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "@pluv/client React.js bindings",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"@types/use-sync-external-store": "^0.0.3",
|
|
21
21
|
"fast-deep-equal": "^3.1.3",
|
|
22
22
|
"use-sync-external-store": "^1.2.0",
|
|
23
|
-
"@pluv/client": "^0.
|
|
23
|
+
"@pluv/client": "^0.2.0",
|
|
24
24
|
"@pluv/types": "^0.1.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typescript": "^4.9.4",
|
|
35
35
|
"yjs": "^13.5.44",
|
|
36
36
|
"@pluv/tsconfig": "^0.1.2",
|
|
37
|
-
"eslint-config-pluv": "^0.1.
|
|
37
|
+
"eslint-config-pluv": "^0.1.3"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
package/src/createRoomBundle.tsx
CHANGED
|
@@ -8,7 +8,6 @@ import type {
|
|
|
8
8
|
import type { PluvRoom } from "@pluv/client";
|
|
9
9
|
import type {
|
|
10
10
|
Id,
|
|
11
|
-
InferEventMessage,
|
|
12
11
|
InferIOInput,
|
|
13
12
|
InferIOOutput,
|
|
14
13
|
InputZodLike,
|
|
@@ -68,9 +67,10 @@ export interface CreateRoomBundle<
|
|
|
68
67
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
69
68
|
|
|
70
69
|
// hooks
|
|
71
|
-
usePluvBroadcast: <
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(
|
|
71
|
+
event: TEvent,
|
|
72
|
+
data: Id<InferIOInput<TIO>[TEvent]>
|
|
73
|
+
) => void;
|
|
74
74
|
usePluvConnection: <T extends unknown = WebSocketConnection>(
|
|
75
75
|
selector: (connection: WebSocketConnection) => T,
|
|
76
76
|
options?: SubscriptionHookOptions<Id<T>>
|
|
@@ -185,14 +185,18 @@ export const createRoomBundle = <
|
|
|
185
185
|
|
|
186
186
|
const usePluvRoom = () => useContext(PluvRoomContext);
|
|
187
187
|
|
|
188
|
-
const usePluvBroadcast = <
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
const usePluvBroadcast = (): (<TEvent extends keyof InferIOInput<TIO>>(
|
|
189
|
+
event: TEvent,
|
|
190
|
+
data: Id<InferIOInput<TIO>[TEvent]>
|
|
191
|
+
) => void) => {
|
|
191
192
|
const room = usePluvRoom();
|
|
192
193
|
|
|
193
194
|
return useCallback(
|
|
194
|
-
|
|
195
|
-
|
|
195
|
+
<TEvent extends keyof InferIOInput<TIO>>(
|
|
196
|
+
event: TEvent,
|
|
197
|
+
data: Id<InferIOInput<TIO>[TEvent]>
|
|
198
|
+
) => {
|
|
199
|
+
room.broadcast(event, data);
|
|
196
200
|
},
|
|
197
201
|
[room]
|
|
198
202
|
);
|
|
@@ -281,10 +285,10 @@ export const createRoomBundle = <
|
|
|
281
285
|
? value(oldMyPresence)
|
|
282
286
|
: value;
|
|
283
287
|
|
|
284
|
-
room.broadcast(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
room.broadcast(
|
|
289
|
+
"$UPDATE_PRESENCE" as keyof InferIOInput<TIO>,
|
|
290
|
+
{ presence } as any
|
|
291
|
+
);
|
|
288
292
|
},
|
|
289
293
|
[room]
|
|
290
294
|
);
|