@pluv/react 0.5.9 → 0.5.11
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 +6 -6
- package/CHANGELOG.md +20 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +27 -30
- package/dist/index.mjs +9 -5
- package/package.json +5 -5
- package/src/createRoomBundle.tsx +14 -9
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/react@0.5.
|
|
2
|
+
> @pluv/react@0.5.11 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
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m8.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m11.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m8.60 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 98ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m11.07 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 91ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 5670ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.37 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @pluv/react
|
|
2
2
|
|
|
3
|
+
## 0.5.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2c9c5c3: changed my-presence to be non-nullable
|
|
8
|
+
- Updated dependencies [2c9c5c3]
|
|
9
|
+
- @pluv/client@0.8.1
|
|
10
|
+
|
|
11
|
+
## 0.5.10
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 5bbfb98: fix not properly handling unauthorized checks
|
|
16
|
+
- b85a232: bumped dependencies
|
|
17
|
+
- Updated dependencies [5bbfb98]
|
|
18
|
+
- Updated dependencies [b85a232]
|
|
19
|
+
- Updated dependencies [fde89cf]
|
|
20
|
+
- @pluv/client@0.8.0
|
|
21
|
+
- @pluv/types@0.2.0
|
|
22
|
+
|
|
3
23
|
## 0.5.9
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TSt
|
|
|
37
37
|
usePluvConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
|
|
38
38
|
usePluvEvent: <TType extends keyof InferIOOutput<TIO>>(type: TType, callback: (data: Id<IOEventMessage<TIO, TType>>) => void) => void;
|
|
39
39
|
usePluvMyPresence: <T extends unknown = TPresence>(selector?: (myPresence: TPresence) => T, options?: SubscriptionHookOptions<Id<T> | null>) => [
|
|
40
|
-
myPresence: Id<T
|
|
40
|
+
myPresence: Id<T>,
|
|
41
41
|
updateMyPresence: Dispatch<UpdateMyPresenceAction<TPresence>>
|
|
42
42
|
];
|
|
43
43
|
usePluvMyself: <T extends unknown = UserInfo<TIO, TPresence>>(selector?: (myself: Id<UserInfo<TIO, TPresence>>) => T, options?: SubscriptionHookOptions<Id<T> | null>) => Id<T> | null;
|
package/dist/index.js
CHANGED
|
@@ -39,14 +39,13 @@ module.exports = __toCommonJS(src_exports);
|
|
|
39
39
|
var import_client2 = require("@pluv/client");
|
|
40
40
|
|
|
41
41
|
// src/createBundle.tsx
|
|
42
|
+
var import_react3 = require("react");
|
|
42
43
|
var import_react4 = require("react");
|
|
43
|
-
var import_react5 = require("react");
|
|
44
44
|
|
|
45
45
|
// src/createRoomBundle.tsx
|
|
46
46
|
var import_client = require("@pluv/client");
|
|
47
47
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
48
48
|
var import_react2 = require("react");
|
|
49
|
-
var import_react3 = require("react");
|
|
50
49
|
|
|
51
50
|
// src/internal/hooks/useRerender.ts
|
|
52
51
|
var import_react = require("react");
|
|
@@ -73,7 +72,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
|
|
|
73
72
|
var createRoomBundle = (client, options = {}) => {
|
|
74
73
|
const PluvRoomContext = (0, import_react2.createContext)(null);
|
|
75
74
|
const MockedRoomContext = (0, import_react2.createContext)({ room: null });
|
|
76
|
-
const MockedRoomProvider = (0,
|
|
75
|
+
const MockedRoomProvider = (0, import_react2.memo)((props) => {
|
|
77
76
|
const {
|
|
78
77
|
children,
|
|
79
78
|
events,
|
|
@@ -92,7 +91,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
92
91
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: room, children }) });
|
|
93
92
|
});
|
|
94
93
|
MockedRoomProvider.displayName = "MockedRoomProvider";
|
|
95
|
-
const PluvRoomProvider = (0,
|
|
94
|
+
const PluvRoomProvider = (0, import_react2.memo)((props) => {
|
|
96
95
|
const {
|
|
97
96
|
children,
|
|
98
97
|
debug,
|
|
@@ -102,7 +101,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
102
101
|
room: _room
|
|
103
102
|
} = props;
|
|
104
103
|
const rerender = useRerender();
|
|
105
|
-
const { room: mockedRoom } = (0,
|
|
104
|
+
const { room: mockedRoom } = (0, import_react2.useContext)(MockedRoomContext);
|
|
106
105
|
const [room] = (0, import_react2.useState)(() => {
|
|
107
106
|
return client.createRoom(_room, {
|
|
108
107
|
debug,
|
|
@@ -112,7 +111,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
112
111
|
onAuthorizationFail
|
|
113
112
|
});
|
|
114
113
|
});
|
|
115
|
-
(0,
|
|
114
|
+
(0, import_react2.useEffect)(() => {
|
|
116
115
|
const unsubscribe = room.subscribe("connection", () => {
|
|
117
116
|
rerender();
|
|
118
117
|
});
|
|
@@ -120,7 +119,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
120
119
|
unsubscribe();
|
|
121
120
|
};
|
|
122
121
|
}, [rerender, room]);
|
|
123
|
-
(0,
|
|
122
|
+
(0, import_react2.useEffect)(() => {
|
|
124
123
|
client.enter(room);
|
|
125
124
|
return () => {
|
|
126
125
|
client.leave(room);
|
|
@@ -129,10 +128,10 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
129
128
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
|
|
130
129
|
});
|
|
131
130
|
PluvRoomProvider.displayName = "PluvRoomProvider";
|
|
132
|
-
const usePluvRoom = () => (0,
|
|
131
|
+
const usePluvRoom = () => (0, import_react2.useContext)(PluvRoomContext);
|
|
133
132
|
const usePluvBroadcast = () => {
|
|
134
133
|
const room = usePluvRoom();
|
|
135
|
-
return (0,
|
|
134
|
+
return (0, import_react2.useCallback)(
|
|
136
135
|
(event, data) => {
|
|
137
136
|
room.broadcast(event, data);
|
|
138
137
|
},
|
|
@@ -142,14 +141,14 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
142
141
|
const usePluvConnection = (selector = identity, options2) => {
|
|
143
142
|
var _a;
|
|
144
143
|
const room = usePluvRoom();
|
|
145
|
-
const subscribe = (0,
|
|
144
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
146
145
|
(onStoreChange) => {
|
|
147
146
|
return room.subscribe("connection", onStoreChange);
|
|
148
147
|
},
|
|
149
148
|
[room]
|
|
150
149
|
);
|
|
151
150
|
const getSnapshot = room.getConnection;
|
|
152
|
-
const _selector = (0,
|
|
151
|
+
const _selector = (0, import_react2.useCallback)(
|
|
153
152
|
(snapshot) => selector(snapshot),
|
|
154
153
|
[selector]
|
|
155
154
|
);
|
|
@@ -163,7 +162,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
163
162
|
};
|
|
164
163
|
const usePluvEvent = (type, callback) => {
|
|
165
164
|
const room = usePluvRoom();
|
|
166
|
-
(0,
|
|
165
|
+
(0, import_react2.useEffect)(() => {
|
|
167
166
|
const unsubscribe = room.event(type, callback);
|
|
168
167
|
return () => {
|
|
169
168
|
unsubscribe();
|
|
@@ -173,17 +172,15 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
173
172
|
const usePluvMyPresence = (selector = identity, options2) => {
|
|
174
173
|
var _a;
|
|
175
174
|
const room = usePluvRoom();
|
|
176
|
-
const subscribe = (0,
|
|
175
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
177
176
|
(onStoreChange) => {
|
|
178
177
|
return room.subscribe("my-presence", onStoreChange);
|
|
179
178
|
},
|
|
180
179
|
[room]
|
|
181
180
|
);
|
|
182
181
|
const getSnapshot = room.getMyPresence;
|
|
183
|
-
const _selector = (0,
|
|
184
|
-
(snapshot) =>
|
|
185
|
-
return !snapshot ? null : selector(snapshot);
|
|
186
|
-
},
|
|
182
|
+
const _selector = (0, import_react2.useCallback)(
|
|
183
|
+
(snapshot) => selector(snapshot),
|
|
187
184
|
[selector]
|
|
188
185
|
);
|
|
189
186
|
const myPresence = (0, import_with_selector.useSyncExternalStoreWithSelector)(
|
|
@@ -193,7 +190,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
193
190
|
_selector,
|
|
194
191
|
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
195
192
|
);
|
|
196
|
-
const updateMyPresence = (0,
|
|
193
|
+
const updateMyPresence = (0, import_react2.useCallback)(
|
|
197
194
|
(value) => {
|
|
198
195
|
const presence = typeof value === "function" ? value(room.getMyPresence()) : value;
|
|
199
196
|
room.updateMyPresence(presence);
|
|
@@ -205,14 +202,14 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
205
202
|
const usePluvMyself = (selector = identity, options2) => {
|
|
206
203
|
var _a;
|
|
207
204
|
const room = usePluvRoom();
|
|
208
|
-
const subscribe = (0,
|
|
205
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
209
206
|
(onStoreChange) => {
|
|
210
207
|
return room.subscribe("myself", onStoreChange);
|
|
211
208
|
},
|
|
212
209
|
[room]
|
|
213
210
|
);
|
|
214
211
|
const getSnapshot = room.getMyself;
|
|
215
|
-
const _selector = (0,
|
|
212
|
+
const _selector = (0, import_react2.useCallback)(
|
|
216
213
|
(snapshot) => {
|
|
217
214
|
return !snapshot ? null : selector(snapshot);
|
|
218
215
|
},
|
|
@@ -229,17 +226,17 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
229
226
|
const usePluvOther = (connectionId, selector = identity, options2) => {
|
|
230
227
|
var _a;
|
|
231
228
|
const room = usePluvRoom();
|
|
232
|
-
const subscribe = (0,
|
|
229
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
233
230
|
(onStoreChange) => {
|
|
234
231
|
return room.other(connectionId, onStoreChange);
|
|
235
232
|
},
|
|
236
233
|
[room, connectionId]
|
|
237
234
|
);
|
|
238
|
-
const getSnapshot = (0,
|
|
235
|
+
const getSnapshot = (0, import_react2.useCallback)(
|
|
239
236
|
() => room.getOther(connectionId),
|
|
240
237
|
[room, connectionId]
|
|
241
238
|
);
|
|
242
|
-
const _selector = (0,
|
|
239
|
+
const _selector = (0, import_react2.useCallback)(
|
|
243
240
|
(snapshot) => {
|
|
244
241
|
return !snapshot ? null : selector(snapshot);
|
|
245
242
|
},
|
|
@@ -256,7 +253,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
256
253
|
const usePluvOthers = (selector = identity, options2) => {
|
|
257
254
|
var _a;
|
|
258
255
|
const room = usePluvRoom();
|
|
259
|
-
const subscribe = (0,
|
|
256
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
260
257
|
(onStoreChange) => {
|
|
261
258
|
return room.subscribe("others", onStoreChange);
|
|
262
259
|
},
|
|
@@ -274,15 +271,15 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
274
271
|
const usePluvStorage = (key, selector = identity, options2) => {
|
|
275
272
|
var _a;
|
|
276
273
|
const room = usePluvRoom();
|
|
277
|
-
const subscribe = (0,
|
|
274
|
+
const subscribe = (0, import_react2.useCallback)(
|
|
278
275
|
(onStoreChange) => room.storage(key, onStoreChange),
|
|
279
276
|
[key, room]
|
|
280
277
|
);
|
|
281
|
-
const getSnapshot = (0,
|
|
278
|
+
const getSnapshot = (0, import_react2.useCallback)(() => {
|
|
282
279
|
var _a2, _b;
|
|
283
280
|
return (_b = (_a2 = room.getStorage(key)) == null ? void 0 : _a2.toJSON()) != null ? _b : null;
|
|
284
281
|
}, [key, room]);
|
|
285
|
-
const _selector = (0,
|
|
282
|
+
const _selector = (0, import_react2.useCallback)(
|
|
286
283
|
(snapshot) => {
|
|
287
284
|
return !snapshot ? null : selector(snapshot);
|
|
288
285
|
},
|
|
@@ -318,13 +315,13 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
318
315
|
// src/createBundle.tsx
|
|
319
316
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
320
317
|
var createBundle = (client) => {
|
|
321
|
-
const PluvContext = (0,
|
|
322
|
-
const PluvProvider = (0,
|
|
318
|
+
const PluvContext = (0, import_react3.createContext)(null);
|
|
319
|
+
const PluvProvider = (0, import_react4.memo)((props) => {
|
|
323
320
|
const { children } = props;
|
|
324
321
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PluvContext.Provider, { value: client, children });
|
|
325
322
|
});
|
|
326
323
|
PluvProvider.displayName = "PluvProvider";
|
|
327
|
-
const usePluvClient = () => (0,
|
|
324
|
+
const usePluvClient = () => (0, import_react4.useContext)(PluvContext);
|
|
328
325
|
const createRoomBundle2 = (options = {}) => createRoomBundle(client, options);
|
|
329
326
|
return {
|
|
330
327
|
createRoomBundle: createRoomBundle2,
|
package/dist/index.mjs
CHANGED
|
@@ -8,8 +8,14 @@ import { memo as memo2, useContext as useContext2 } from "react";
|
|
|
8
8
|
// src/createRoomBundle.tsx
|
|
9
9
|
import { MockedRoom } from "@pluv/client";
|
|
10
10
|
import fastDeepEqual from "fast-deep-equal";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import {
|
|
12
|
+
createContext,
|
|
13
|
+
memo,
|
|
14
|
+
useCallback as useCallback2,
|
|
15
|
+
useContext,
|
|
16
|
+
useEffect,
|
|
17
|
+
useState as useState2
|
|
18
|
+
} from "react";
|
|
13
19
|
|
|
14
20
|
// src/internal/hooks/useRerender.ts
|
|
15
21
|
import { useCallback, useState } from "react";
|
|
@@ -144,9 +150,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
144
150
|
);
|
|
145
151
|
const getSnapshot = room.getMyPresence;
|
|
146
152
|
const _selector = useCallback2(
|
|
147
|
-
(snapshot) =>
|
|
148
|
-
return !snapshot ? null : selector(snapshot);
|
|
149
|
-
},
|
|
153
|
+
(snapshot) => selector(snapshot),
|
|
150
154
|
[selector]
|
|
151
155
|
);
|
|
152
156
|
const myPresence = useSyncExternalStoreWithSelector(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
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.8.1",
|
|
24
24
|
"@pluv/types": "^0.2.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
"yjs": "^13.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/react": "18.2.
|
|
31
|
+
"@types/react": "18.2.6",
|
|
32
32
|
"react": "18.2.0",
|
|
33
33
|
"tsup": "^6.7.0",
|
|
34
34
|
"typescript": "^5.0.4",
|
|
35
|
-
"yjs": "^13.6.
|
|
35
|
+
"yjs": "^13.6.1",
|
|
36
36
|
"@pluv/tsconfig": "^0.1.6",
|
|
37
|
-
"eslint-config-pluv": "^0.1.
|
|
37
|
+
"eslint-config-pluv": "^0.1.12"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup src/index.ts --format esm,cjs --dts --external react",
|
package/src/createRoomBundle.tsx
CHANGED
|
@@ -10,17 +10,24 @@ import type {
|
|
|
10
10
|
} from "@pluv/client";
|
|
11
11
|
import { MockedRoom } from "@pluv/client";
|
|
12
12
|
import type {
|
|
13
|
+
IOEventMessage,
|
|
14
|
+
IOLike,
|
|
13
15
|
Id,
|
|
14
16
|
InferIOInput,
|
|
15
17
|
InferIOOutput,
|
|
16
18
|
InputZodLike,
|
|
17
|
-
IOEventMessage,
|
|
18
|
-
IOLike,
|
|
19
19
|
JsonObject,
|
|
20
20
|
} from "@pluv/types";
|
|
21
21
|
import fastDeepEqual from "fast-deep-equal";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
22
|
+
import type { Dispatch, FC, ReactNode } from "react";
|
|
23
|
+
import {
|
|
24
|
+
createContext,
|
|
25
|
+
memo,
|
|
26
|
+
useCallback,
|
|
27
|
+
useContext,
|
|
28
|
+
useEffect,
|
|
29
|
+
useState,
|
|
30
|
+
} from "react";
|
|
24
31
|
import type { AbstractType } from "yjs";
|
|
25
32
|
import {
|
|
26
33
|
identity,
|
|
@@ -99,7 +106,7 @@ export interface CreateRoomBundle<
|
|
|
99
106
|
selector?: (myPresence: TPresence) => T,
|
|
100
107
|
options?: SubscriptionHookOptions<Id<T> | null>
|
|
101
108
|
) => [
|
|
102
|
-
myPresence: Id<T
|
|
109
|
+
myPresence: Id<T>,
|
|
103
110
|
updateMyPresence: Dispatch<UpdateMyPresenceAction<TPresence>>
|
|
104
111
|
];
|
|
105
112
|
usePluvMyself: <T extends unknown = UserInfo<TIO, TPresence>>(
|
|
@@ -304,7 +311,7 @@ export const createRoomBundle = <
|
|
|
304
311
|
const usePluvMyPresence = <T extends unknown = TPresence>(
|
|
305
312
|
selector = identity as (myPresence: TPresence) => T,
|
|
306
313
|
options?: SubscriptionHookOptions<Id<T> | null>
|
|
307
|
-
): [Id<T
|
|
314
|
+
): [Id<T>, Dispatch<UpdateMyPresenceAction<TPresence>>] => {
|
|
308
315
|
const room = usePluvRoom();
|
|
309
316
|
|
|
310
317
|
const subscribe = useCallback(
|
|
@@ -317,9 +324,7 @@ export const createRoomBundle = <
|
|
|
317
324
|
const getSnapshot = room.getMyPresence;
|
|
318
325
|
|
|
319
326
|
const _selector = useCallback(
|
|
320
|
-
(snapshot: TPresence
|
|
321
|
-
return !snapshot ? null : (selector(snapshot) as Id<T>);
|
|
322
|
-
},
|
|
327
|
+
(snapshot: TPresence) => selector(snapshot) as Id<T>,
|
|
323
328
|
[selector]
|
|
324
329
|
);
|
|
325
330
|
|