@pluv/react 0.0.0 → 0.1.1
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 +23 -0
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +14 -5
- package/src/createRoomBundle.tsx +7 -7
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/react@0.
|
|
2
|
+
> @pluv/react@0.1.1 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
|
[32mCJS[39m [1mdist/index.js [22m[32m9.71 KB[39m
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m7.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 124ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m7.70 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 127ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5343ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.92 KB[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# @pluv/react
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 24016e6: Updated dependencies
|
|
8
|
+
- Updated dependencies [23a7382]
|
|
9
|
+
- Updated dependencies [24016e6]
|
|
10
|
+
- @pluv/client@0.1.1
|
|
11
|
+
- @pluv/types@0.1.1
|
|
12
|
+
|
|
13
|
+
## 0.1.0
|
|
14
|
+
|
|
15
|
+
### Minor Changes
|
|
16
|
+
|
|
17
|
+
- a22f525: Added documentation
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [a22f525]
|
|
22
|
+
- @pluv/client@0.1.0
|
|
23
|
+
- @pluv/types@0.1.0
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Shoubhit Dash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<img src="https://github.com/pluv-io/pluv/blob/master/assets/pluv-icon-192x192.png?raw=true" alt="Pluv.IO" width="180" style="border-radius:16px">
|
|
4
|
+
<br>
|
|
5
|
+
Pluv.IO (preview)
|
|
6
|
+
<br>
|
|
7
|
+
</h1>
|
|
8
|
+
|
|
9
|
+
<h3 align="center">Multi-platform, E2E type-safe realtime packages</h3>
|
|
10
|
+
<h4 align="center">💕 Inspired by <a href="https://trpc.io">trpc</a> 💕 Built with <a href="https://docs.yjs.dev/">yjs</a> 💕</h4>
|
|
11
|
+
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://www.npmjs.com/package/@pluv/react">
|
|
14
|
+
<img src="https://img.shields.io/npm/v/@pluv/react" alt="npm @pluv/react" />
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/pluv-io/pluv/blob/master/LICENSE">
|
|
17
|
+
<img alt="GitHub" src="https://img.shields.io/github/license/pluv-io/pluv" alt="License MIT" />
|
|
18
|
+
</a>
|
|
19
|
+
<img src="https://badgen.net/badge/-/TypeScript?icon=typescript&label&labelColor=blue&color=555555" alt="TypeScript">
|
|
20
|
+
<a href="https://commitizen.github.io/cz-cli/">
|
|
21
|
+
<img src="https://img.shields.io/badge/commitizen-friendly-brightgreen.svg" alt="Commitizen friendly" />
|
|
22
|
+
</a>
|
|
23
|
+
<img src="https://img.shields.io/badge/docs-coming%20soon!-blue" alt="Docs coming soon!" />
|
|
24
|
+
</p>
|
|
25
|
+
|
|
26
|
+
<img src="https://github.com/pluv-io/pluv/blob/master/assets/demo-events.gif?raw=true" alt="Demo" />
|
|
27
|
+
|
|
28
|
+
## `@pluv/react`
|
|
29
|
+
|
|
30
|
+
> [React.js](https://reactjs.org/) bindings for [@pluv/client](https://img.shields.io/npm/v/@pluv/client).
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# npm
|
|
36
|
+
npm install @pluv/react yjs
|
|
37
|
+
|
|
38
|
+
# yarn
|
|
39
|
+
yarn add @pluv/react yjs
|
|
40
|
+
|
|
41
|
+
# pnpm
|
|
42
|
+
pnpm add @pluv/react yjs
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
If you plan on using presence and/or storage, make sure to also install `zod`.
|
|
46
|
+
|
|
47
|
+
## Basic Example
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { createBundle, createClient, y } from "@pluv/react";
|
|
51
|
+
import { z } from "zod";
|
|
52
|
+
// Import the PluvIO instance as a type from your server file
|
|
53
|
+
import { type io } from "./server";
|
|
54
|
+
|
|
55
|
+
// Initialize the @pluv/client client
|
|
56
|
+
const client = createClient<typeof io>({
|
|
57
|
+
authEndpoint: (room) => {
|
|
58
|
+
return `https://localhost:3000/api/authorize?room=${room}`;
|
|
59
|
+
},
|
|
60
|
+
wsEndpoint: (room) => {
|
|
61
|
+
return `ws://localhost:3000/api/room/${room}`;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const {
|
|
66
|
+
// factories
|
|
67
|
+
createRoomBundle,
|
|
68
|
+
|
|
69
|
+
// components
|
|
70
|
+
PluvProvider,
|
|
71
|
+
|
|
72
|
+
// hooks
|
|
73
|
+
usePluvClient,
|
|
74
|
+
} = createBundle(client);
|
|
75
|
+
|
|
76
|
+
export const {
|
|
77
|
+
// components
|
|
78
|
+
PluvRoomProvider,
|
|
79
|
+
|
|
80
|
+
// hooks
|
|
81
|
+
usePluvBroadcast,
|
|
82
|
+
usePluvConnection,
|
|
83
|
+
usePluvEvent,
|
|
84
|
+
usePluvMyPresence,
|
|
85
|
+
usePluvMyself,
|
|
86
|
+
usePluvOther,
|
|
87
|
+
usePluvOthers,
|
|
88
|
+
usePluvRoom,
|
|
89
|
+
usePluvStorage,
|
|
90
|
+
} = createRoomBundle({
|
|
91
|
+
initialStorage: () => ({
|
|
92
|
+
messages: y.array([
|
|
93
|
+
y.unstable__object({
|
|
94
|
+
message: "Hello World!",
|
|
95
|
+
name: "johnathan_doe",
|
|
96
|
+
}),
|
|
97
|
+
]),
|
|
98
|
+
}),
|
|
99
|
+
presence: z.object({
|
|
100
|
+
cursor: z.nullable(
|
|
101
|
+
z.object({
|
|
102
|
+
x: z.number(),
|
|
103
|
+
y: z.number(),
|
|
104
|
+
})
|
|
105
|
+
),
|
|
106
|
+
}),
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
import { FC } from "react";
|
|
110
|
+
|
|
111
|
+
export const MyPage: FC<Record<string, never>> = () => {
|
|
112
|
+
return (
|
|
113
|
+
<PluvProvider>
|
|
114
|
+
<MyRoom />
|
|
115
|
+
</PluvProvider>
|
|
116
|
+
);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const MyRoom: FC<Record<string, never>> = () => {
|
|
120
|
+
const broadcast = usePluvBroadcast();
|
|
121
|
+
|
|
122
|
+
usePluvEvent("RECEIVE_MESSAGE", ({ data }) => {
|
|
123
|
+
// data is typed as { message: string }
|
|
124
|
+
console.log(data.message);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<button
|
|
129
|
+
onClick={() => {
|
|
130
|
+
broadcast({
|
|
131
|
+
type: "SEND_MESSAGE",
|
|
132
|
+
data: {
|
|
133
|
+
// TypeScript will require that message is typed as string
|
|
134
|
+
message: "Hello world!",
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}}
|
|
138
|
+
type="button"
|
|
139
|
+
>
|
|
140
|
+
Send Message
|
|
141
|
+
</button>
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Reference
|
|
147
|
+
|
|
148
|
+
Check us out on [GitHub](https://github.com/pluv-io/pluv) for more information on how to use `@pluv/io`.
|
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, InferEventMessage, InferIOInput,
|
|
4
|
+
import { JsonObject, InputZodLike, IOLike, Id, InferEventMessage, InferIOInput, 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: <TMessage extends InferEventMessage<InferIOInput<TIO
|
|
33
|
+
usePluvBroadcast: <TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>>() => (message: TMessage) => 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
|
@@ -97,11 +97,11 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
97
97
|
};
|
|
98
98
|
}, [rerender, room]);
|
|
99
99
|
(0, import_react3.useEffect)(() => {
|
|
100
|
-
client.enter(
|
|
100
|
+
client.enter(room);
|
|
101
101
|
return () => {
|
|
102
|
-
client.leave(
|
|
102
|
+
client.leave(room);
|
|
103
103
|
};
|
|
104
|
-
}, [
|
|
104
|
+
}, [room]);
|
|
105
105
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, {
|
|
106
106
|
value: room,
|
|
107
107
|
children
|
package/dist/index.mjs
CHANGED
|
@@ -64,11 +64,11 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
64
64
|
};
|
|
65
65
|
}, [rerender, room]);
|
|
66
66
|
useEffect(() => {
|
|
67
|
-
client.enter(
|
|
67
|
+
client.enter(room);
|
|
68
68
|
return () => {
|
|
69
|
-
client.leave(
|
|
69
|
+
client.leave(room);
|
|
70
70
|
};
|
|
71
|
-
}, [
|
|
71
|
+
}, [room]);
|
|
72
72
|
return /* @__PURE__ */ jsx(PluvRoomContext.Provider, {
|
|
73
73
|
value: room,
|
|
74
74
|
children
|
package/package.json
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "@pluv/client React.js bindings",
|
|
5
|
+
"author": "leedavidcs",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/pluv-io/pluv",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pluv-io/pluv.git",
|
|
11
|
+
"directory": "packages/react"
|
|
12
|
+
},
|
|
4
13
|
"main": "./dist/index.js",
|
|
5
14
|
"module": "./dist/index.mjs",
|
|
6
15
|
"types": "./dist/index.d.ts",
|
|
@@ -8,8 +17,8 @@
|
|
|
8
17
|
"access": "public"
|
|
9
18
|
},
|
|
10
19
|
"dependencies": {
|
|
11
|
-
"@pluv/client": "^0.
|
|
12
|
-
"@pluv/types": "^0.
|
|
20
|
+
"@pluv/client": "^0.1.1",
|
|
21
|
+
"@pluv/types": "^0.1.1",
|
|
13
22
|
"@types/use-sync-external-store": "^0.0.3",
|
|
14
23
|
"fast-deep-equal": "^3.1.3",
|
|
15
24
|
"use-sync-external-store": "^1.2.0"
|
|
@@ -19,9 +28,9 @@
|
|
|
19
28
|
"yjs": "^13.0.0"
|
|
20
29
|
},
|
|
21
30
|
"devDependencies": {
|
|
22
|
-
"@pluv/tsconfig": "^0.
|
|
31
|
+
"@pluv/tsconfig": "^0.1.1",
|
|
23
32
|
"@types/react": "18.0.26",
|
|
24
|
-
"eslint-config-pluv": "^0.
|
|
33
|
+
"eslint-config-pluv": "^0.1.1",
|
|
25
34
|
"react": "18.2.0",
|
|
26
35
|
"tsup": "^6.5.0",
|
|
27
36
|
"typescript": "^4.9.4",
|
package/src/createRoomBundle.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
UserInfo,
|
|
6
6
|
WebSocketConnection,
|
|
7
7
|
} from "@pluv/client";
|
|
8
|
-
import {
|
|
8
|
+
import type { PluvRoom } from "@pluv/client";
|
|
9
9
|
import type {
|
|
10
10
|
Id,
|
|
11
11
|
InferEventMessage,
|
|
@@ -69,7 +69,7 @@ export interface CreateRoomBundle<
|
|
|
69
69
|
|
|
70
70
|
// hooks
|
|
71
71
|
usePluvBroadcast: <
|
|
72
|
-
TMessage extends InferEventMessage<InferIOInput<TIO
|
|
72
|
+
TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>
|
|
73
73
|
>() => (message: TMessage) => void;
|
|
74
74
|
usePluvConnection: <T extends unknown = WebSocketConnection>(
|
|
75
75
|
selector: (connection: WebSocketConnection) => T,
|
|
@@ -167,12 +167,12 @@ export const createRoomBundle = <
|
|
|
167
167
|
}, [rerender, room]);
|
|
168
168
|
|
|
169
169
|
useEffect(() => {
|
|
170
|
-
client.enter(
|
|
170
|
+
client.enter(room);
|
|
171
171
|
|
|
172
172
|
return () => {
|
|
173
|
-
client.leave(
|
|
173
|
+
client.leave(room);
|
|
174
174
|
};
|
|
175
|
-
}, [
|
|
175
|
+
}, [room]);
|
|
176
176
|
|
|
177
177
|
return (
|
|
178
178
|
<PluvRoomContext.Provider value={room}>
|
|
@@ -186,7 +186,7 @@ export const createRoomBundle = <
|
|
|
186
186
|
const usePluvRoom = () => useContext(PluvRoomContext);
|
|
187
187
|
|
|
188
188
|
const usePluvBroadcast = <
|
|
189
|
-
TMessage extends InferEventMessage<InferIOInput<TIO
|
|
189
|
+
TMessage extends Id<InferEventMessage<InferIOInput<TIO>>>
|
|
190
190
|
>(): ((message: TMessage) => void) => {
|
|
191
191
|
const room = usePluvRoom();
|
|
192
192
|
|
|
@@ -284,7 +284,7 @@ export const createRoomBundle = <
|
|
|
284
284
|
room.broadcast({
|
|
285
285
|
type: "$UPDATE_PRESENCE",
|
|
286
286
|
data: { presence },
|
|
287
|
-
} as InferEventMessage<InferIOInput<TIO
|
|
287
|
+
} as Id<InferEventMessage<InferIOInput<TIO>>>);
|
|
288
288
|
},
|
|
289
289
|
[room]
|
|
290
290
|
);
|