@pluv/react 0.27.0 → 0.29.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 +8 -8
- package/CHANGELOG.md +94 -0
- package/dist/index.d.mts +15 -21
- package/dist/index.d.ts +15 -21
- package/dist/index.js +27 -40
- package/dist/index.mjs +27 -40
- package/package.json +7 -7
- package/src/createBundle.tsx +531 -16
- package/src/index.ts +1 -8
- package/src/createRoomBundle.tsx +0 -559
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/react@0.
|
|
2
|
+
> @pluv/react@0.29.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,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mCJS[39m ⚡️ Build success in
|
|
13
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m11.
|
|
14
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m13.92 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 71ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m11.47 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 75ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4327ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m5.54 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m5.54 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @pluv/react
|
|
2
2
|
|
|
3
|
+
## 0.29.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 525aeae: **BREAKING**
|
|
8
|
+
|
|
9
|
+
Merge `createBundle` with `createRoomBundle`.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
// Before
|
|
13
|
+
const {
|
|
14
|
+
createRoomBundle,
|
|
15
|
+
|
|
16
|
+
// components
|
|
17
|
+
PluvProvider,
|
|
18
|
+
|
|
19
|
+
// hooks
|
|
20
|
+
useClient,
|
|
21
|
+
} = createBundle(client);
|
|
22
|
+
|
|
23
|
+
export const {
|
|
24
|
+
// components
|
|
25
|
+
MockedRoomProvider,
|
|
26
|
+
PluvRoomProvider,
|
|
27
|
+
|
|
28
|
+
// utils
|
|
29
|
+
event,
|
|
30
|
+
|
|
31
|
+
// hooks
|
|
32
|
+
useBroadcast,
|
|
33
|
+
useCanRedo,
|
|
34
|
+
useCanUndo,
|
|
35
|
+
useConnection,
|
|
36
|
+
useDoc,
|
|
37
|
+
useEvent,
|
|
38
|
+
useMyPresence,
|
|
39
|
+
useMyself,
|
|
40
|
+
useOther,
|
|
41
|
+
useOthers,
|
|
42
|
+
useRedo,
|
|
43
|
+
useRoom,
|
|
44
|
+
useStorage,
|
|
45
|
+
useTransact,
|
|
46
|
+
useUndo,
|
|
47
|
+
} = createRoomBundle({});
|
|
48
|
+
|
|
49
|
+
// After
|
|
50
|
+
const {
|
|
51
|
+
// components
|
|
52
|
+
MockedRoomProvider,
|
|
53
|
+
PluvProvider,
|
|
54
|
+
PluvRoomProvider,
|
|
55
|
+
|
|
56
|
+
// utils
|
|
57
|
+
event,
|
|
58
|
+
|
|
59
|
+
// hooks
|
|
60
|
+
useBroadcast,
|
|
61
|
+
useCanRedo,
|
|
62
|
+
useCanUndo,
|
|
63
|
+
useClient,
|
|
64
|
+
useConnection,
|
|
65
|
+
useDoc,
|
|
66
|
+
useEvent,
|
|
67
|
+
useMyPresence,
|
|
68
|
+
useMyself,
|
|
69
|
+
useOther,
|
|
70
|
+
useOthers,
|
|
71
|
+
useRedo,
|
|
72
|
+
useRoom,
|
|
73
|
+
useStorage,
|
|
74
|
+
useTransact,
|
|
75
|
+
useUndo,
|
|
76
|
+
} = createBundle(client);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- @pluv/client@0.29.0
|
|
82
|
+
- @pluv/crdt@0.29.0
|
|
83
|
+
- @pluv/types@0.29.0
|
|
84
|
+
|
|
85
|
+
## 0.28.0
|
|
86
|
+
|
|
87
|
+
### Minor Changes
|
|
88
|
+
|
|
89
|
+
- 778b43e: Remove the `initialStorage` option from `createRoomBundle`. This has been moved to `createClient`.
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- @pluv/client@0.28.0
|
|
94
|
+
- @pluv/crdt@0.28.0
|
|
95
|
+
- @pluv/types@0.28.0
|
|
96
|
+
|
|
3
97
|
## 0.27.0
|
|
4
98
|
|
|
5
99
|
### Minor Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluvRoomDebug, PluvRouterEventConfig, MergeEvents, PluvClient, WebSocketConnection, UserInfo, AbstractRoom, MockedRoomEvents, PluvRoomAddon, PluvRouter } from '@pluv/client';
|
|
2
2
|
export { ConnectionState, createClient } from '@pluv/client';
|
|
3
|
-
import { CrdtType,
|
|
3
|
+
import { CrdtType, AbstractCrdtDoc, InferCrdtJson } from '@pluv/crdt';
|
|
4
4
|
export { CrdtType, InferCrdtJson } from '@pluv/crdt';
|
|
5
5
|
import { IOLike, JsonObject, Id, InferIOOutput, IOEventMessage, InferIOInput } from '@pluv/types';
|
|
6
6
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
7
|
-
import { FC, Dispatch
|
|
7
|
+
import { ReactNode, FC, Dispatch } from 'react';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
13
|
-
};
|
|
9
|
+
interface PluvProviderProps {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
14
12
|
type BaseRoomProviderProps<TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>> = {
|
|
15
13
|
children?: ReactNode;
|
|
16
14
|
initialStorage?: keyof TStorage extends never ? never : () => TStorage;
|
|
@@ -43,13 +41,15 @@ type EventProxy<TIO extends IOLike> = {
|
|
|
43
41
|
useEvent: (callback: (data: Id<IOEventMessage<TIO, event>>) => void) => void;
|
|
44
42
|
};
|
|
45
43
|
};
|
|
46
|
-
interface
|
|
44
|
+
interface CreateBundle<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> {
|
|
47
45
|
MockedRoomProvider: FC<MockedRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
46
|
+
PluvProvider: FC<PluvProviderProps>;
|
|
48
47
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TMetadata, TPresence, TStorage>>;
|
|
49
48
|
event: EventProxy<MergeEvents<TEvents, TIO>>;
|
|
50
49
|
useBroadcast: () => BroadcastProxy<MergeEvents<TEvents, TIO>>;
|
|
51
50
|
useCanRedo: () => boolean;
|
|
52
51
|
useCanUndo: () => boolean;
|
|
52
|
+
useClient: () => PluvClient<TIO, TPresence, TStorage, TMetadata>;
|
|
53
53
|
useConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
|
|
54
54
|
useDoc: () => AbstractCrdtDoc<TStorage>;
|
|
55
55
|
useEvent: <TType extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(type: TType, callback: (data: Id<IOEventMessage<MergeEvents<TEvents, TIO>, TType>>) => void) => void;
|
|
@@ -63,16 +63,10 @@ interface CreateRoomBundle<TIO extends IOLike, TMetadata extends JsonObject, TPr
|
|
|
63
63
|
useTransact: () => (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
64
64
|
useUndo: () => () => void;
|
|
65
65
|
}
|
|
66
|
-
type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
interface CreateBundle<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}> {
|
|
72
|
-
createRoomBundle: <TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}>(options: CreateRoomBundleOptions<TIO, TMetadata, TPresence, TStorage, TEvents>) => CreateRoomBundle<TIO, TMetadata, TPresence, TStorage, TEvents>;
|
|
73
|
-
PluvProvider: FC<PluvProviderProps>;
|
|
74
|
-
useClient: () => PluvClient<TIO, TPresence, TStorage, TMetadata>;
|
|
75
|
-
}
|
|
76
|
-
declare const createBundle: <TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}>(client: PluvClient<TIO, TPresence, TStorage, TMetadata>) => CreateBundle<TIO, TMetadata, TPresence, TStorage>;
|
|
66
|
+
type CreateBundleOptions<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
67
|
+
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
68
|
+
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
69
|
+
};
|
|
70
|
+
declare const createBundle: <TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}>(client: PluvClient<TIO, TPresence, TStorage, TMetadata>, options?: CreateBundleOptions<TIO, TMetadata, TPresence, TStorage, TEvents>) => CreateBundle<TIO, TMetadata, TPresence, TStorage>;
|
|
77
71
|
|
|
78
|
-
export { type CreateBundle, type
|
|
72
|
+
export { type CreateBundle, type PluvProviderProps, type PluvRoomProviderProps, type SubscriptionHookOptions, createBundle };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PluvRoomDebug, PluvRouterEventConfig, MergeEvents, PluvClient, WebSocketConnection, UserInfo, AbstractRoom, MockedRoomEvents, PluvRoomAddon, PluvRouter } from '@pluv/client';
|
|
2
2
|
export { ConnectionState, createClient } from '@pluv/client';
|
|
3
|
-
import { CrdtType,
|
|
3
|
+
import { CrdtType, AbstractCrdtDoc, InferCrdtJson } from '@pluv/crdt';
|
|
4
4
|
export { CrdtType, InferCrdtJson } from '@pluv/crdt';
|
|
5
5
|
import { IOLike, JsonObject, Id, InferIOOutput, IOEventMessage, InferIOInput } from '@pluv/types';
|
|
6
6
|
export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
|
|
7
|
-
import { FC, Dispatch
|
|
7
|
+
import { ReactNode, FC, Dispatch } from 'react';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
13
|
-
};
|
|
9
|
+
interface PluvProviderProps {
|
|
10
|
+
children?: ReactNode;
|
|
11
|
+
}
|
|
14
12
|
type BaseRoomProviderProps<TPresence extends JsonObject, TStorage extends Record<string, CrdtType<any, any>>> = {
|
|
15
13
|
children?: ReactNode;
|
|
16
14
|
initialStorage?: keyof TStorage extends never ? never : () => TStorage;
|
|
@@ -43,13 +41,15 @@ type EventProxy<TIO extends IOLike> = {
|
|
|
43
41
|
useEvent: (callback: (data: Id<IOEventMessage<TIO, event>>) => void) => void;
|
|
44
42
|
};
|
|
45
43
|
};
|
|
46
|
-
interface
|
|
44
|
+
interface CreateBundle<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> {
|
|
47
45
|
MockedRoomProvider: FC<MockedRoomProviderProps<TIO, TPresence, TStorage>>;
|
|
46
|
+
PluvProvider: FC<PluvProviderProps>;
|
|
48
47
|
PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TMetadata, TPresence, TStorage>>;
|
|
49
48
|
event: EventProxy<MergeEvents<TEvents, TIO>>;
|
|
50
49
|
useBroadcast: () => BroadcastProxy<MergeEvents<TEvents, TIO>>;
|
|
51
50
|
useCanRedo: () => boolean;
|
|
52
51
|
useCanUndo: () => boolean;
|
|
52
|
+
useClient: () => PluvClient<TIO, TPresence, TStorage, TMetadata>;
|
|
53
53
|
useConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
|
|
54
54
|
useDoc: () => AbstractCrdtDoc<TStorage>;
|
|
55
55
|
useEvent: <TType extends keyof InferIOOutput<MergeEvents<TEvents, TIO>>>(type: TType, callback: (data: Id<IOEventMessage<MergeEvents<TEvents, TIO>, TType>>) => void) => void;
|
|
@@ -63,16 +63,10 @@ interface CreateRoomBundle<TIO extends IOLike, TMetadata extends JsonObject, TPr
|
|
|
63
63
|
useTransact: () => (fn: (storage: TStorage) => void, origin?: string) => void;
|
|
64
64
|
useUndo: () => () => void;
|
|
65
65
|
}
|
|
66
|
-
type
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
interface CreateBundle<TIO extends IOLike, TMetadata extends JsonObject, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}> {
|
|
72
|
-
createRoomBundle: <TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}>(options: CreateRoomBundleOptions<TIO, TMetadata, TPresence, TStorage, TEvents>) => CreateRoomBundle<TIO, TMetadata, TPresence, TStorage, TEvents>;
|
|
73
|
-
PluvProvider: FC<PluvProviderProps>;
|
|
74
|
-
useClient: () => PluvClient<TIO, TPresence, TStorage, TMetadata>;
|
|
75
|
-
}
|
|
76
|
-
declare const createBundle: <TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}>(client: PluvClient<TIO, TPresence, TStorage, TMetadata>) => CreateBundle<TIO, TMetadata, TPresence, TStorage>;
|
|
66
|
+
type CreateBundleOptions<TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}> = {
|
|
67
|
+
addons?: readonly PluvRoomAddon<TIO, TMetadata, TPresence, TStorage>[];
|
|
68
|
+
router?: PluvRouter<TIO, TPresence, TStorage, TEvents>;
|
|
69
|
+
};
|
|
70
|
+
declare const createBundle: <TIO extends IOLike, TMetadata extends JsonObject = {}, TPresence extends JsonObject = {}, TStorage extends Record<string, CrdtType<any, any>> = {}, TEvents extends PluvRouterEventConfig<TIO, TPresence, TStorage> = {}>(client: PluvClient<TIO, TPresence, TStorage, TMetadata>, options?: CreateBundleOptions<TIO, TMetadata, TPresence, TStorage, TEvents>) => CreateBundle<TIO, TMetadata, TPresence, TStorage>;
|
|
77
71
|
|
|
78
|
-
export { type CreateBundle, type
|
|
72
|
+
export { type CreateBundle, type PluvProviderProps, type PluvRoomProviderProps, type SubscriptionHookOptions, createBundle };
|
package/dist/index.js
CHANGED
|
@@ -38,11 +38,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
38
38
|
var import_client2 = require("@pluv/client");
|
|
39
39
|
|
|
40
40
|
// src/createBundle.tsx
|
|
41
|
-
var import_react5 = require("react");
|
|
42
|
-
|
|
43
|
-
// src/createRoomBundle.tsx
|
|
44
41
|
var import_client = require("@pluv/client");
|
|
45
|
-
var import_crdt = require("@pluv/crdt");
|
|
46
42
|
var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
|
|
47
43
|
var import_react4 = require("react");
|
|
48
44
|
|
|
@@ -109,20 +105,20 @@ var useSyncExternalStoreWithSelector = (subscribe, getClientSnapshot, getServerS
|
|
|
109
105
|
return typeof window !== "undefined" ? noSsr(result, _getServerSnapshot == null ? void 0 : _getServerSnapshot()) : result;
|
|
110
106
|
};
|
|
111
107
|
|
|
112
|
-
// src/
|
|
108
|
+
// src/createBundle.tsx
|
|
113
109
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
114
|
-
var
|
|
115
|
-
|
|
116
|
-
const _initialStorage = (_a = options.initialStorage) != null ? _a : import_crdt.noop.doc();
|
|
110
|
+
var createBundle = (client, options = {}) => {
|
|
111
|
+
const PluvContext = (0, import_react4.createContext)(null);
|
|
117
112
|
const PluvRoomContext = (0, import_react4.createContext)(null);
|
|
118
113
|
const MockedRoomContext = (0, import_react4.createContext)({ room: null });
|
|
119
114
|
const MockedRoomProvider = (0, import_react4.memo)((props) => {
|
|
120
115
|
const { children, events, initialPresence, initialStorage, room: _room } = props;
|
|
121
116
|
const [room] = (0, import_react4.useState)(() => {
|
|
117
|
+
var _a;
|
|
122
118
|
return new import_client.MockedRoom(_room, {
|
|
123
119
|
events,
|
|
124
120
|
initialPresence,
|
|
125
|
-
initialStorage: typeof initialStorage === "function" ?
|
|
121
|
+
initialStorage: typeof initialStorage === "function" ? (_a = client._defs.initialStorage) == null ? void 0 : _a.getFactory(initialStorage) : client._defs.initialStorage
|
|
126
122
|
});
|
|
127
123
|
});
|
|
128
124
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: room, children }) });
|
|
@@ -133,11 +129,12 @@ var createRoomBundle = (client, options) => {
|
|
|
133
129
|
const rerender = useRerender();
|
|
134
130
|
const { room: mockedRoom } = (0, import_react4.useContext)(MockedRoomContext);
|
|
135
131
|
const [room] = (0, import_react4.useState)(() => {
|
|
132
|
+
var _a;
|
|
136
133
|
return client.createRoom(_room, {
|
|
137
134
|
addons: options.addons,
|
|
138
135
|
debug,
|
|
139
136
|
initialPresence,
|
|
140
|
-
initialStorage: typeof initialStorage === "function" ?
|
|
137
|
+
initialStorage: typeof initialStorage === "function" ? (_a = client._defs.initialStorage) == null ? void 0 : _a.getFactory(initialStorage) : client._defs.initialStorage,
|
|
141
138
|
metadata,
|
|
142
139
|
onAuthorizationFail,
|
|
143
140
|
router: options.router
|
|
@@ -160,6 +157,12 @@ var createRoomBundle = (client, options) => {
|
|
|
160
157
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
|
|
161
158
|
});
|
|
162
159
|
PluvRoomProvider.displayName = "PluvRoomProvider";
|
|
160
|
+
const PluvProvider = (0, import_react4.memo)((props) => {
|
|
161
|
+
const { children } = props;
|
|
162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PluvContext.Provider, { value: client, children });
|
|
163
|
+
});
|
|
164
|
+
PluvProvider.displayName = "PluvProvider";
|
|
165
|
+
const useClient = () => (0, import_react4.useContext)(PluvContext);
|
|
163
166
|
const useRoom = () => (0, import_react4.useContext)(PluvRoomContext);
|
|
164
167
|
const useBroadcast = () => {
|
|
165
168
|
const room = useRoom();
|
|
@@ -194,7 +197,7 @@ var createRoomBundle = (client, options) => {
|
|
|
194
197
|
return canUndo;
|
|
195
198
|
};
|
|
196
199
|
const useConnection = (selector = identity, options2) => {
|
|
197
|
-
var
|
|
200
|
+
var _a;
|
|
198
201
|
const room = useRoom();
|
|
199
202
|
const subscribe = (0, import_react4.useCallback)(
|
|
200
203
|
(onStoreChange) => {
|
|
@@ -209,7 +212,7 @@ var createRoomBundle = (client, options) => {
|
|
|
209
212
|
getSnapshot,
|
|
210
213
|
getSnapshot,
|
|
211
214
|
_selector,
|
|
212
|
-
(
|
|
215
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
213
216
|
);
|
|
214
217
|
};
|
|
215
218
|
const useDoc = () => {
|
|
@@ -237,7 +240,7 @@ var createRoomBundle = (client, options) => {
|
|
|
237
240
|
}
|
|
238
241
|
);
|
|
239
242
|
const useMyPresence = (selector = identity, options2) => {
|
|
240
|
-
var
|
|
243
|
+
var _a;
|
|
241
244
|
const room = useRoom();
|
|
242
245
|
const subscribe = (0, import_react4.useCallback)(
|
|
243
246
|
(onStoreChange) => {
|
|
@@ -252,12 +255,12 @@ var createRoomBundle = (client, options) => {
|
|
|
252
255
|
getSnapshot,
|
|
253
256
|
getSnapshot,
|
|
254
257
|
_selector,
|
|
255
|
-
(
|
|
258
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
256
259
|
);
|
|
257
260
|
return [myPresence, room.updateMyPresence];
|
|
258
261
|
};
|
|
259
262
|
const useMyself = (selector = identity, options2) => {
|
|
260
|
-
var
|
|
263
|
+
var _a;
|
|
261
264
|
const room = useRoom();
|
|
262
265
|
const subscribe = (0, import_react4.useCallback)(
|
|
263
266
|
(onStoreChange) => {
|
|
@@ -277,11 +280,11 @@ var createRoomBundle = (client, options) => {
|
|
|
277
280
|
getSnapshot,
|
|
278
281
|
getSnapshot,
|
|
279
282
|
_selector,
|
|
280
|
-
(
|
|
283
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
281
284
|
);
|
|
282
285
|
};
|
|
283
286
|
const useOther = (connectionId, selector = identity, options2) => {
|
|
284
|
-
var
|
|
287
|
+
var _a;
|
|
285
288
|
const room = useRoom();
|
|
286
289
|
const subscribe = (0, import_react4.useCallback)(
|
|
287
290
|
(onStoreChange) => {
|
|
@@ -301,11 +304,11 @@ var createRoomBundle = (client, options) => {
|
|
|
301
304
|
getSnapshot,
|
|
302
305
|
getSnapshot,
|
|
303
306
|
_selector,
|
|
304
|
-
(
|
|
307
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
305
308
|
);
|
|
306
309
|
};
|
|
307
310
|
const useOthers = (selector = identity, options2) => {
|
|
308
|
-
var
|
|
311
|
+
var _a;
|
|
309
312
|
const room = useRoom();
|
|
310
313
|
const subscribe = (0, import_react4.useCallback)(
|
|
311
314
|
(onStoreChange) => {
|
|
@@ -319,7 +322,7 @@ var createRoomBundle = (client, options) => {
|
|
|
319
322
|
getSnapshot,
|
|
320
323
|
getSnapshot,
|
|
321
324
|
selector,
|
|
322
|
-
(
|
|
325
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : (a, b) => {
|
|
323
326
|
if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
|
|
324
327
|
return shallowArrayEqual(a, b);
|
|
325
328
|
}
|
|
@@ -332,7 +335,7 @@ var createRoomBundle = (client, options) => {
|
|
|
332
335
|
return room.redo;
|
|
333
336
|
};
|
|
334
337
|
const useStorage = (key, selector = identity, options2) => {
|
|
335
|
-
var
|
|
338
|
+
var _a, _b;
|
|
336
339
|
const room = useRoom();
|
|
337
340
|
const rerender = useRerender();
|
|
338
341
|
room.subscribe("storage-loaded", () => {
|
|
@@ -353,7 +356,7 @@ var createRoomBundle = (client, options) => {
|
|
|
353
356
|
getSnapshot,
|
|
354
357
|
getSnapshot,
|
|
355
358
|
_selector,
|
|
356
|
-
(
|
|
359
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : import_fast_deep_equal.default
|
|
357
360
|
);
|
|
358
361
|
const sharedType = (_b = room.getStorage(key)) != null ? _b : null;
|
|
359
362
|
return [data, sharedType];
|
|
@@ -369,6 +372,7 @@ var createRoomBundle = (client, options) => {
|
|
|
369
372
|
return {
|
|
370
373
|
// components
|
|
371
374
|
MockedRoomProvider,
|
|
375
|
+
PluvProvider,
|
|
372
376
|
PluvRoomProvider,
|
|
373
377
|
// proxies
|
|
374
378
|
event,
|
|
@@ -376,6 +380,7 @@ var createRoomBundle = (client, options) => {
|
|
|
376
380
|
useBroadcast,
|
|
377
381
|
useCanRedo,
|
|
378
382
|
useCanUndo,
|
|
383
|
+
useClient,
|
|
379
384
|
useConnection,
|
|
380
385
|
useDoc,
|
|
381
386
|
useEvent,
|
|
@@ -390,24 +395,6 @@ var createRoomBundle = (client, options) => {
|
|
|
390
395
|
useUndo
|
|
391
396
|
};
|
|
392
397
|
};
|
|
393
|
-
|
|
394
|
-
// src/createBundle.tsx
|
|
395
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
396
|
-
var createBundle = (client) => {
|
|
397
|
-
const PluvContext = (0, import_react5.createContext)(null);
|
|
398
|
-
const PluvProvider = (0, import_react5.memo)((props) => {
|
|
399
|
-
const { children } = props;
|
|
400
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PluvContext.Provider, { value: client, children });
|
|
401
|
-
});
|
|
402
|
-
PluvProvider.displayName = "PluvProvider";
|
|
403
|
-
const useClient = () => (0, import_react5.useContext)(PluvContext);
|
|
404
|
-
const createRoomBundle2 = (options) => createRoomBundle(client, options);
|
|
405
|
-
return {
|
|
406
|
-
createRoomBundle: createRoomBundle2,
|
|
407
|
-
PluvProvider,
|
|
408
|
-
useClient
|
|
409
|
-
};
|
|
410
|
-
};
|
|
411
398
|
// Annotate the CommonJS export names for ESM import in node:
|
|
412
399
|
0 && (module.exports = {
|
|
413
400
|
ConnectionState,
|
package/dist/index.mjs
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
import { ConnectionState, createClient } from "@pluv/client";
|
|
3
3
|
|
|
4
4
|
// src/createBundle.tsx
|
|
5
|
-
import { createContext as createContext2, memo as memo2, useContext as useContext2 } from "react";
|
|
6
|
-
|
|
7
|
-
// src/createRoomBundle.tsx
|
|
8
5
|
import { MockedRoom } from "@pluv/client";
|
|
9
|
-
import { noop } from "@pluv/crdt";
|
|
10
6
|
import fastDeepEqual from "fast-deep-equal";
|
|
11
7
|
import { createContext, memo, useCallback as useCallback3, useContext, useEffect as useEffect2, useMemo, useState as useState3 } from "react";
|
|
12
8
|
|
|
@@ -73,20 +69,20 @@ var useSyncExternalStoreWithSelector = (subscribe, getClientSnapshot, getServerS
|
|
|
73
69
|
return typeof window !== "undefined" ? noSsr(result, _getServerSnapshot == null ? void 0 : _getServerSnapshot()) : result;
|
|
74
70
|
};
|
|
75
71
|
|
|
76
|
-
// src/
|
|
72
|
+
// src/createBundle.tsx
|
|
77
73
|
import { jsx } from "react/jsx-runtime";
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
const _initialStorage = (_a = options.initialStorage) != null ? _a : noop.doc();
|
|
74
|
+
var createBundle = (client, options = {}) => {
|
|
75
|
+
const PluvContext = createContext(null);
|
|
81
76
|
const PluvRoomContext = createContext(null);
|
|
82
77
|
const MockedRoomContext = createContext({ room: null });
|
|
83
78
|
const MockedRoomProvider = memo((props) => {
|
|
84
79
|
const { children, events, initialPresence, initialStorage, room: _room } = props;
|
|
85
80
|
const [room] = useState3(() => {
|
|
81
|
+
var _a;
|
|
86
82
|
return new MockedRoom(_room, {
|
|
87
83
|
events,
|
|
88
84
|
initialPresence,
|
|
89
|
-
initialStorage: typeof initialStorage === "function" ?
|
|
85
|
+
initialStorage: typeof initialStorage === "function" ? (_a = client._defs.initialStorage) == null ? void 0 : _a.getFactory(initialStorage) : client._defs.initialStorage
|
|
90
86
|
});
|
|
91
87
|
});
|
|
92
88
|
return /* @__PURE__ */ jsx(MockedRoomContext.Provider, { value: { room }, children: /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: room, children }) });
|
|
@@ -97,11 +93,12 @@ var createRoomBundle = (client, options) => {
|
|
|
97
93
|
const rerender = useRerender();
|
|
98
94
|
const { room: mockedRoom } = useContext(MockedRoomContext);
|
|
99
95
|
const [room] = useState3(() => {
|
|
96
|
+
var _a;
|
|
100
97
|
return client.createRoom(_room, {
|
|
101
98
|
addons: options.addons,
|
|
102
99
|
debug,
|
|
103
100
|
initialPresence,
|
|
104
|
-
initialStorage: typeof initialStorage === "function" ?
|
|
101
|
+
initialStorage: typeof initialStorage === "function" ? (_a = client._defs.initialStorage) == null ? void 0 : _a.getFactory(initialStorage) : client._defs.initialStorage,
|
|
105
102
|
metadata,
|
|
106
103
|
onAuthorizationFail,
|
|
107
104
|
router: options.router
|
|
@@ -124,6 +121,12 @@ var createRoomBundle = (client, options) => {
|
|
|
124
121
|
return /* @__PURE__ */ jsx(PluvRoomContext.Provider, { value: mockedRoom != null ? mockedRoom : room, children });
|
|
125
122
|
});
|
|
126
123
|
PluvRoomProvider.displayName = "PluvRoomProvider";
|
|
124
|
+
const PluvProvider = memo((props) => {
|
|
125
|
+
const { children } = props;
|
|
126
|
+
return /* @__PURE__ */ jsx(PluvContext.Provider, { value: client, children });
|
|
127
|
+
});
|
|
128
|
+
PluvProvider.displayName = "PluvProvider";
|
|
129
|
+
const useClient = () => useContext(PluvContext);
|
|
127
130
|
const useRoom = () => useContext(PluvRoomContext);
|
|
128
131
|
const useBroadcast = () => {
|
|
129
132
|
const room = useRoom();
|
|
@@ -158,7 +161,7 @@ var createRoomBundle = (client, options) => {
|
|
|
158
161
|
return canUndo;
|
|
159
162
|
};
|
|
160
163
|
const useConnection = (selector = identity, options2) => {
|
|
161
|
-
var
|
|
164
|
+
var _a;
|
|
162
165
|
const room = useRoom();
|
|
163
166
|
const subscribe = useCallback3(
|
|
164
167
|
(onStoreChange) => {
|
|
@@ -173,7 +176,7 @@ var createRoomBundle = (client, options) => {
|
|
|
173
176
|
getSnapshot,
|
|
174
177
|
getSnapshot,
|
|
175
178
|
_selector,
|
|
176
|
-
(
|
|
179
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
|
|
177
180
|
);
|
|
178
181
|
};
|
|
179
182
|
const useDoc = () => {
|
|
@@ -201,7 +204,7 @@ var createRoomBundle = (client, options) => {
|
|
|
201
204
|
}
|
|
202
205
|
);
|
|
203
206
|
const useMyPresence = (selector = identity, options2) => {
|
|
204
|
-
var
|
|
207
|
+
var _a;
|
|
205
208
|
const room = useRoom();
|
|
206
209
|
const subscribe = useCallback3(
|
|
207
210
|
(onStoreChange) => {
|
|
@@ -216,12 +219,12 @@ var createRoomBundle = (client, options) => {
|
|
|
216
219
|
getSnapshot,
|
|
217
220
|
getSnapshot,
|
|
218
221
|
_selector,
|
|
219
|
-
(
|
|
222
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
|
|
220
223
|
);
|
|
221
224
|
return [myPresence, room.updateMyPresence];
|
|
222
225
|
};
|
|
223
226
|
const useMyself = (selector = identity, options2) => {
|
|
224
|
-
var
|
|
227
|
+
var _a;
|
|
225
228
|
const room = useRoom();
|
|
226
229
|
const subscribe = useCallback3(
|
|
227
230
|
(onStoreChange) => {
|
|
@@ -241,11 +244,11 @@ var createRoomBundle = (client, options) => {
|
|
|
241
244
|
getSnapshot,
|
|
242
245
|
getSnapshot,
|
|
243
246
|
_selector,
|
|
244
|
-
(
|
|
247
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
|
|
245
248
|
);
|
|
246
249
|
};
|
|
247
250
|
const useOther = (connectionId, selector = identity, options2) => {
|
|
248
|
-
var
|
|
251
|
+
var _a;
|
|
249
252
|
const room = useRoom();
|
|
250
253
|
const subscribe = useCallback3(
|
|
251
254
|
(onStoreChange) => {
|
|
@@ -265,11 +268,11 @@ var createRoomBundle = (client, options) => {
|
|
|
265
268
|
getSnapshot,
|
|
266
269
|
getSnapshot,
|
|
267
270
|
_selector,
|
|
268
|
-
(
|
|
271
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
|
|
269
272
|
);
|
|
270
273
|
};
|
|
271
274
|
const useOthers = (selector = identity, options2) => {
|
|
272
|
-
var
|
|
275
|
+
var _a;
|
|
273
276
|
const room = useRoom();
|
|
274
277
|
const subscribe = useCallback3(
|
|
275
278
|
(onStoreChange) => {
|
|
@@ -283,7 +286,7 @@ var createRoomBundle = (client, options) => {
|
|
|
283
286
|
getSnapshot,
|
|
284
287
|
getSnapshot,
|
|
285
288
|
selector,
|
|
286
|
-
(
|
|
289
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : (a, b) => {
|
|
287
290
|
if (Array.isArray(a) && Array.isArray(b) && a.length === b.length) {
|
|
288
291
|
return shallowArrayEqual(a, b);
|
|
289
292
|
}
|
|
@@ -296,7 +299,7 @@ var createRoomBundle = (client, options) => {
|
|
|
296
299
|
return room.redo;
|
|
297
300
|
};
|
|
298
301
|
const useStorage = (key, selector = identity, options2) => {
|
|
299
|
-
var
|
|
302
|
+
var _a, _b;
|
|
300
303
|
const room = useRoom();
|
|
301
304
|
const rerender = useRerender();
|
|
302
305
|
room.subscribe("storage-loaded", () => {
|
|
@@ -317,7 +320,7 @@ var createRoomBundle = (client, options) => {
|
|
|
317
320
|
getSnapshot,
|
|
318
321
|
getSnapshot,
|
|
319
322
|
_selector,
|
|
320
|
-
(
|
|
323
|
+
(_a = options2 == null ? void 0 : options2.isEqual) != null ? _a : fastDeepEqual
|
|
321
324
|
);
|
|
322
325
|
const sharedType = (_b = room.getStorage(key)) != null ? _b : null;
|
|
323
326
|
return [data, sharedType];
|
|
@@ -333,6 +336,7 @@ var createRoomBundle = (client, options) => {
|
|
|
333
336
|
return {
|
|
334
337
|
// components
|
|
335
338
|
MockedRoomProvider,
|
|
339
|
+
PluvProvider,
|
|
336
340
|
PluvRoomProvider,
|
|
337
341
|
// proxies
|
|
338
342
|
event,
|
|
@@ -340,6 +344,7 @@ var createRoomBundle = (client, options) => {
|
|
|
340
344
|
useBroadcast,
|
|
341
345
|
useCanRedo,
|
|
342
346
|
useCanUndo,
|
|
347
|
+
useClient,
|
|
343
348
|
useConnection,
|
|
344
349
|
useDoc,
|
|
345
350
|
useEvent,
|
|
@@ -354,24 +359,6 @@ var createRoomBundle = (client, options) => {
|
|
|
354
359
|
useUndo
|
|
355
360
|
};
|
|
356
361
|
};
|
|
357
|
-
|
|
358
|
-
// src/createBundle.tsx
|
|
359
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
360
|
-
var createBundle = (client) => {
|
|
361
|
-
const PluvContext = createContext2(null);
|
|
362
|
-
const PluvProvider = memo2((props) => {
|
|
363
|
-
const { children } = props;
|
|
364
|
-
return /* @__PURE__ */ jsx2(PluvContext.Provider, { value: client, children });
|
|
365
|
-
});
|
|
366
|
-
PluvProvider.displayName = "PluvProvider";
|
|
367
|
-
const useClient = () => useContext2(PluvContext);
|
|
368
|
-
const createRoomBundle2 = (options) => createRoomBundle(client, options);
|
|
369
|
-
return {
|
|
370
|
-
createRoomBundle: createRoomBundle2,
|
|
371
|
-
PluvProvider,
|
|
372
|
-
useClient
|
|
373
|
-
};
|
|
374
|
-
};
|
|
375
362
|
export {
|
|
376
363
|
ConnectionState,
|
|
377
364
|
createBundle,
|