@pluv/react 0.5.11 → 0.6.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.
@@ -1,17 +1,18 @@
1
1
 
2
- > @pluv/react@0.5.11 build /home/runner/work/pluv/pluv/packages/react
2
+ > @pluv/react@0.6.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
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
- CLI tsup v6.7.0
7
+ CLI tsup v7.1.0
8
8
  CLI Target: es6
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.mjs 8.60 KB
12
- ESM ⚡️ Build success in 98ms
13
- CJS dist/index.js 11.07 KB
14
- CJS ⚡️ Build success in 91ms
11
+ ESM dist/index.mjs 8.63 KB
12
+ ESM ⚡️ Build success in 136ms
13
+ CJS dist/index.js 11.10 KB
14
+ CJS ⚡️ Build success in 136ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 5670ms
17
- DTS dist/index.d.ts 4.37 KB
16
+ DTS ⚡️ Build success in 8645ms
17
+ DTS dist/index.d.mts 4.47 KB
18
+ DTS dist/index.d.ts 4.47 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,66 @@
1
1
  # @pluv/react
2
2
 
3
+ ## 0.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 8fba48b: fix including incorrect dependency
8
+ - 8997c65: bumped dependencies
9
+ - Updated dependencies [8fba48b]
10
+ - Updated dependencies [8997c65]
11
+ - @pluv/client@0.9.1
12
+ - @pluv/types@0.2.2
13
+
14
+ ## 0.6.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 829d31b: Added support for defining persistant frontend storage for rooms via a new `addons` option on rooms.
19
+
20
+ This also introduces the first new addon `@pluv/addon-indexeddb`, which is more-or-less the equivalent to `y-indexeddb` which you can install like so:
21
+
22
+ ```
23
+ npm install @pluv/addon-indexeddb
24
+ ```
25
+
26
+ To use this new addon, simply pass it to options when creating a room:
27
+
28
+ ```ts
29
+ import { addonIndexedDB } from "@pluv/addon-indexeddb";
30
+ import { createClient } from "@pluv/client";
31
+
32
+ const client = createClient({
33
+ // ...
34
+ });
35
+
36
+ const room = client.createRoom("my-new-room", {
37
+ addons: [
38
+ // Define your addons in an array like so
39
+ addonIndexedDB(),
40
+ ],
41
+ });
42
+ ```
43
+
44
+ Or when using `@pluv/react`:
45
+
46
+ ```ts
47
+ const PluvRoom = createRoomBundle({
48
+ // ...
49
+ addons: [
50
+ // Define your addons in an array like so
51
+ addonIndexedDB(),
52
+ ],
53
+ });
54
+ ```
55
+
56
+ ### Patch Changes
57
+
58
+ - 8d11672: bumped dependencies to latest
59
+ - Updated dependencies [8d11672]
60
+ - Updated dependencies [829d31b]
61
+ - @pluv/client@0.9.0
62
+ - @pluv/types@0.2.1
63
+
3
64
  ## 0.5.11
4
65
 
5
66
  ### Patch Changes
@@ -0,0 +1,61 @@
1
+ import { PluvRoomAddon, PluvRoomDebug, WebSocketConnection, UserInfo, AbstractRoom, InferYjsSharedTypeJson, MockedRoomEvents, PluvClient } from '@pluv/client';
2
+ export { AbstractType, ConnectionState, createClient, y } from '@pluv/client';
3
+ import * as _pluv_types from '@pluv/types';
4
+ import { IOLike, JsonObject, InputZodLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
5
+ export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
6
+ import { FC, Dispatch, ReactNode } from 'react';
7
+ import { AbstractType } from 'yjs';
8
+
9
+ interface CreateRoomBundleOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> {
10
+ addons?: readonly PluvRoomAddon<TIO, TPresence, TStorage>[];
11
+ initialStorage?: () => TStorage;
12
+ presence?: InputZodLike<TPresence>;
13
+ }
14
+ type BaseRoomProviderProps<TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = {
15
+ children?: ReactNode;
16
+ initialStorage?: keyof TStorage extends never ? never : () => TStorage;
17
+ room: string;
18
+ } & (keyof TPresence extends never ? {
19
+ initialPresence?: never;
20
+ } : {
21
+ initialPresence: TPresence;
22
+ });
23
+ type MockedRoomProviderProps<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = BaseRoomProviderProps<TPresence, TStorage> & {
24
+ events?: MockedRoomEvents<TIO>;
25
+ };
26
+ type PluvRoomProviderProps<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> = BaseRoomProviderProps<TPresence, TStorage> & {
27
+ debug?: boolean | PluvRoomDebug<TIO>;
28
+ onAuthorizationFail?: (error: Error) => void;
29
+ };
30
+ interface SubscriptionHookOptions<T extends unknown> {
31
+ isEqual?: (a: T, b: T) => boolean;
32
+ }
33
+ type UpdateMyPresenceAction<TPresence extends JsonObject> = Partial<TPresence> | ((oldPresence: TPresence | null) => Partial<TPresence>);
34
+ interface CreateRoomBundle<TIO extends IOLike, TPresence extends JsonObject, TStorage extends Record<string, AbstractType<any>>> {
35
+ MockedRoomProvider: FC<MockedRoomProviderProps<TIO, TPresence, TStorage>>;
36
+ PluvRoomProvider: FC<PluvRoomProviderProps<TIO, TPresence, TStorage>>;
37
+ usePluvBroadcast: () => <TEvent extends keyof InferIOInput<TIO>>(event: TEvent, data: Id<InferIOInput<TIO>[TEvent]>) => void;
38
+ usePluvConnection: <T extends unknown = WebSocketConnection>(selector: (connection: WebSocketConnection) => T, options?: SubscriptionHookOptions<Id<T>>) => Id<T>;
39
+ usePluvEvent: <TType extends keyof InferIOOutput<TIO>>(type: TType, callback: (data: Id<IOEventMessage<TIO, TType>>) => void) => void;
40
+ usePluvMyPresence: <T extends unknown = TPresence>(selector?: (myPresence: TPresence) => T, options?: SubscriptionHookOptions<Id<T> | null>) => [
41
+ myPresence: Id<T>,
42
+ updateMyPresence: Dispatch<UpdateMyPresenceAction<TPresence>>
43
+ ];
44
+ usePluvMyself: <T extends unknown = UserInfo<TIO, TPresence>>(selector?: (myself: Id<UserInfo<TIO, TPresence>>) => T, options?: SubscriptionHookOptions<Id<T> | null>) => Id<T> | null;
45
+ usePluvOther: <T extends unknown = UserInfo<TIO, TPresence>>(connectionId: string, selector?: (other: UserInfo<TIO, TPresence>) => T, options?: SubscriptionHookOptions<Id<T> | null>) => Id<T> | null;
46
+ usePluvOthers: <T extends unknown = UserInfo<TIO, TPresence>>(selector?: (other: readonly Id<UserInfo<TIO, TPresence>>[]) => T[], options?: SubscriptionHookOptions<readonly Id<T>[]>) => readonly Id<T>[];
47
+ usePluvRoom: () => AbstractRoom<TIO, TPresence, TStorage>;
48
+ 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];
49
+ }
50
+
51
+ interface PluvProviderProps {
52
+ children?: ReactNode;
53
+ }
54
+ interface CreateBundle<TIO extends IOLike> {
55
+ createRoomBundle: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}>(options?: CreateRoomBundleOptions<TIO, TPresence, TStorage>) => CreateRoomBundle<TIO, TPresence, TStorage>;
56
+ PluvProvider: FC<PluvProviderProps>;
57
+ usePluvClient: () => PluvClient<TIO>;
58
+ }
59
+ declare const createBundle: <TIO extends IOLike<_pluv_types.IOAuthorize<any, any>, {}, {}, {}, {}>>(client: PluvClient<TIO>) => CreateBundle<TIO>;
60
+
61
+ export { CreateBundle, CreateRoomBundle, CreateRoomBundleOptions, PluvProviderProps, PluvRoomProviderProps, SubscriptionHookOptions, createBundle };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
- import { PluvRoomDebug, WebSocketConnection, UserInfo, AbstractRoom, InferYjsSharedTypeJson, MockedRoomEvents, PluvClient } from '@pluv/client';
1
+ import { PluvRoomAddon, 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
- import { JsonObject, InputZodLike, IOLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
4
+ import { IOLike, JsonObject, InputZodLike, InferIOInput, Id, InferIOOutput, IOEventMessage } from '@pluv/types';
5
5
  export { BaseUser, EventMessage, EventRecord, IOEventMessage } from '@pluv/types';
6
6
  import { FC, Dispatch, ReactNode } from 'react';
7
7
  import { AbstractType } from 'yjs';
8
8
 
9
- interface CreateRoomBundleOptions<TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> {
9
+ interface CreateRoomBundleOptions<TIO extends IOLike, TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}> {
10
+ addons?: readonly PluvRoomAddon<TIO, TPresence, TStorage>[];
10
11
  initialStorage?: () => TStorage;
11
12
  presence?: InputZodLike<TPresence>;
12
13
  }
@@ -51,7 +52,7 @@ interface PluvProviderProps {
51
52
  children?: ReactNode;
52
53
  }
53
54
  interface CreateBundle<TIO extends IOLike> {
54
- createRoomBundle: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}>(options?: CreateRoomBundleOptions<TPresence, TStorage>) => CreateRoomBundle<TIO, TPresence, TStorage>;
55
+ createRoomBundle: <TPresence extends JsonObject = {}, TStorage extends Record<string, AbstractType<any>> = {}>(options?: CreateRoomBundleOptions<TIO, TPresence, TStorage>) => CreateRoomBundle<TIO, TPresence, TStorage>;
55
56
  PluvProvider: FC<PluvProviderProps>;
56
57
  usePluvClient: () => PluvClient<TIO>;
57
58
  }
package/dist/index.js CHANGED
@@ -104,6 +104,7 @@ var createRoomBundle = (client, options = {}) => {
104
104
  const { room: mockedRoom } = (0, import_react2.useContext)(MockedRoomContext);
105
105
  const [room] = (0, import_react2.useState)(() => {
106
106
  return client.createRoom(_room, {
107
+ addons: options.addons,
107
108
  debug,
108
109
  initialPresence,
109
110
  initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
package/dist/index.mjs CHANGED
@@ -74,6 +74,7 @@ var createRoomBundle = (client, options = {}) => {
74
74
  const { room: mockedRoom } = useContext(MockedRoomContext);
75
75
  const [room] = useState2(() => {
76
76
  return client.createRoom(_room, {
77
+ addons: options.addons,
77
78
  debug,
78
79
  initialPresence,
79
80
  initialStorage: typeof initialStorage === "function" ? initialStorage : options.initialStorage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/react",
3
- "version": "0.5.11",
3
+ "version": "0.6.1",
4
4
  "description": "@pluv/client React.js bindings",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -20,21 +20,21 @@
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.8.1",
24
- "@pluv/types": "^0.2.0"
23
+ "@pluv/client": "^0.9.1",
24
+ "@pluv/types": "^0.2.2"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^17.0.0 || ^18.0.0",
28
28
  "yjs": "^13.0.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@types/react": "18.2.6",
31
+ "@types/react": "18.2.15",
32
32
  "react": "18.2.0",
33
- "tsup": "^6.7.0",
34
- "typescript": "^5.0.4",
35
- "yjs": "^13.6.1",
36
- "@pluv/tsconfig": "^0.1.6",
37
- "eslint-config-pluv": "^0.1.12"
33
+ "tsup": "^7.1.0",
34
+ "typescript": "^5.1.6",
35
+ "yjs": "^13.6.6",
36
+ "@pluv/tsconfig": "^0.1.8",
37
+ "eslint-config-pluv": "^0.1.14"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup src/index.ts --format esm,cjs --dts --external react",
@@ -19,7 +19,7 @@ export interface CreateBundle<TIO extends IOLike> {
19
19
  TPresence extends JsonObject = {},
20
20
  TStorage extends Record<string, AbstractType<any>> = {}
21
21
  >(
22
- options?: CreateRoomBundleOptions<TPresence, TStorage>
22
+ options?: CreateRoomBundleOptions<TIO, TPresence, TStorage>
23
23
  ) => CreateRoomBundle<TIO, TPresence, TStorage>;
24
24
 
25
25
  // components
@@ -59,7 +59,7 @@ export const createBundle = <TIO extends IOLike>(
59
59
  TPresence extends JsonObject = {},
60
60
  TStorage extends Record<string, AbstractType<any>> = {}
61
61
  >(
62
- options: CreateRoomBundleOptions<TPresence, TStorage> = {}
62
+ options: CreateRoomBundleOptions<TIO, TPresence, TStorage> = {}
63
63
  ): CreateRoomBundle<TIO, TPresence, TStorage> =>
64
64
  _createRoomBundle(client, options);
65
65
 
@@ -4,6 +4,7 @@ import type {
4
4
  MockedRoomEvents,
5
5
  PluvClient,
6
6
  PluvRoom,
7
+ PluvRoomAddon,
7
8
  PluvRoomDebug,
8
9
  UserInfo,
9
10
  WebSocketConnection,
@@ -37,9 +38,11 @@ import {
37
38
  } from "./internal";
38
39
 
39
40
  export interface CreateRoomBundleOptions<
41
+ TIO extends IOLike,
40
42
  TPresence extends JsonObject = {},
41
43
  TStorage extends Record<string, AbstractType<any>> = {}
42
44
  > {
45
+ addons?: readonly PluvRoomAddon<TIO, TPresence, TStorage>[];
43
46
  initialStorage?: () => TStorage;
44
47
  presence?: InputZodLike<TPresence>;
45
48
  }
@@ -139,7 +142,7 @@ export const createRoomBundle = <
139
142
  TStorage extends Record<string, AbstractType<any>> = {}
140
143
  >(
141
144
  client: PluvClient<TIO>,
142
- options: CreateRoomBundleOptions<TPresence, TStorage> = {}
145
+ options: CreateRoomBundleOptions<TIO, TPresence, TStorage> = {}
143
146
  ): CreateRoomBundle<TIO, TPresence, TStorage> => {
144
147
  /**
145
148
  * !HACK
@@ -207,6 +210,7 @@ export const createRoomBundle = <
207
210
 
208
211
  const [room] = useState<PluvRoom<TIO, TPresence, TStorage>>(() => {
209
212
  return client.createRoom<TPresence, TStorage>(_room, {
213
+ addons: options.addons,
210
214
  debug,
211
215
  initialPresence,
212
216
  initialStorage: