@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.
@@ -5,14 +5,14 @@
5
5
  CLI Target: esnext
6
6
  CJS Build start
7
7
  ESM Build start
8
- ESM dist/index.mjs 29.75 KB
9
- ESM dist/index.mjs.map 53.84 KB
10
- ESM ⚡️ Build success in 50ms
11
- CJS dist/index.js 33.83 KB
12
- CJS dist/index.js.map 53.63 KB
13
- CJS ⚡️ Build success in 70ms
8
+ ESM dist/index.mjs 37.08 KB
9
+ ESM dist/index.mjs.map 67.28 KB
10
+ ESM ⚡️ Build success in 79ms
11
+ CJS dist/index.js 41.86 KB
12
+ CJS dist/index.js.map 67.12 KB
13
+ CJS ⚡️ Build success in 80ms
14
14
  DTS Build start
15
- "ComponentPropsWithoutRef" is imported from external module "react" but never used in "src/inspector/StateInspector.tsx" and "src/hooks.ts".
16
- DTS ⚡️ Build success in 2630ms
17
- DTS dist/index.d.ts 2.69 KB
18
- DTS dist/index.d.mts 2.69 KB
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
+ DTS ⚡️ Build success in 3235ms
17
+ DTS dist/index.d.ts 4.71 KB
18
+ DTS dist/index.d.mts 4.71 KB
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 { ConnectionEvent, MultiplayerUser, Task, MultiplayerStateManager, StateManager, Get, StateManagerOptions, MultiplayerStateManagerOptions } from '@noya-app/state-manager';
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 useMultiplayerState<S extends object, M = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
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 { ConnectionEvent, MultiplayerUser, Task, MultiplayerStateManager, StateManager, Get, StateManagerOptions, MultiplayerStateManagerOptions } from '@noya-app/state-manager';
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 useMultiplayerState<S extends object, M = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
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 };