@noya-app/noya-multiplayer-react 0.1.18 → 0.1.20

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 30.94 KB
9
- ESM dist/index.mjs.map 56.01 KB
10
- ESM ⚡️ Build success in 35ms
11
- CJS dist/index.js 35.19 KB
12
- CJS dist/index.js.map 55.79 KB
13
- CJS ⚡️ Build success in 37ms
8
+ ESM dist/index.mjs 37.54 KB
9
+ ESM dist/index.mjs.map 68.07 KB
10
+ ESM ⚡️ Build success in 21ms
11
+ CJS dist/index.js 42.34 KB
12
+ CJS dist/index.js.map 67.91 KB
13
+ CJS ⚡️ Build success in 22ms
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 2094ms
17
- DTS dist/index.d.ts 3.00 KB
18
- DTS dist/index.d.mts 3.00 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 4487ms
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,23 @@
1
1
  # @noya-app/state-manager
2
2
 
3
+ ## 0.1.20
4
+
5
+ ### Patch Changes
6
+
7
+ - 499628d: Improve graphics
8
+
9
+ ## 0.1.19
10
+
11
+ ### Patch Changes
12
+
13
+ - 35b2424: Add ephemeral data and observable
14
+ - Updated dependencies [35b2424]
15
+ - Updated dependencies [48cd6ba]
16
+ - Updated dependencies [6d2cf3d]
17
+ - Updated dependencies [1b63535]
18
+ - @noya-app/state-manager@0.1.19
19
+ - @noya-app/observable@0.1.1
20
+
3
21
  ## 0.1.18
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,8 +1,50 @@
1
1
  import * as _noya_app_state_manager from '@noya-app/state-manager';
2
- import { ConnectionEvent, MultiplayerUser, Task, MultiplayerStateManager, EphemeralUserData, 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
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;
@@ -23,7 +65,11 @@ declare function useSyncStateManager<S extends object, M, P extends string>(stat
23
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>];
24
66
  declare function useManagedHistory<S extends object, M = void>(stateManager: StateManager<S, M>): _noya_app_state_manager.HistorySnapshot<S, M>;
25
67
  declare function useSyncMultiplayerStateManager<S extends object, M = void>(multiplayerStateManager: MultiplayerStateManager<S, M>): S;
26
- declare function useEphemeralUserData<E>(ephemeralUserData: EphemeralUserData<E>): Record<string, E>;
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
+ };
27
73
  declare function useMultiplayerState<S extends object, M = void, E = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
28
74
  sync?: (options: {
29
75
  ms: MultiplayerStateManager<S, M>;
@@ -34,9 +80,10 @@ declare function useMultiplayerState<S extends object, M = void, E = void>(initi
34
80
  inspector?: boolean | Pick<ComponentProps<typeof StateInspector>, "colorScheme" | "anchor">;
35
81
  }): readonly [S, (...args: M extends {} ? [metadata: M, action: S | ((prevState: S) => S)] : [action: S | ((prevState: S) => S)]) => void, MultiplayerStateManager<S, M>, {
36
82
  tasks: Task[];
83
+ userId: string | undefined;
37
84
  connectionEvents: ConnectionEvent<S>[] | undefined;
38
85
  connectedUsers: MultiplayerUser[];
39
86
  ephemeralUserData: EphemeralUserData<E>;
40
87
  }];
41
88
 
42
- export { StateInspector, useEphemeralUserData, 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,8 +1,50 @@
1
1
  import * as _noya_app_state_manager from '@noya-app/state-manager';
2
- import { ConnectionEvent, MultiplayerUser, Task, MultiplayerStateManager, EphemeralUserData, 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
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;
@@ -23,7 +65,11 @@ declare function useSyncStateManager<S extends object, M, P extends string>(stat
23
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>];
24
66
  declare function useManagedHistory<S extends object, M = void>(stateManager: StateManager<S, M>): _noya_app_state_manager.HistorySnapshot<S, M>;
25
67
  declare function useSyncMultiplayerStateManager<S extends object, M = void>(multiplayerStateManager: MultiplayerStateManager<S, M>): S;
26
- declare function useEphemeralUserData<E>(ephemeralUserData: EphemeralUserData<E>): Record<string, E>;
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
+ };
27
73
  declare function useMultiplayerState<S extends object, M = void, E = void>(initialState: S | (() => S), options?: MultiplayerStateManagerOptions<S, M> & {
28
74
  sync?: (options: {
29
75
  ms: MultiplayerStateManager<S, M>;
@@ -34,9 +80,10 @@ declare function useMultiplayerState<S extends object, M = void, E = void>(initi
34
80
  inspector?: boolean | Pick<ComponentProps<typeof StateInspector>, "colorScheme" | "anchor">;
35
81
  }): readonly [S, (...args: M extends {} ? [metadata: M, action: S | ((prevState: S) => S)] : [action: S | ((prevState: S) => S)]) => void, MultiplayerStateManager<S, M>, {
36
82
  tasks: Task[];
83
+ userId: string | undefined;
37
84
  connectionEvents: ConnectionEvent<S>[] | undefined;
38
85
  connectedUsers: MultiplayerUser[];
39
86
  ephemeralUserData: EphemeralUserData<E>;
40
87
  }];
41
88
 
42
- export { StateInspector, useEphemeralUserData, 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 };