@hai3/react 0.2.0-alpha.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/CLAUDE.md +227 -0
- package/commands/hai3-duplicate-screenset.md +58 -0
- package/commands/hai3-new-component.md +76 -0
- package/commands/hai3-new-screen.md +81 -0
- package/commands/hai3-new-screenset.md +85 -0
- package/dist/index.cjs +27587 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +345 -0
- package/dist/index.d.ts +345 -0
- package/dist/index.js +27558 -0
- package/dist/index.js.map +1 -0
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +247 -0
- package/dist/types.d.ts +247 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/llms.txt +60 -0
- package/package.json +59 -0
package/dist/types.cjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
19
|
+
//# sourceMappingURL=types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * @hai3/react - Type Definitions\n *\n * Core types for HAI3 React bindings.\n * Provides type-safe hooks and components.\n *\n * Now using real imports from @hai3/framework since packages are built together.\n */\n\nimport type { ReactNode } from 'react';\nimport type {\n HAI3Config,\n HAI3App,\n RootState,\n Language,\n LanguageMetadata,\n MenuItemConfig,\n ScreensetDefinition,\n ScreensetCategory,\n} from '@hai3/framework';\n\n// Re-export imported types for convenience\nexport type { HAI3Config, HAI3App, MenuItemConfig, ScreensetDefinition, ScreensetCategory };\n\n// ============================================================================\n// Type Aliases\n// ============================================================================\n\n// From @hai3/store\ntype Selector<TResult, TState = RootState> = (state: TState) => TResult;\n\n// From @hai3/i18n (Language is now imported from @hai3/framework)\ntype TranslationParams = Record<string, string | number | boolean>;\n\n// ============================================================================\n// HAI3 Provider Props\n// ============================================================================\n\n/**\n * HAI3 Provider Props\n * Props for the main HAI3Provider component.\n *\n * @example\n * ```tsx\n * <HAI3Provider config={{ devMode: true }}>\n * <App />\n * </HAI3Provider>\n * ```\n */\nexport interface HAI3ProviderProps {\n /** Child components */\n children: ReactNode;\n /** HAI3 configuration */\n config?: HAI3Config;\n /** Pre-built HAI3 app instance (optional) */\n app?: HAI3App;\n}\n\n// ============================================================================\n// Hook Return Types\n// ============================================================================\n\n/**\n * useHAI3 Hook Return Type\n * Returns the HAI3 app instance from context.\n */\nexport type UseHAI3Return = HAI3App;\n\n/**\n * useAppSelector Hook\n * Type-safe selector hook for Redux state.\n *\n * @template TResult - The result type of the selector\n */\nexport type UseAppSelector = <TResult>(selector: Selector<TResult>) => TResult;\n\n/**\n * useAppDispatch Hook Return Type\n * Returns the typed dispatch function.\n */\nexport type UseAppDispatchReturn = (action: unknown) => unknown;\n\n/**\n * useTranslation Hook Return Type\n * Translation utilities.\n */\nexport interface UseTranslationReturn {\n /** Translate a key */\n t: (key: string, params?: TranslationParams) => string;\n /** Current language */\n language: Language | null;\n /** Change language */\n setLanguage: (language: Language) => Promise<void>;\n /** Check if current language is RTL */\n isRTL: boolean;\n}\n\n/**\n * useScreenTranslations Hook Return Type\n * Screen-level translation loading state.\n */\nexport interface UseScreenTranslationsReturn {\n /** Whether translations are loaded */\n isLoaded: boolean;\n /** Loading error (if any) */\n error: Error | null;\n}\n\n/**\n * useLanguage Hook Return Type\n * Language selection utilities.\n */\nexport interface UseLanguageReturn {\n /** Current language */\n current: Language | null;\n /** All supported languages */\n supported: LanguageMetadata[];\n /** Change language */\n setLanguage: (language: Language) => Promise<void>;\n /** Check if current language is RTL */\n isRTL: boolean;\n}\n\n/**\n * useTheme Hook Return Type\n * Theme utilities.\n */\nexport interface UseThemeReturn {\n /** Current theme ID */\n currentTheme: string | undefined;\n /** All available themes */\n themes: Array<{ id: string; name: string }>;\n /** Change theme */\n setTheme: (themeId: string) => void;\n}\n\n/**\n * useMenu Hook Return Type\n * Menu state and actions.\n */\nexport interface UseMenuReturn {\n /** Menu items */\n items: MenuItemConfig[];\n /** Whether menu is collapsed */\n collapsed: boolean;\n /** Whether menu is visible */\n visible: boolean;\n /** Toggle menu collapse */\n toggle: () => void;\n /** Set collapsed state */\n setCollapsed: (collapsed: boolean) => void;\n}\n\n/**\n * useScreen Hook Return Type\n * Current screen state.\n */\nexport interface UseScreenReturn {\n /** Active screen ID */\n activeScreen: string | null;\n /** Whether screen is loading */\n isLoading: boolean;\n}\n\n/**\n * useNavigation Hook Return Type\n * Navigation utilities.\n */\nexport interface UseNavigationReturn {\n /** Navigate to a screen */\n navigateToScreen: (screensetId: string, screenId: string) => void;\n /** Navigate to a screenset (uses default screen) */\n navigateToScreenset: (screensetId: string) => void;\n /** Current screenset ID */\n currentScreenset: string | null;\n /** Current screen ID */\n currentScreen: string | null;\n}\n\n/**\n * useScreenset Hook Return Type\n * Current screenset state.\n */\nexport interface UseScreensetReturn {\n /** Current screenset */\n screenset: ScreensetDefinition | undefined;\n /** Current screenset ID */\n screensetId: string | null;\n /** Current category */\n category: ScreensetCategory | null;\n}\n\n/**\n * usePopup Hook Return Type\n * Popup utilities.\n */\nexport interface UsePopupReturn {\n /** Show a popup */\n show: (config: { id: string; title?: string; content?: () => Promise<{ default: React.ComponentType }> }) => void;\n /** Hide current popup */\n hide: () => void;\n /** Hide all popups */\n hideAll: () => void;\n /** Whether any popup is open */\n isOpen: boolean;\n /** Current popup stack */\n stack: Array<{ id: string; title?: string }>;\n}\n\n/**\n * useOverlay Hook Return Type\n * Overlay utilities.\n */\nexport interface UseOverlayReturn {\n /** Show an overlay */\n show: (config: { id: string; content?: () => Promise<{ default: React.ComponentType }> }) => void;\n /** Hide current overlay */\n hide: () => void;\n /** Whether any overlay is open */\n isOpen: boolean;\n}\n\n// ============================================================================\n// App Router Props\n// ============================================================================\n\n/**\n * App Router Props\n * Props for the AppRouter component.\n */\nexport interface AppRouterProps {\n /** Fallback component while loading */\n fallback?: ReactNode;\n /** Error boundary fallback */\n errorFallback?: ReactNode | ((error: Error) => ReactNode);\n}\n\n// ============================================================================\n// Text Loader Props\n// ============================================================================\n\n/**\n * Text Loader Props\n * Props for TextLoader component that prevents flash of untranslated content.\n */\nexport interface TextLoaderProps {\n /** Child content to render when translations are loaded */\n children: ReactNode;\n /** Fallback while loading (alternative to skeleton) */\n fallback?: ReactNode;\n /**\n * Optional className for the skeleton loader\n * Use this to match the expected size of the text\n * @example \"h-8 w-48\" for a heading\n * @example \"h-4 w-32\" for a button label\n */\n skeletonClassName?: string;\n /** Optional className for the wrapper div */\n className?: string;\n /**\n * If true, skeleton inherits the text color instead of using bg-muted\n * Use this for buttons, menu items, and colored text\n * @default false\n */\n inheritColor?: boolean;\n}\n\n// ============================================================================\n// Component Types\n// ============================================================================\n\n/**\n * HAI3Provider Component Type\n */\nexport type HAI3ProviderComponent = React.FC<HAI3ProviderProps>;\n\n/**\n * AppRouter Component Type\n */\nexport type AppRouterComponent = React.FC<AppRouterProps>;\n\n/**\n * TextLoader Component Type\n */\nexport type TextLoaderComponent = React.FC<TextLoaderProps>;\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { HAI3Config, HAI3App, Language, RootState, LanguageMetadata, MenuItemConfig, ScreensetDefinition, ScreensetCategory } from '@hai3/framework';
|
|
3
|
+
export { HAI3App, HAI3Config, MenuItemConfig, ScreensetCategory, ScreensetDefinition } from '@hai3/framework';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @hai3/react - Type Definitions
|
|
7
|
+
*
|
|
8
|
+
* Core types for HAI3 React bindings.
|
|
9
|
+
* Provides type-safe hooks and components.
|
|
10
|
+
*
|
|
11
|
+
* Now using real imports from @hai3/framework since packages are built together.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type Selector<TResult, TState = RootState> = (state: TState) => TResult;
|
|
15
|
+
type TranslationParams = Record<string, string | number | boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* HAI3 Provider Props
|
|
18
|
+
* Props for the main HAI3Provider component.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <HAI3Provider config={{ devMode: true }}>
|
|
23
|
+
* <App />
|
|
24
|
+
* </HAI3Provider>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface HAI3ProviderProps {
|
|
28
|
+
/** Child components */
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
/** HAI3 configuration */
|
|
31
|
+
config?: HAI3Config;
|
|
32
|
+
/** Pre-built HAI3 app instance (optional) */
|
|
33
|
+
app?: HAI3App;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* useHAI3 Hook Return Type
|
|
37
|
+
* Returns the HAI3 app instance from context.
|
|
38
|
+
*/
|
|
39
|
+
type UseHAI3Return = HAI3App;
|
|
40
|
+
/**
|
|
41
|
+
* useAppSelector Hook
|
|
42
|
+
* Type-safe selector hook for Redux state.
|
|
43
|
+
*
|
|
44
|
+
* @template TResult - The result type of the selector
|
|
45
|
+
*/
|
|
46
|
+
type UseAppSelector = <TResult>(selector: Selector<TResult>) => TResult;
|
|
47
|
+
/**
|
|
48
|
+
* useAppDispatch Hook Return Type
|
|
49
|
+
* Returns the typed dispatch function.
|
|
50
|
+
*/
|
|
51
|
+
type UseAppDispatchReturn = (action: unknown) => unknown;
|
|
52
|
+
/**
|
|
53
|
+
* useTranslation Hook Return Type
|
|
54
|
+
* Translation utilities.
|
|
55
|
+
*/
|
|
56
|
+
interface UseTranslationReturn {
|
|
57
|
+
/** Translate a key */
|
|
58
|
+
t: (key: string, params?: TranslationParams) => string;
|
|
59
|
+
/** Current language */
|
|
60
|
+
language: Language | null;
|
|
61
|
+
/** Change language */
|
|
62
|
+
setLanguage: (language: Language) => Promise<void>;
|
|
63
|
+
/** Check if current language is RTL */
|
|
64
|
+
isRTL: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* useScreenTranslations Hook Return Type
|
|
68
|
+
* Screen-level translation loading state.
|
|
69
|
+
*/
|
|
70
|
+
interface UseScreenTranslationsReturn {
|
|
71
|
+
/** Whether translations are loaded */
|
|
72
|
+
isLoaded: boolean;
|
|
73
|
+
/** Loading error (if any) */
|
|
74
|
+
error: Error | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* useLanguage Hook Return Type
|
|
78
|
+
* Language selection utilities.
|
|
79
|
+
*/
|
|
80
|
+
interface UseLanguageReturn {
|
|
81
|
+
/** Current language */
|
|
82
|
+
current: Language | null;
|
|
83
|
+
/** All supported languages */
|
|
84
|
+
supported: LanguageMetadata[];
|
|
85
|
+
/** Change language */
|
|
86
|
+
setLanguage: (language: Language) => Promise<void>;
|
|
87
|
+
/** Check if current language is RTL */
|
|
88
|
+
isRTL: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* useTheme Hook Return Type
|
|
92
|
+
* Theme utilities.
|
|
93
|
+
*/
|
|
94
|
+
interface UseThemeReturn {
|
|
95
|
+
/** Current theme ID */
|
|
96
|
+
currentTheme: string | undefined;
|
|
97
|
+
/** All available themes */
|
|
98
|
+
themes: Array<{
|
|
99
|
+
id: string;
|
|
100
|
+
name: string;
|
|
101
|
+
}>;
|
|
102
|
+
/** Change theme */
|
|
103
|
+
setTheme: (themeId: string) => void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* useMenu Hook Return Type
|
|
107
|
+
* Menu state and actions.
|
|
108
|
+
*/
|
|
109
|
+
interface UseMenuReturn {
|
|
110
|
+
/** Menu items */
|
|
111
|
+
items: MenuItemConfig[];
|
|
112
|
+
/** Whether menu is collapsed */
|
|
113
|
+
collapsed: boolean;
|
|
114
|
+
/** Whether menu is visible */
|
|
115
|
+
visible: boolean;
|
|
116
|
+
/** Toggle menu collapse */
|
|
117
|
+
toggle: () => void;
|
|
118
|
+
/** Set collapsed state */
|
|
119
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* useScreen Hook Return Type
|
|
123
|
+
* Current screen state.
|
|
124
|
+
*/
|
|
125
|
+
interface UseScreenReturn {
|
|
126
|
+
/** Active screen ID */
|
|
127
|
+
activeScreen: string | null;
|
|
128
|
+
/** Whether screen is loading */
|
|
129
|
+
isLoading: boolean;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* useNavigation Hook Return Type
|
|
133
|
+
* Navigation utilities.
|
|
134
|
+
*/
|
|
135
|
+
interface UseNavigationReturn {
|
|
136
|
+
/** Navigate to a screen */
|
|
137
|
+
navigateToScreen: (screensetId: string, screenId: string) => void;
|
|
138
|
+
/** Navigate to a screenset (uses default screen) */
|
|
139
|
+
navigateToScreenset: (screensetId: string) => void;
|
|
140
|
+
/** Current screenset ID */
|
|
141
|
+
currentScreenset: string | null;
|
|
142
|
+
/** Current screen ID */
|
|
143
|
+
currentScreen: string | null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* useScreenset Hook Return Type
|
|
147
|
+
* Current screenset state.
|
|
148
|
+
*/
|
|
149
|
+
interface UseScreensetReturn {
|
|
150
|
+
/** Current screenset */
|
|
151
|
+
screenset: ScreensetDefinition | undefined;
|
|
152
|
+
/** Current screenset ID */
|
|
153
|
+
screensetId: string | null;
|
|
154
|
+
/** Current category */
|
|
155
|
+
category: ScreensetCategory | null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* usePopup Hook Return Type
|
|
159
|
+
* Popup utilities.
|
|
160
|
+
*/
|
|
161
|
+
interface UsePopupReturn {
|
|
162
|
+
/** Show a popup */
|
|
163
|
+
show: (config: {
|
|
164
|
+
id: string;
|
|
165
|
+
title?: string;
|
|
166
|
+
content?: () => Promise<{
|
|
167
|
+
default: React.ComponentType;
|
|
168
|
+
}>;
|
|
169
|
+
}) => void;
|
|
170
|
+
/** Hide current popup */
|
|
171
|
+
hide: () => void;
|
|
172
|
+
/** Hide all popups */
|
|
173
|
+
hideAll: () => void;
|
|
174
|
+
/** Whether any popup is open */
|
|
175
|
+
isOpen: boolean;
|
|
176
|
+
/** Current popup stack */
|
|
177
|
+
stack: Array<{
|
|
178
|
+
id: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
}>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* useOverlay Hook Return Type
|
|
184
|
+
* Overlay utilities.
|
|
185
|
+
*/
|
|
186
|
+
interface UseOverlayReturn {
|
|
187
|
+
/** Show an overlay */
|
|
188
|
+
show: (config: {
|
|
189
|
+
id: string;
|
|
190
|
+
content?: () => Promise<{
|
|
191
|
+
default: React.ComponentType;
|
|
192
|
+
}>;
|
|
193
|
+
}) => void;
|
|
194
|
+
/** Hide current overlay */
|
|
195
|
+
hide: () => void;
|
|
196
|
+
/** Whether any overlay is open */
|
|
197
|
+
isOpen: boolean;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* App Router Props
|
|
201
|
+
* Props for the AppRouter component.
|
|
202
|
+
*/
|
|
203
|
+
interface AppRouterProps {
|
|
204
|
+
/** Fallback component while loading */
|
|
205
|
+
fallback?: ReactNode;
|
|
206
|
+
/** Error boundary fallback */
|
|
207
|
+
errorFallback?: ReactNode | ((error: Error) => ReactNode);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Text Loader Props
|
|
211
|
+
* Props for TextLoader component that prevents flash of untranslated content.
|
|
212
|
+
*/
|
|
213
|
+
interface TextLoaderProps {
|
|
214
|
+
/** Child content to render when translations are loaded */
|
|
215
|
+
children: ReactNode;
|
|
216
|
+
/** Fallback while loading (alternative to skeleton) */
|
|
217
|
+
fallback?: ReactNode;
|
|
218
|
+
/**
|
|
219
|
+
* Optional className for the skeleton loader
|
|
220
|
+
* Use this to match the expected size of the text
|
|
221
|
+
* @example "h-8 w-48" for a heading
|
|
222
|
+
* @example "h-4 w-32" for a button label
|
|
223
|
+
*/
|
|
224
|
+
skeletonClassName?: string;
|
|
225
|
+
/** Optional className for the wrapper div */
|
|
226
|
+
className?: string;
|
|
227
|
+
/**
|
|
228
|
+
* If true, skeleton inherits the text color instead of using bg-muted
|
|
229
|
+
* Use this for buttons, menu items, and colored text
|
|
230
|
+
* @default false
|
|
231
|
+
*/
|
|
232
|
+
inheritColor?: boolean;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* HAI3Provider Component Type
|
|
236
|
+
*/
|
|
237
|
+
type HAI3ProviderComponent = React.FC<HAI3ProviderProps>;
|
|
238
|
+
/**
|
|
239
|
+
* AppRouter Component Type
|
|
240
|
+
*/
|
|
241
|
+
type AppRouterComponent = React.FC<AppRouterProps>;
|
|
242
|
+
/**
|
|
243
|
+
* TextLoader Component Type
|
|
244
|
+
*/
|
|
245
|
+
type TextLoaderComponent = React.FC<TextLoaderProps>;
|
|
246
|
+
|
|
247
|
+
export type { AppRouterComponent, AppRouterProps, HAI3ProviderComponent, HAI3ProviderProps, TextLoaderComponent, TextLoaderProps, UseAppDispatchReturn, UseAppSelector, UseHAI3Return, UseLanguageReturn, UseMenuReturn, UseNavigationReturn, UseOverlayReturn, UsePopupReturn, UseScreenReturn, UseScreenTranslationsReturn, UseScreensetReturn, UseThemeReturn, UseTranslationReturn };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { HAI3Config, HAI3App, Language, RootState, LanguageMetadata, MenuItemConfig, ScreensetDefinition, ScreensetCategory } from '@hai3/framework';
|
|
3
|
+
export { HAI3App, HAI3Config, MenuItemConfig, ScreensetCategory, ScreensetDefinition } from '@hai3/framework';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @hai3/react - Type Definitions
|
|
7
|
+
*
|
|
8
|
+
* Core types for HAI3 React bindings.
|
|
9
|
+
* Provides type-safe hooks and components.
|
|
10
|
+
*
|
|
11
|
+
* Now using real imports from @hai3/framework since packages are built together.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
type Selector<TResult, TState = RootState> = (state: TState) => TResult;
|
|
15
|
+
type TranslationParams = Record<string, string | number | boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* HAI3 Provider Props
|
|
18
|
+
* Props for the main HAI3Provider component.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <HAI3Provider config={{ devMode: true }}>
|
|
23
|
+
* <App />
|
|
24
|
+
* </HAI3Provider>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
interface HAI3ProviderProps {
|
|
28
|
+
/** Child components */
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
/** HAI3 configuration */
|
|
31
|
+
config?: HAI3Config;
|
|
32
|
+
/** Pre-built HAI3 app instance (optional) */
|
|
33
|
+
app?: HAI3App;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* useHAI3 Hook Return Type
|
|
37
|
+
* Returns the HAI3 app instance from context.
|
|
38
|
+
*/
|
|
39
|
+
type UseHAI3Return = HAI3App;
|
|
40
|
+
/**
|
|
41
|
+
* useAppSelector Hook
|
|
42
|
+
* Type-safe selector hook for Redux state.
|
|
43
|
+
*
|
|
44
|
+
* @template TResult - The result type of the selector
|
|
45
|
+
*/
|
|
46
|
+
type UseAppSelector = <TResult>(selector: Selector<TResult>) => TResult;
|
|
47
|
+
/**
|
|
48
|
+
* useAppDispatch Hook Return Type
|
|
49
|
+
* Returns the typed dispatch function.
|
|
50
|
+
*/
|
|
51
|
+
type UseAppDispatchReturn = (action: unknown) => unknown;
|
|
52
|
+
/**
|
|
53
|
+
* useTranslation Hook Return Type
|
|
54
|
+
* Translation utilities.
|
|
55
|
+
*/
|
|
56
|
+
interface UseTranslationReturn {
|
|
57
|
+
/** Translate a key */
|
|
58
|
+
t: (key: string, params?: TranslationParams) => string;
|
|
59
|
+
/** Current language */
|
|
60
|
+
language: Language | null;
|
|
61
|
+
/** Change language */
|
|
62
|
+
setLanguage: (language: Language) => Promise<void>;
|
|
63
|
+
/** Check if current language is RTL */
|
|
64
|
+
isRTL: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* useScreenTranslations Hook Return Type
|
|
68
|
+
* Screen-level translation loading state.
|
|
69
|
+
*/
|
|
70
|
+
interface UseScreenTranslationsReturn {
|
|
71
|
+
/** Whether translations are loaded */
|
|
72
|
+
isLoaded: boolean;
|
|
73
|
+
/** Loading error (if any) */
|
|
74
|
+
error: Error | null;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* useLanguage Hook Return Type
|
|
78
|
+
* Language selection utilities.
|
|
79
|
+
*/
|
|
80
|
+
interface UseLanguageReturn {
|
|
81
|
+
/** Current language */
|
|
82
|
+
current: Language | null;
|
|
83
|
+
/** All supported languages */
|
|
84
|
+
supported: LanguageMetadata[];
|
|
85
|
+
/** Change language */
|
|
86
|
+
setLanguage: (language: Language) => Promise<void>;
|
|
87
|
+
/** Check if current language is RTL */
|
|
88
|
+
isRTL: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* useTheme Hook Return Type
|
|
92
|
+
* Theme utilities.
|
|
93
|
+
*/
|
|
94
|
+
interface UseThemeReturn {
|
|
95
|
+
/** Current theme ID */
|
|
96
|
+
currentTheme: string | undefined;
|
|
97
|
+
/** All available themes */
|
|
98
|
+
themes: Array<{
|
|
99
|
+
id: string;
|
|
100
|
+
name: string;
|
|
101
|
+
}>;
|
|
102
|
+
/** Change theme */
|
|
103
|
+
setTheme: (themeId: string) => void;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* useMenu Hook Return Type
|
|
107
|
+
* Menu state and actions.
|
|
108
|
+
*/
|
|
109
|
+
interface UseMenuReturn {
|
|
110
|
+
/** Menu items */
|
|
111
|
+
items: MenuItemConfig[];
|
|
112
|
+
/** Whether menu is collapsed */
|
|
113
|
+
collapsed: boolean;
|
|
114
|
+
/** Whether menu is visible */
|
|
115
|
+
visible: boolean;
|
|
116
|
+
/** Toggle menu collapse */
|
|
117
|
+
toggle: () => void;
|
|
118
|
+
/** Set collapsed state */
|
|
119
|
+
setCollapsed: (collapsed: boolean) => void;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* useScreen Hook Return Type
|
|
123
|
+
* Current screen state.
|
|
124
|
+
*/
|
|
125
|
+
interface UseScreenReturn {
|
|
126
|
+
/** Active screen ID */
|
|
127
|
+
activeScreen: string | null;
|
|
128
|
+
/** Whether screen is loading */
|
|
129
|
+
isLoading: boolean;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* useNavigation Hook Return Type
|
|
133
|
+
* Navigation utilities.
|
|
134
|
+
*/
|
|
135
|
+
interface UseNavigationReturn {
|
|
136
|
+
/** Navigate to a screen */
|
|
137
|
+
navigateToScreen: (screensetId: string, screenId: string) => void;
|
|
138
|
+
/** Navigate to a screenset (uses default screen) */
|
|
139
|
+
navigateToScreenset: (screensetId: string) => void;
|
|
140
|
+
/** Current screenset ID */
|
|
141
|
+
currentScreenset: string | null;
|
|
142
|
+
/** Current screen ID */
|
|
143
|
+
currentScreen: string | null;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* useScreenset Hook Return Type
|
|
147
|
+
* Current screenset state.
|
|
148
|
+
*/
|
|
149
|
+
interface UseScreensetReturn {
|
|
150
|
+
/** Current screenset */
|
|
151
|
+
screenset: ScreensetDefinition | undefined;
|
|
152
|
+
/** Current screenset ID */
|
|
153
|
+
screensetId: string | null;
|
|
154
|
+
/** Current category */
|
|
155
|
+
category: ScreensetCategory | null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* usePopup Hook Return Type
|
|
159
|
+
* Popup utilities.
|
|
160
|
+
*/
|
|
161
|
+
interface UsePopupReturn {
|
|
162
|
+
/** Show a popup */
|
|
163
|
+
show: (config: {
|
|
164
|
+
id: string;
|
|
165
|
+
title?: string;
|
|
166
|
+
content?: () => Promise<{
|
|
167
|
+
default: React.ComponentType;
|
|
168
|
+
}>;
|
|
169
|
+
}) => void;
|
|
170
|
+
/** Hide current popup */
|
|
171
|
+
hide: () => void;
|
|
172
|
+
/** Hide all popups */
|
|
173
|
+
hideAll: () => void;
|
|
174
|
+
/** Whether any popup is open */
|
|
175
|
+
isOpen: boolean;
|
|
176
|
+
/** Current popup stack */
|
|
177
|
+
stack: Array<{
|
|
178
|
+
id: string;
|
|
179
|
+
title?: string;
|
|
180
|
+
}>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* useOverlay Hook Return Type
|
|
184
|
+
* Overlay utilities.
|
|
185
|
+
*/
|
|
186
|
+
interface UseOverlayReturn {
|
|
187
|
+
/** Show an overlay */
|
|
188
|
+
show: (config: {
|
|
189
|
+
id: string;
|
|
190
|
+
content?: () => Promise<{
|
|
191
|
+
default: React.ComponentType;
|
|
192
|
+
}>;
|
|
193
|
+
}) => void;
|
|
194
|
+
/** Hide current overlay */
|
|
195
|
+
hide: () => void;
|
|
196
|
+
/** Whether any overlay is open */
|
|
197
|
+
isOpen: boolean;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* App Router Props
|
|
201
|
+
* Props for the AppRouter component.
|
|
202
|
+
*/
|
|
203
|
+
interface AppRouterProps {
|
|
204
|
+
/** Fallback component while loading */
|
|
205
|
+
fallback?: ReactNode;
|
|
206
|
+
/** Error boundary fallback */
|
|
207
|
+
errorFallback?: ReactNode | ((error: Error) => ReactNode);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Text Loader Props
|
|
211
|
+
* Props for TextLoader component that prevents flash of untranslated content.
|
|
212
|
+
*/
|
|
213
|
+
interface TextLoaderProps {
|
|
214
|
+
/** Child content to render when translations are loaded */
|
|
215
|
+
children: ReactNode;
|
|
216
|
+
/** Fallback while loading (alternative to skeleton) */
|
|
217
|
+
fallback?: ReactNode;
|
|
218
|
+
/**
|
|
219
|
+
* Optional className for the skeleton loader
|
|
220
|
+
* Use this to match the expected size of the text
|
|
221
|
+
* @example "h-8 w-48" for a heading
|
|
222
|
+
* @example "h-4 w-32" for a button label
|
|
223
|
+
*/
|
|
224
|
+
skeletonClassName?: string;
|
|
225
|
+
/** Optional className for the wrapper div */
|
|
226
|
+
className?: string;
|
|
227
|
+
/**
|
|
228
|
+
* If true, skeleton inherits the text color instead of using bg-muted
|
|
229
|
+
* Use this for buttons, menu items, and colored text
|
|
230
|
+
* @default false
|
|
231
|
+
*/
|
|
232
|
+
inheritColor?: boolean;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* HAI3Provider Component Type
|
|
236
|
+
*/
|
|
237
|
+
type HAI3ProviderComponent = React.FC<HAI3ProviderProps>;
|
|
238
|
+
/**
|
|
239
|
+
* AppRouter Component Type
|
|
240
|
+
*/
|
|
241
|
+
type AppRouterComponent = React.FC<AppRouterProps>;
|
|
242
|
+
/**
|
|
243
|
+
* TextLoader Component Type
|
|
244
|
+
*/
|
|
245
|
+
type TextLoaderComponent = React.FC<TextLoaderProps>;
|
|
246
|
+
|
|
247
|
+
export type { AppRouterComponent, AppRouterProps, HAI3ProviderComponent, HAI3ProviderProps, TextLoaderComponent, TextLoaderProps, UseAppDispatchReturn, UseAppSelector, UseHAI3Return, UseLanguageReturn, UseMenuReturn, UseNavigationReturn, UseOverlayReturn, UsePopupReturn, UseScreenReturn, UseScreenTranslationsReturn, UseScreensetReturn, UseThemeReturn, UseTranslationReturn };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/llms.txt
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @hai3/react
|
|
2
|
+
|
|
3
|
+
> React bindings, hooks, and components for HAI3 SDK. Provides type-safe integration with React applications.
|
|
4
|
+
|
|
5
|
+
Part of the HAI3 React Layer (L3) - depends on @hai3/framework. Peer dependency on react and react-dom.
|
|
6
|
+
|
|
7
|
+
## Core API
|
|
8
|
+
|
|
9
|
+
- [HAI3Provider](https://hai3.dev/docs/react/provider): Root context provider
|
|
10
|
+
- [AppRouter](https://hai3.dev/docs/react/router): Screen rendering with lazy loading
|
|
11
|
+
- [TextLoader](https://hai3.dev/docs/react/textloader): Prevents flash of untranslated content
|
|
12
|
+
|
|
13
|
+
## Hooks
|
|
14
|
+
|
|
15
|
+
| Hook | Purpose |
|
|
16
|
+
|------|---------|
|
|
17
|
+
| `useHAI3()` | Access app instance |
|
|
18
|
+
| `useAppDispatch()` | Type-safe dispatch |
|
|
19
|
+
| `useAppSelector()` | Type-safe selector |
|
|
20
|
+
| `useTranslation()` | Translation utilities (t, language, setLanguage, isRTL) |
|
|
21
|
+
| `useScreenTranslations()` | Lazy load screen translations |
|
|
22
|
+
| `useNavigation()` | Navigate between screens |
|
|
23
|
+
| `useTheme()` | Theme utilities (currentTheme, themes, setTheme) |
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { HAI3Provider, AppRouter, useTranslation, useNavigation } from '@hai3/react';
|
|
29
|
+
|
|
30
|
+
// Wrap app with provider
|
|
31
|
+
function App() {
|
|
32
|
+
return (
|
|
33
|
+
<HAI3Provider>
|
|
34
|
+
<Layout>
|
|
35
|
+
<AppRouter fallback={<Loading />} />
|
|
36
|
+
</Layout>
|
|
37
|
+
</HAI3Provider>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Use hooks in components
|
|
42
|
+
function MyComponent() {
|
|
43
|
+
const { t, isRTL } = useTranslation();
|
|
44
|
+
const { navigateToScreen } = useNavigation();
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div dir={isRTL ? 'rtl' : 'ltr'}>
|
|
48
|
+
<h1>{t('common:title')}</h1>
|
|
49
|
+
<button onClick={() => navigateToScreen('demo', 'home')}>
|
|
50
|
+
Go Home
|
|
51
|
+
</button>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Optional
|
|
58
|
+
|
|
59
|
+
- [Screen Translations](https://hai3.dev/docs/react/translations): Per-screen lazy loading
|
|
60
|
+
- [Custom Hooks](https://hai3.dev/docs/react/hooks): Building on HAI3 hooks
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hai3/react",
|
|
3
|
+
"version": "0.2.0-alpha.0",
|
|
4
|
+
"description": "React bindings and hooks for HAI3 framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./types": {
|
|
16
|
+
"types": "./dist/types.d.ts",
|
|
17
|
+
"import": "./dist/types.js",
|
|
18
|
+
"require": "./dist/types.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"CLAUDE.md",
|
|
24
|
+
"llms.txt",
|
|
25
|
+
"commands"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup",
|
|
29
|
+
"type-check": "tsc --noEmit"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.0.0",
|
|
34
|
+
"typescript": "^5.4.2",
|
|
35
|
+
"react": "^18.3.1",
|
|
36
|
+
"@types/react": "^18.3.3",
|
|
37
|
+
"react-redux": "^9.1.0",
|
|
38
|
+
"@types/react-redux": "^7.1.33"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@hai3/framework": "*",
|
|
42
|
+
"react": ">=18.0.0",
|
|
43
|
+
"react-redux": ">=8.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependenciesMeta": {
|
|
46
|
+
"@hai3/framework": { "optional": false },
|
|
47
|
+
"react": { "optional": false },
|
|
48
|
+
"react-redux": { "optional": false }
|
|
49
|
+
},
|
|
50
|
+
"keywords": [
|
|
51
|
+
"hai3",
|
|
52
|
+
"react",
|
|
53
|
+
"hooks",
|
|
54
|
+
"provider",
|
|
55
|
+
"typescript"
|
|
56
|
+
],
|
|
57
|
+
"author": "HAI3",
|
|
58
|
+
"license": "Apache-2.0"
|
|
59
|
+
}
|