@pluv/react 0.2.0 → 0.4.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 +7 -7
- package/CHANGELOG.md +24 -0
- package/dist/index.d.ts +13 -10
- package/dist/index.js +29 -7
- package/dist/index.mjs +25 -3
- package/package.json +3 -3
- package/src/createRoomBundle.tsx +59 -13
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/react@0.
|
|
2
|
+
> @pluv/react@0.4.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
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m10.35 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 126ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m8.27 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 149ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4416ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.37 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @pluv/react
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 043c915: Added MockedDataProvider from createRoomBundle
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 93f8c54: chore(deps): update dependency @types/react to v18.0.27
|
|
12
|
+
- Updated dependencies [595e66f]
|
|
13
|
+
- @pluv/client@0.4.0
|
|
14
|
+
|
|
15
|
+
## 0.3.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- 043c915: Added MockedDataProvider from createRoomBundle
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- 93f8c54: chore(deps): update dependency @types/react to v18.0.27
|
|
24
|
+
- Updated dependencies [595e66f]
|
|
25
|
+
- @pluv/client@0.3.0
|
|
26
|
+
|
|
3
27
|
## 0.2.0
|
|
4
28
|
|
|
5
29
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -1,34 +1,37 @@
|
|
|
1
|
-
import { PluvRoomDebug, WebSocketConnection, UserInfo,
|
|
1
|
+
import { PluvRoomDebug, WebSocketConnection, UserInfo, AbstractRoom, InferYjsSharedTypeJson, MockedRoomEvents, PluvClient } from '@pluv/client';
|
|
2
2
|
export { AbstractType, ConnectionState, createClient, y } from '@pluv/client';
|
|
3
3
|
import * as _pluv_types from '@pluv/types';
|
|
4
4
|
import { JsonObject, InputZodLike, IOLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
|
|
5
5
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
6
|
-
import {
|
|
6
|
+
import { FC, Dispatch, ReactNode } from 'react';
|
|
7
7
|
import { AbstractType } from 'yjs';
|
|
8
8
|
|
|
9
9
|
interface CreateRoomBundleOptions<TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> {
|
|
10
10
|
initialStorage?: () => TStorage;
|
|
11
11
|
presence?: InputZodLike<TPresence>;
|
|
12
12
|
}
|
|
13
|
-
type
|
|
13
|
+
type BaseRoomProviderProps<TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = {
|
|
14
14
|
children?: ReactNode;
|
|
15
|
-
|
|
16
|
-
onAuthorizationFail?: (error: Error) => void;
|
|
15
|
+
initialStorage?: keyof TStorage extends never ? never : () => TStorage;
|
|
17
16
|
room: string;
|
|
18
17
|
} & (keyof TPresence extends never ? {
|
|
19
18
|
initialPresence?: never;
|
|
20
19
|
} : {
|
|
21
20
|
initialPresence: TPresence;
|
|
22
|
-
}) & (keyof TStorage extends never ? {
|
|
23
|
-
initialStorage?: never;
|
|
24
|
-
} : {
|
|
25
|
-
initialStorage?: () => TStorage;
|
|
26
21
|
});
|
|
22
|
+
type MockedRoomProviderProps<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = BaseRoomProviderProps<TPresence, TStorage> & {
|
|
23
|
+
events?: MockedRoomEvents<TIO>;
|
|
24
|
+
};
|
|
25
|
+
type PluvRoomProviderProps<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = BaseRoomProviderProps<TPresence, TStorage> & {
|
|
26
|
+
debug?: boolean | PluvRoomDebug<TIO>;
|
|
27
|
+
onAuthorizationFail?: (error: Error) => void;
|
|
28
|
+
};
|
|
27
29
|
interface SubscriptionHookOptions<T extends unknown> {
|
|
28
30
|
isEqual?: (a: T, b: T) => boolean;
|
|
29
31
|
}
|
|
30
32
|
type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
|
|
31
33
|
interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> {
|
|
34
|
+
MockedRoomProvider: FC<MockedRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
32
35
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
33
36
|
usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => void;
|
|
34
37
|
usePluvConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
|
|
@@ -40,7 +43,7 @@ interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TSt
|
|
|
40
43
|
usePluvMyself: <T extends unknown = UserInfo<TIO, TPresence>>(selector?: (myself: Id<UserInfo<TIO, TPresence>>) => T, options?: SubscriptionHookOptions<Id<T> | null>) => Id<T> | null;
|
|
41
44
|
usePluvOther: <T extends unknown = UserInfo<TIO, TPresence>>(connectionId: string, selector?: (other: UserInfo<TIO, TPresence>) => T, options?: SubscriptionHookOptions<Id<T> | null>) => Id<T> | null;
|
|
42
45
|
usePluvOthers: <T extends unknown = UserInfo<TIO, TPresence>>(selector?: (other: readonly Id<UserInfo<TIO, TPresence>>[]) => T[], options?: SubscriptionHookOptions<readonly Id<T>[]>) => readonly Id<T>[];
|
|
43
|
-
usePluvRoom: () =>
|
|
46
|
+
usePluvRoom: () => AbstractRoom<TIO, TPresence, TStorage>;
|
|
44
47
|
usePluvStorage: <TKey extends keyof TStorage, TData extends unknown = InferYjsSharedTypeJson<TStorage[TKey]>>(key: TKey, selector?: (data: InferYjsSharedTypeJson<TStorage[TKey]>) => TData, options?: SubscriptionHookOptions<TData | null>) => [data: TData | null, sharedType: TStorage[TKey] | null];
|
|
45
48
|
}
|
|
46
49
|
|
package/dist/index.js
CHANGED
|
@@ -26,19 +26,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
26
26
|
// src/index.ts
|
|
27
27
|
var src_exports = {};
|
|
28
28
|
__export(src_exports, {
|
|
29
|
-
ConnectionState: () =>
|
|
29
|
+
ConnectionState: () => import_client2.ConnectionState,
|
|
30
30
|
createBundle: () => createBundle,
|
|
31
|
-
createClient: () =>
|
|
32
|
-
y: () =>
|
|
31
|
+
createClient: () => import_client2.createClient,
|
|
32
|
+
y: () => import_client2.y
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(src_exports);
|
|
35
|
-
var
|
|
35
|
+
var import_client2 = require("@pluv/client");
|
|
36
36
|
|
|
37
37
|
// src/createBundle.tsx
|
|
38
38
|
var import_react4 = require("react");
|
|
39
39
|
var import_react5 = require("react");
|
|
40
40
|
|
|
41
41
|
// src/createRoomBundle.tsx
|
|
42
|
+
var import_client = require("@pluv/client");
|
|
42
43
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
43
44
|
var import_react2 = require("react");
|
|
44
45
|
var import_react3 = require("react");
|
|
@@ -66,9 +67,29 @@ var shallowArrayEqual = (a, b) => {
|
|
|
66
67
|
// src/createRoomBundle.tsx
|
|
67
68
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
68
69
|
var createRoomBundle = (client, options = {}) => {
|
|
69
|
-
const PluvRoomContext = (0, import_react2.createContext)(
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const PluvRoomContext = (0, import_react2.createContext)(null);
|
|
71
|
+
const MockedRoomProvider = (0, import_react3.memo)((props) => {
|
|
72
|
+
const {
|
|
73
|
+
children,
|
|
74
|
+
events,
|
|
75
|
+
initialPresence,
|
|
76
|
+
initialStorage,
|
|
77
|
+
room: _room
|
|
78
|
+
} = props;
|
|
79
|
+
const [room] = (0, import_react2.useState)(() => {
|
|
80
|
+
return new import_client.MockedRoom(_room, {
|
|
81
|
+
events,
|
|
82
|
+
initialPresence,
|
|
83
|
+
initialStorage,
|
|
84
|
+
presence: options.presence
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, {
|
|
88
|
+
value: room,
|
|
89
|
+
children
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
MockedRoomProvider.displayName = "MockedRoomProvider";
|
|
72
93
|
const PluvRoomProvider = (0, import_react3.memo)((props) => {
|
|
73
94
|
const {
|
|
74
95
|
children,
|
|
@@ -278,6 +299,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
278
299
|
return [data, sharedType];
|
|
279
300
|
};
|
|
280
301
|
return {
|
|
302
|
+
MockedRoomProvider,
|
|
281
303
|
PluvRoomProvider,
|
|
282
304
|
usePluvBroadcast,
|
|
283
305
|
usePluvConnection,
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { createContext as createContext2 } from "react";
|
|
|
6
6
|
import { memo as memo2, useContext as useContext2 } from "react";
|
|
7
7
|
|
|
8
8
|
// src/createRoomBundle.tsx
|
|
9
|
+
import { MockedRoom } from "@pluv/client";
|
|
9
10
|
import fastDeepEqual from "fast-deep-equal";
|
|
10
11
|
import { createContext, useState as useState2 } from "react";
|
|
11
12
|
import { memo, useCallback as useCallback2, useContext, useEffect } from "react";
|
|
@@ -33,9 +34,29 @@ var shallowArrayEqual = (a, b) => {
|
|
|
33
34
|
// src/createRoomBundle.tsx
|
|
34
35
|
import { jsx } from "react/jsx-runtime";
|
|
35
36
|
var createRoomBundle = (client, options = {}) => {
|
|
36
|
-
const PluvRoomContext = createContext(
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const PluvRoomContext = createContext(null);
|
|
38
|
+
const MockedRoomProvider = memo((props) => {
|
|
39
|
+
const {
|
|
40
|
+
children,
|
|
41
|
+
events,
|
|
42
|
+
initialPresence,
|
|
43
|
+
initialStorage,
|
|
44
|
+
room: _room
|
|
45
|
+
} = props;
|
|
46
|
+
const [room] = useState2(() => {
|
|
47
|
+
return new MockedRoom(_room, {
|
|
48
|
+
events,
|
|
49
|
+
initialPresence,
|
|
50
|
+
initialStorage,
|
|
51
|
+
presence: options.presence
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return /* @__PURE__ */ jsx(PluvRoomContext.Provider, {
|
|
55
|
+
value: room,
|
|
56
|
+
children
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
MockedRoomProvider.displayName = "MockedRoomProvider";
|
|
39
60
|
const PluvRoomProvider = memo((props) => {
|
|
40
61
|
const {
|
|
41
62
|
children,
|
|
@@ -245,6 +266,7 @@ var createRoomBundle = (client, options = {}) => {
|
|
|
245
266
|
return [data, sharedType];
|
|
246
267
|
};
|
|
247
268
|
return {
|
|
269
|
+
MockedRoomProvider,
|
|
248
270
|
PluvRoomProvider,
|
|
249
271
|
usePluvBroadcast,
|
|
250
272
|
usePluvConnection,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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.4.0",
|
|
24
24
|
"@pluv/types": "^0.1.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"yjs": "^13.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/react": "18.0.
|
|
31
|
+
"@types/react": "18.0.27",
|
|
32
32
|
"react": "18.2.0",
|
|
33
33
|
"tsup": "^6.5.0",
|
|
34
34
|
"typescript": "^4.9.4",
|
package/src/createRoomBundle.tsx
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AbstractRoom,
|
|
2
3
|
InferYjsSharedTypeJson,
|
|
4
|
+
MockedRoomEvents,
|
|
3
5
|
PluvClient,
|
|
6
|
+
PluvRoom,
|
|
4
7
|
PluvRoomDebug,
|
|
5
8
|
UserInfo,
|
|
6
9
|
WebSocketConnection,
|
|
7
10
|
} from "@pluv/client";
|
|
8
|
-
import
|
|
11
|
+
import { MockedRoom } from "@pluv/client";
|
|
9
12
|
import type {
|
|
10
13
|
Id,
|
|
11
14
|
InferIOInput,
|
|
@@ -34,21 +37,33 @@ export interface CreateRoomBundleOptions<
|
|
|
34
37
|
presence?: InputZodLike<TPresence>;
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
TIO extends IOLike,
|
|
40
|
+
type BaseRoomProviderProps<
|
|
39
41
|
TPresence extends JsonObject,
|
|
40
42
|
TStorage extends Record<string, AbstractType<any>>
|
|
41
43
|
> = {
|
|
42
44
|
children?: ReactNode;
|
|
43
|
-
|
|
44
|
-
onAuthorizationFail?: (error: Error) => void;
|
|
45
|
+
initialStorage?: keyof TStorage extends never ? never : () => TStorage;
|
|
45
46
|
room: string;
|
|
46
47
|
} & (keyof TPresence extends never
|
|
47
48
|
? { initialPresence?: never }
|
|
48
|
-
: { initialPresence: TPresence })
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
: { initialPresence: TPresence });
|
|
50
|
+
|
|
51
|
+
export type MockedRoomProviderProps<
|
|
52
|
+
TIO extends IOLike,
|
|
53
|
+
TPresence extends JsonObject,
|
|
54
|
+
TStorage extends Record<string, AbstractType<any>>
|
|
55
|
+
> = BaseRoomProviderProps<TPresence, TStorage> & {
|
|
56
|
+
events?: MockedRoomEvents<TIO>;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type PluvRoomProviderProps<
|
|
60
|
+
TIO extends IOLike,
|
|
61
|
+
TPresence extends JsonObject,
|
|
62
|
+
TStorage extends Record<string, AbstractType<any>>
|
|
63
|
+
> = BaseRoomProviderProps<TPresence, TStorage> & {
|
|
64
|
+
debug?: boolean | PluvRoomDebug<TIO>;
|
|
65
|
+
onAuthorizationFail?: (error: Error) => void;
|
|
66
|
+
};
|
|
52
67
|
|
|
53
68
|
export interface SubscriptionHookOptions<T extends unknown> {
|
|
54
69
|
isEqual?: (a: T, b: T) => boolean;
|
|
@@ -64,6 +79,7 @@ export interface CreateRoomBundle<
|
|
|
64
79
|
TStorage extends Record<string, AbstractType<any>>
|
|
65
80
|
> {
|
|
66
81
|
// components
|
|
82
|
+
MockedRoomProvider: FC<MockedRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
67
83
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
68
84
|
|
|
69
85
|
// hooks
|
|
@@ -99,7 +115,7 @@ export interface CreateRoomBundle<
|
|
|
99
115
|
selector?: (other: readonly Id<UserInfo<TIO, TPresence>>[]) => T[],
|
|
100
116
|
options?: SubscriptionHookOptions<readonly Id<T>[]>
|
|
101
117
|
) => readonly Id<T>[];
|
|
102
|
-
usePluvRoom: () =>
|
|
118
|
+
usePluvRoom: () => AbstractRoom<TIO, TPresence, TStorage>;
|
|
103
119
|
usePluvStorage: <
|
|
104
120
|
TKey extends keyof TStorage,
|
|
105
121
|
TData extends unknown = InferYjsSharedTypeJson<TStorage[TKey]>
|
|
@@ -125,9 +141,38 @@ export const createRoomBundle = <
|
|
|
125
141
|
* @author leedavidcs
|
|
126
142
|
* @date November 11, 2022
|
|
127
143
|
*/
|
|
128
|
-
const PluvRoomContext = createContext<
|
|
129
|
-
|
|
130
|
-
);
|
|
144
|
+
const PluvRoomContext = createContext<
|
|
145
|
+
AbstractRoom<TIO, TPresence, TStorage>
|
|
146
|
+
>(null as any);
|
|
147
|
+
|
|
148
|
+
const MockedRoomProvider = memo<
|
|
149
|
+
MockedRoomProviderProps<TIO, TPresence, TStorage>
|
|
150
|
+
>((props) => {
|
|
151
|
+
const {
|
|
152
|
+
children,
|
|
153
|
+
events,
|
|
154
|
+
initialPresence,
|
|
155
|
+
initialStorage,
|
|
156
|
+
room: _room,
|
|
157
|
+
} = props;
|
|
158
|
+
|
|
159
|
+
const [room] = useState<MockedRoom<TIO, TPresence, TStorage>>(() => {
|
|
160
|
+
return new MockedRoom<TIO, TPresence, TStorage>(_room, {
|
|
161
|
+
events,
|
|
162
|
+
initialPresence,
|
|
163
|
+
initialStorage,
|
|
164
|
+
presence: options.presence,
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<PluvRoomContext.Provider value={room}>
|
|
170
|
+
{children}
|
|
171
|
+
</PluvRoomContext.Provider>
|
|
172
|
+
);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
MockedRoomProvider.displayName = "MockedRoomProvider";
|
|
131
176
|
|
|
132
177
|
const PluvRoomProvider = memo<
|
|
133
178
|
PluvRoomProviderProps<TIO, TPresence, TStorage>
|
|
@@ -435,6 +480,7 @@ export const createRoomBundle = <
|
|
|
435
480
|
|
|
436
481
|
return {
|
|
437
482
|
// components
|
|
483
|
+
MockedRoomProvider,
|
|
438
484
|
PluvRoomProvider,
|
|
439
485
|
|
|
440
486
|
// hooks
|