@idosgames/react 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 iDos Games
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # @idosgames/react
2
+
3
+ Shared React glue for the iDosGames host shell and its composable modules — the pieces every module
4
+ used to copy-paste, extracted into one package.
5
+
6
+ - `IDosGamesProvider` / `useIDosGamesClient` — provide and read the one shared SDK client.
7
+ - `StatusProvider` / `useStatus` — a transient status line shared across the app.
8
+ - `useUserState` / `useSdkEvent` — live SDK state hooks (re-render on cache changes / typed events).
9
+ - `createControllerContext<T>(name)` — factory for a module's typed controller context (replaces the
10
+ hand-written Provider + guarded `useContext` pair each module used to write).
11
+
12
+ ```ts
13
+ import {
14
+ useIDosGamesClient,
15
+ useUserState,
16
+ createControllerContext,
17
+ } from "@idosgames/react";
18
+ ```
19
+
20
+ Built for [`@idosgames/core`](https://www.npmjs.com/package/@idosgames/core) and the module contract
21
+ in [`@idosgames/module-sdk`](https://www.npmjs.com/package/@idosgames/module-sdk). React is a peer
22
+ dependency. See `docs/composable-modules-architecture.md` for the architecture.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var u=react.createContext(null);function f({client:e,children:t}){return jsxRuntime.jsx(u.Provider,{value:e,children:t})}function n(){let e=react.useContext(u);if(!e)throw new Error("useIDosGamesClient must be used within <IDosGamesProvider>.");return e}var l=react.createContext(null);function y({children:e}){let[t,o]=react.useState(null),s=react.useCallback((c,p="info")=>{o({text:c,kind:p});},[]),r=react.useCallback(()=>{o(null);},[]),i=react.useMemo(()=>({message:t,setStatus:s,clear:r}),[t,s,r]);return jsxRuntime.jsx(l.Provider,{value:i,children:e})}function D(){let e=react.useContext(l);if(!e)throw new Error("useStatus must be used within <StatusProvider>.");return e}function R(){let e=n(),[,t]=react.useReducer(o=>o+1,0);return react.useEffect(()=>e.on("user:anyUpdated",()=>{t();}),[e]),e.data.user.state}function N(e,t){let o=n();react.useEffect(()=>o.on(e,t),[o,e,t]);}function E(e){let t=react.createContext(null);function o({controller:r,children:i}){return jsxRuntime.jsx(t.Provider,{value:r,children:i})}function s(){let r=react.useContext(t);if(r===null)throw new Error(`use${e} must be used within its <${e}Provider>.`);return r}return [o,s]}exports.IDosGamesProvider=f;exports.StatusProvider=y;exports.createControllerContext=E;exports.useIDosGamesClient=n;exports.useSdkEvent=N;exports.useStatus=D;exports.useUserState=R;
@@ -0,0 +1,44 @@
1
+ import { ReactNode } from 'react';
2
+ import { IDosGamesClient, SdkEvents, UserState } from '@idosgames/core';
3
+
4
+ declare function IDosGamesProvider({ client, children, }: {
5
+ client: IDosGamesClient;
6
+ children: ReactNode;
7
+ }): ReactNode;
8
+ declare function useIDosGamesClient(): IDosGamesClient;
9
+
10
+ type StatusKind = "info" | "success" | "error";
11
+ interface StatusMessage {
12
+ text: string;
13
+ kind: StatusKind;
14
+ }
15
+ interface StatusApi {
16
+ message: StatusMessage | null;
17
+ setStatus: (text: string, kind?: StatusKind) => void;
18
+ clear: () => void;
19
+ }
20
+ declare function StatusProvider({ children, }: {
21
+ children: ReactNode;
22
+ }): ReactNode;
23
+ declare function useStatus(): StatusApi;
24
+
25
+ /** Live user state that re-renders the component whenever the SDK cache changes. */
26
+ declare function useUserState(): UserState | null;
27
+ /** Subscribe to a typed SDK event for the lifetime of the component. */
28
+ declare function useSdkEvent<K extends keyof SdkEvents>(event: K, handler: (payload: SdkEvents[K]) => void): void;
29
+
30
+ interface ControllerProviderProps<T> {
31
+ controller: T;
32
+ children: ReactNode;
33
+ }
34
+ /**
35
+ * Build a typed controller context.
36
+ *
37
+ * const [BoardControllerProvider, useBoardController] =
38
+ * createControllerContext<BoardController>("BoardController");
39
+ *
40
+ * @param name Used only in the "must be used within its provider" error message.
41
+ */
42
+ declare function createControllerContext<T>(name: string): readonly [(props: ControllerProviderProps<T>) => ReactNode, () => T];
43
+
44
+ export { type ControllerProviderProps, IDosGamesProvider, type StatusKind, type StatusMessage, StatusProvider, createControllerContext, useIDosGamesClient, useSdkEvent, useStatus, useUserState };
@@ -0,0 +1,44 @@
1
+ import { ReactNode } from 'react';
2
+ import { IDosGamesClient, SdkEvents, UserState } from '@idosgames/core';
3
+
4
+ declare function IDosGamesProvider({ client, children, }: {
5
+ client: IDosGamesClient;
6
+ children: ReactNode;
7
+ }): ReactNode;
8
+ declare function useIDosGamesClient(): IDosGamesClient;
9
+
10
+ type StatusKind = "info" | "success" | "error";
11
+ interface StatusMessage {
12
+ text: string;
13
+ kind: StatusKind;
14
+ }
15
+ interface StatusApi {
16
+ message: StatusMessage | null;
17
+ setStatus: (text: string, kind?: StatusKind) => void;
18
+ clear: () => void;
19
+ }
20
+ declare function StatusProvider({ children, }: {
21
+ children: ReactNode;
22
+ }): ReactNode;
23
+ declare function useStatus(): StatusApi;
24
+
25
+ /** Live user state that re-renders the component whenever the SDK cache changes. */
26
+ declare function useUserState(): UserState | null;
27
+ /** Subscribe to a typed SDK event for the lifetime of the component. */
28
+ declare function useSdkEvent<K extends keyof SdkEvents>(event: K, handler: (payload: SdkEvents[K]) => void): void;
29
+
30
+ interface ControllerProviderProps<T> {
31
+ controller: T;
32
+ children: ReactNode;
33
+ }
34
+ /**
35
+ * Build a typed controller context.
36
+ *
37
+ * const [BoardControllerProvider, useBoardController] =
38
+ * createControllerContext<BoardController>("BoardController");
39
+ *
40
+ * @param name Used only in the "must be used within its provider" error message.
41
+ */
42
+ declare function createControllerContext<T>(name: string): readonly [(props: ControllerProviderProps<T>) => ReactNode, () => T];
43
+
44
+ export { type ControllerProviderProps, IDosGamesProvider, type StatusKind, type StatusMessage, StatusProvider, createControllerContext, useIDosGamesClient, useSdkEvent, useStatus, useUserState };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import {createContext,useContext,useState,useCallback,useMemo,useReducer,useEffect}from'react';import {jsx}from'react/jsx-runtime';var u=createContext(null);function f({client:e,children:t}){return jsx(u.Provider,{value:e,children:t})}function n(){let e=useContext(u);if(!e)throw new Error("useIDosGamesClient must be used within <IDosGamesProvider>.");return e}var l=createContext(null);function y({children:e}){let[t,o]=useState(null),s=useCallback((c,p="info")=>{o({text:c,kind:p});},[]),r=useCallback(()=>{o(null);},[]),i=useMemo(()=>({message:t,setStatus:s,clear:r}),[t,s,r]);return jsx(l.Provider,{value:i,children:e})}function D(){let e=useContext(l);if(!e)throw new Error("useStatus must be used within <StatusProvider>.");return e}function R(){let e=n(),[,t]=useReducer(o=>o+1,0);return useEffect(()=>e.on("user:anyUpdated",()=>{t();}),[e]),e.data.user.state}function N(e,t){let o=n();useEffect(()=>o.on(e,t),[o,e,t]);}function E(e){let t=createContext(null);function o({controller:r,children:i}){return jsx(t.Provider,{value:r,children:i})}function s(){let r=useContext(t);if(r===null)throw new Error(`use${e} must be used within its <${e}Provider>.`);return r}return [o,s]}export{f as IDosGamesProvider,y as StatusProvider,E as createControllerContext,n as useIDosGamesClient,N as useSdkEvent,D as useStatus,R as useUserState};
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@idosgames/react",
3
+ "version": "0.1.0",
4
+ "description": "Shared React glue for the iDosGames host shell and modules: the client provider, status provider, live-state hooks, and a controller-context factory. Extracted from what every template used to copy-paste.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "iDos Games",
8
+ "homepage": "https://github.com/iDos-Games/iDosGamesSDK_TS#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/iDos-Games/iDosGamesSDK_TS.git",
12
+ "directory": "packages/react"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/iDos-Games/iDosGamesSDK_TS/issues"
16
+ },
17
+ "keywords": [
18
+ "idosgames",
19
+ "sdk",
20
+ "react",
21
+ "hooks"
22
+ ],
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "sideEffects": false,
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "typecheck": "tsc --noEmit -p tsconfig.json"
45
+ },
46
+ "//": "react is a peer (consumer-provided, never bundled). @idosgames/core is a real range for the same reason as in @idosgames/wallet — a published package must pin the core whose types it references.",
47
+ "dependencies": {
48
+ "@idosgames/core": "^0.1.1"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "^18.3.1 || ^19.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@types/react": "^19.2.17",
55
+ "react": "^19.2.7"
56
+ }
57
+ }