@noya-app/noya-multiplayer-react 0.1.17 → 0.1.19
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 +10 -10
- package/CHANGELOG.md +20 -0
- package/dist/index.d.mts +55 -4
- package/dist/index.d.ts +55 -4
- package/dist/index.js +353 -132
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +321 -107
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/avatarStyle.ts +82 -0
- package/src/components/UserPointersOverlay.tsx +182 -0
- package/src/globals.ts +1 -39
- package/src/hooks.ts +28 -10
- package/src/index.ts +2 -0
- package/src/inspector/StateInspector.tsx +29 -1
- package/src/inspector/useStateInspector.tsx +6 -1
- package/src/useObservable.ts +25 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
[34mCLI[39m Target: esnext
|
|
6
6
|
[34mCJS[39m Build start
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
9
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
10
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
13
|
-
[32mCJS[39m ⚡️ Build success in
|
|
8
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m37.08 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m67.28 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 79ms
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m41.86 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m67.12 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 80ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
"ComponentPropsWithoutRef" is imported from external module "react" but never used in "src/inspector/StateInspector.tsx" and "src/hooks.ts".
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
15
|
+
"ComponentPropsWithoutRef" is imported from external module "react" but never used in "src/components/UserPointersOverlay.tsx", "src/inspector/StateInspector.tsx" and "src/hooks.ts".
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3235ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m4.71 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m4.71 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @noya-app/state-manager
|
|
2
2
|
|
|
3
|
+
## 0.1.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 35b2424: Add ephemeral data and observable
|
|
8
|
+
- Updated dependencies [35b2424]
|
|
9
|
+
- Updated dependencies [48cd6ba]
|
|
10
|
+
- Updated dependencies [6d2cf3d]
|
|
11
|
+
- Updated dependencies [1b63535]
|
|
12
|
+
- @noya-app/state-manager@0.1.19
|
|
13
|
+
- @noya-app/observable@0.1.1
|
|
14
|
+
|
|
15
|
+
## 0.1.18
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 536ef31: Add ephemeral user data
|
|
20
|
+
- Updated dependencies [536ef31]
|
|
21
|
+
- @noya-app/state-manager@0.1.18
|
|
22
|
+
|
|
3
23
|
## 0.1.17
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
import * as _noya_app_state_manager from '@noya-app/state-manager';
|
|
2
|
-
import {
|
|
2
|
+
import { MultiplayerUser, EphemeralUserData, ConnectionEvent, Task, MultiplayerStateManager, StateManager, Get, StateManagerOptions, MultiplayerStateManagerOptions } from '@noya-app/state-manager';
|
|
3
3
|
export * from '@noya-app/state-manager';
|
|
4
4
|
import React, { SetStateAction, ComponentProps } from 'react';
|
|
5
5
|
|
|
6
|
+
declare function getAvatarInitials(name: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Create a background color and initials from a name
|
|
9
|
+
*
|
|
10
|
+
* Adapted from https://mui.com/material-ui/react-avatar/
|
|
11
|
+
*/
|
|
12
|
+
declare function getAvatarStyle(name: string): {
|
|
13
|
+
color: string;
|
|
14
|
+
backgroundColor: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Point = {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
type UserPointerData = {
|
|
22
|
+
pointer?: Point;
|
|
23
|
+
};
|
|
24
|
+
type UserPointerProps<E extends UserPointerData> = {
|
|
25
|
+
user: MultiplayerUser;
|
|
26
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
27
|
+
hideAfter?: number;
|
|
28
|
+
};
|
|
29
|
+
declare const UserPointer: <E extends UserPointerData>({ user, ephemeralUserData, hideAfter, }: UserPointerProps<E>) => React.JSX.Element | null;
|
|
30
|
+
declare const UserPointerContainer: React.NamedExoticComponent<{
|
|
31
|
+
point: Point;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
show?: boolean | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
declare const UserNameTag: React.NamedExoticComponent<{
|
|
36
|
+
background: string;
|
|
37
|
+
children: React.ReactNode;
|
|
38
|
+
}>;
|
|
39
|
+
type UserPointersOverlayProps<E extends UserPointerData> = {
|
|
40
|
+
connectedUsers: MultiplayerUser[];
|
|
41
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
42
|
+
};
|
|
43
|
+
declare const UserPointersOverlay: React.MemoExoticComponent<(<E extends UserPointerData>({ connectedUsers, ephemeralUserData }: UserPointersOverlayProps<E>) => React.JSX.Element)>;
|
|
44
|
+
declare const UserPointerIcon: React.NamedExoticComponent<{
|
|
45
|
+
color?: string | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
6
48
|
type Anchor = "left" | "right" | "bottom left" | "bottom right";
|
|
7
|
-
declare const StateInspector: React.MemoExoticComponent<(<S extends object, M>({ state, connectionEvents, connectedUsers, tasks, userId, unstyled, colorScheme, multiplayerStateManager, anchor, forceInit, ...props }: {
|
|
49
|
+
declare const StateInspector: React.MemoExoticComponent<(<S extends object, M, E>({ state, connectionEvents, connectedUsers, tasks, userId, unstyled, colorScheme, multiplayerStateManager, ephemeralUserData, anchor, forceInit, ...props }: {
|
|
8
50
|
state: S;
|
|
9
51
|
connectionEvents?: ConnectionEvent<S>[] | undefined;
|
|
10
52
|
connectedUsers?: MultiplayerUser[] | undefined;
|
|
@@ -13,6 +55,7 @@ declare const StateInspector: React.MemoExoticComponent<(<S extends object, M>({
|
|
|
13
55
|
unstyled?: boolean | undefined;
|
|
14
56
|
colorScheme?: "light" | "dark" | undefined;
|
|
15
57
|
multiplayerStateManager: MultiplayerStateManager<S, M>;
|
|
58
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
16
59
|
anchor?: Anchor | undefined;
|
|
17
60
|
forceInit: () => void;
|
|
18
61
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">) => React.JSX.Element | null)>;
|
|
@@ -22,17 +65,25 @@ declare function useSyncStateManager<S extends object, M, P extends string>(stat
|
|
|
22
65
|
declare function useManagedState<S extends object, M = void>(createInitialState: () => S, options?: StateManagerOptions<S, M>): readonly [S, (...args: M extends {} ? [metadata: M, action: SetStateAction<S>] : [action: SetStateAction<S>]) => void, StateManager<S, M>];
|
|
23
66
|
declare function useManagedHistory<S extends object, M = void>(stateManager: StateManager<S, M>): _noya_app_state_manager.HistorySnapshot<S, M>;
|
|
24
67
|
declare function useSyncMultiplayerStateManager<S extends object, M = void>(multiplayerStateManager: MultiplayerStateManager<S, M>): S;
|
|
25
|
-
declare function
|
|
68
|
+
declare function useEphemeralUserData<E>(ephemeralUserData: EphemeralUserData<E>): {
|
|
69
|
+
data: Record<string, E | undefined>;
|
|
70
|
+
metadata: Record<string, _noya_app_state_manager.EphemeralUserMetadata | undefined>;
|
|
71
|
+
currentUserId: string | undefined;
|
|
72
|
+
};
|
|
73
|
+
declare function useMultiplayerState<S extends object, M = void, E = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
|
|
26
74
|
sync?: (options: {
|
|
27
75
|
ms: MultiplayerStateManager<S, M>;
|
|
76
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
28
77
|
}) => void;
|
|
29
78
|
trackConnectionEvents?: boolean;
|
|
30
79
|
trackTasks?: boolean;
|
|
31
80
|
inspector?: boolean | Pick<ComponentProps<typeof StateInspector>, "colorScheme" | "anchor">;
|
|
32
81
|
}): readonly [S, (...args: M extends {} ? [metadata: M, action: S | ((prevState: S) => S)] : [action: S | ((prevState: S) => S)]) => void, MultiplayerStateManager<S, M>, {
|
|
33
82
|
tasks: Task[];
|
|
83
|
+
userId: string | undefined;
|
|
34
84
|
connectionEvents: ConnectionEvent<S>[] | undefined;
|
|
35
85
|
connectedUsers: MultiplayerUser[];
|
|
86
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
36
87
|
}];
|
|
37
88
|
|
|
38
|
-
export { StateInspector, useManagedHistory, useManagedState, useMultiplayerState, useSyncMultiplayerStateManager, useSyncStateManager };
|
|
89
|
+
export { StateInspector, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, getAvatarInitials, getAvatarStyle, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useSyncMultiplayerStateManager, useSyncStateManager };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
import * as _noya_app_state_manager from '@noya-app/state-manager';
|
|
2
|
-
import {
|
|
2
|
+
import { MultiplayerUser, EphemeralUserData, ConnectionEvent, Task, MultiplayerStateManager, StateManager, Get, StateManagerOptions, MultiplayerStateManagerOptions } from '@noya-app/state-manager';
|
|
3
3
|
export * from '@noya-app/state-manager';
|
|
4
4
|
import React, { SetStateAction, ComponentProps } from 'react';
|
|
5
5
|
|
|
6
|
+
declare function getAvatarInitials(name: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Create a background color and initials from a name
|
|
9
|
+
*
|
|
10
|
+
* Adapted from https://mui.com/material-ui/react-avatar/
|
|
11
|
+
*/
|
|
12
|
+
declare function getAvatarStyle(name: string): {
|
|
13
|
+
color: string;
|
|
14
|
+
backgroundColor: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type Point = {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
};
|
|
21
|
+
type UserPointerData = {
|
|
22
|
+
pointer?: Point;
|
|
23
|
+
};
|
|
24
|
+
type UserPointerProps<E extends UserPointerData> = {
|
|
25
|
+
user: MultiplayerUser;
|
|
26
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
27
|
+
hideAfter?: number;
|
|
28
|
+
};
|
|
29
|
+
declare const UserPointer: <E extends UserPointerData>({ user, ephemeralUserData, hideAfter, }: UserPointerProps<E>) => React.JSX.Element | null;
|
|
30
|
+
declare const UserPointerContainer: React.NamedExoticComponent<{
|
|
31
|
+
point: Point;
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
show?: boolean | undefined;
|
|
34
|
+
}>;
|
|
35
|
+
declare const UserNameTag: React.NamedExoticComponent<{
|
|
36
|
+
background: string;
|
|
37
|
+
children: React.ReactNode;
|
|
38
|
+
}>;
|
|
39
|
+
type UserPointersOverlayProps<E extends UserPointerData> = {
|
|
40
|
+
connectedUsers: MultiplayerUser[];
|
|
41
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
42
|
+
};
|
|
43
|
+
declare const UserPointersOverlay: React.MemoExoticComponent<(<E extends UserPointerData>({ connectedUsers, ephemeralUserData }: UserPointersOverlayProps<E>) => React.JSX.Element)>;
|
|
44
|
+
declare const UserPointerIcon: React.NamedExoticComponent<{
|
|
45
|
+
color?: string | undefined;
|
|
46
|
+
}>;
|
|
47
|
+
|
|
6
48
|
type Anchor = "left" | "right" | "bottom left" | "bottom right";
|
|
7
|
-
declare const StateInspector: React.MemoExoticComponent<(<S extends object, M>({ state, connectionEvents, connectedUsers, tasks, userId, unstyled, colorScheme, multiplayerStateManager, anchor, forceInit, ...props }: {
|
|
49
|
+
declare const StateInspector: React.MemoExoticComponent<(<S extends object, M, E>({ state, connectionEvents, connectedUsers, tasks, userId, unstyled, colorScheme, multiplayerStateManager, ephemeralUserData, anchor, forceInit, ...props }: {
|
|
8
50
|
state: S;
|
|
9
51
|
connectionEvents?: ConnectionEvent<S>[] | undefined;
|
|
10
52
|
connectedUsers?: MultiplayerUser[] | undefined;
|
|
@@ -13,6 +55,7 @@ declare const StateInspector: React.MemoExoticComponent<(<S extends object, M>({
|
|
|
13
55
|
unstyled?: boolean | undefined;
|
|
14
56
|
colorScheme?: "light" | "dark" | undefined;
|
|
15
57
|
multiplayerStateManager: MultiplayerStateManager<S, M>;
|
|
58
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
16
59
|
anchor?: Anchor | undefined;
|
|
17
60
|
forceInit: () => void;
|
|
18
61
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref">) => React.JSX.Element | null)>;
|
|
@@ -22,17 +65,25 @@ declare function useSyncStateManager<S extends object, M, P extends string>(stat
|
|
|
22
65
|
declare function useManagedState<S extends object, M = void>(createInitialState: () => S, options?: StateManagerOptions<S, M>): readonly [S, (...args: M extends {} ? [metadata: M, action: SetStateAction<S>] : [action: SetStateAction<S>]) => void, StateManager<S, M>];
|
|
23
66
|
declare function useManagedHistory<S extends object, M = void>(stateManager: StateManager<S, M>): _noya_app_state_manager.HistorySnapshot<S, M>;
|
|
24
67
|
declare function useSyncMultiplayerStateManager<S extends object, M = void>(multiplayerStateManager: MultiplayerStateManager<S, M>): S;
|
|
25
|
-
declare function
|
|
68
|
+
declare function useEphemeralUserData<E>(ephemeralUserData: EphemeralUserData<E>): {
|
|
69
|
+
data: Record<string, E | undefined>;
|
|
70
|
+
metadata: Record<string, _noya_app_state_manager.EphemeralUserMetadata | undefined>;
|
|
71
|
+
currentUserId: string | undefined;
|
|
72
|
+
};
|
|
73
|
+
declare function useMultiplayerState<S extends object, M = void, E = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
|
|
26
74
|
sync?: (options: {
|
|
27
75
|
ms: MultiplayerStateManager<S, M>;
|
|
76
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
28
77
|
}) => void;
|
|
29
78
|
trackConnectionEvents?: boolean;
|
|
30
79
|
trackTasks?: boolean;
|
|
31
80
|
inspector?: boolean | Pick<ComponentProps<typeof StateInspector>, "colorScheme" | "anchor">;
|
|
32
81
|
}): readonly [S, (...args: M extends {} ? [metadata: M, action: S | ((prevState: S) => S)] : [action: S | ((prevState: S) => S)]) => void, MultiplayerStateManager<S, M>, {
|
|
33
82
|
tasks: Task[];
|
|
83
|
+
userId: string | undefined;
|
|
34
84
|
connectionEvents: ConnectionEvent<S>[] | undefined;
|
|
35
85
|
connectedUsers: MultiplayerUser[];
|
|
86
|
+
ephemeralUserData: EphemeralUserData<E>;
|
|
36
87
|
}];
|
|
37
88
|
|
|
38
|
-
export { StateInspector, useManagedHistory, useManagedState, useMultiplayerState, useSyncMultiplayerStateManager, useSyncStateManager };
|
|
89
|
+
export { StateInspector, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, getAvatarInitials, getAvatarStyle, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useSyncMultiplayerStateManager, useSyncStateManager };
|