@gears-frontx/react 0.1.0 → 0.2.0-alpha.2

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.
@@ -1,166 +0,0 @@
1
- <!-- @standalone -->
2
- # hai3:new-mfe - Create New Microfrontend Package
3
-
4
- ## PREREQUISITES (CRITICAL - STOP IF FAILED)
5
-
6
- 1. MFE must be associated with a screenset
7
- 2. Screenset must exist (run `hai3-new-screenset` first if needed)
8
- 3. Vite and Module Federation must be configured
9
-
10
- ## QUICK START
11
-
12
- For a screenset named `{screensetName}` with a new MFE:
13
-
14
- ```bash
15
- # 1. Create the MFE package in src/mfe_packages/{screensetName}-mfe/
16
- cp -r packages/cli/template-sources/mfe-package/ src/mfe_packages/{screensetName}-mfe/
17
-
18
- # 2. Update variables in package.json and vite.config.ts:
19
- # - Replace {{mfeName}} with your screenset name (camelCase)
20
- # - Replace {{port}} with available port (3001, 3010, 3020, etc)
21
- # - IMPORTANT: set preview script to "vite preview --port {{port}}"
22
-
23
- # 3. Install dependencies
24
- cd src/mfe_packages/{screensetName}-mfe
25
- npm install
26
-
27
- # 4. Create src/lifecycle.tsx that extends ThemeAwareReactLifecycle
28
-
29
- # 5. Regenerate MFE manifests so bootstrap.ts picks up the new package
30
- npm run generate:mfe-manifests
31
- ```
32
-
33
- ## CONFIGURATION REQUIREMENTS
34
-
35
- ✅ **Correct preview script** (required for port auto-discovery):
36
- ```json
37
- "preview": "vite preview --port {{port}}"
38
- ```
39
-
40
- ✅ **Correct dev script** (for hot reload):
41
- ```json
42
- "dev": "vite --port {{port}}"
43
- ```
44
-
45
- ❌ **WRONG** (don't use this for dev):
46
- ```json
47
- "dev": "vite build && vite preview --port {{port}}"
48
- ```
49
-
50
- ## PORT ALLOCATION
51
-
52
- Reserve ports for MFE packages:
53
- - **3001**: demo-mfe
54
- - **3010+**: (next available: 3010, 3020, 3030, ...)
55
- - **5173**: Main app
56
-
57
- ## LIFECYCLE TEMPLATE
58
-
59
- Create `src/lifecycle.tsx`:
60
-
61
- ```typescript
62
- import React from 'react';
63
- import type { ChildMfeBridge } from '@gears-frontx/react';
64
- import { ThemeAwareReactLifecycle } from '@gears-frontx/screensets/mfe/handler';
65
- import { YourScreen } from './screens/YourScreen';
66
-
67
- class Lifecycle extends ThemeAwareReactLifecycle {
68
- constructor() {
69
- super({
70
- name: '{screensetName}',
71
- version: '1.0.0',
72
- });
73
- }
74
-
75
- async mount(shadowRoot: ShadowRoot, bridge: ChildMfeBridge) {
76
- const div = document.createElement('div');
77
- shadowRoot.appendChild(div);
78
-
79
- const style = document.createElement('style');
80
- style.textContent = tailwindStyles;
81
- shadowRoot.appendChild(style);
82
-
83
- // Render component
84
- const root = ReactDOM.createRoot(div);
85
- root.render(<YourScreen bridge={bridge} />);
86
-
87
- return { root, div };
88
- }
89
- }
90
-
91
- export default new Lifecycle();
92
- ```
93
-
94
- ## dev:all INTEGRATION (AUTOMATIC)
95
-
96
- After creating the MFE and running `npm run generate:mfe-manifests`, the `dev:all`
97
- script auto-discovers your new package — no manual configuration needed.
98
-
99
- `dev-all.ts` scans `src/mfe_packages/*/package.json` and reads the port from the
100
- `preview` (or `dev`) script using `--port NNNN`. The new MFE will automatically
101
- appear in the next `npm run dev:all` run.
102
-
103
- ## VALIDATION
104
-
105
- After creation:
106
-
107
- ```bash
108
- # Regenerate manifests (required after adding new MFE)
109
- npm run generate:mfe-manifests
110
-
111
- # Validate TypeScript
112
- npm run type-check
113
-
114
- # Check architecture compliance
115
- npm run arch:check
116
-
117
- # Run the dev server (picks up new MFE automatically)
118
- npm run dev:all
119
-
120
- # Verify MFE loads at http://localhost:5173
121
- # Open Studio Overlay (Ctrl+`) and check screenset
122
- ```
123
-
124
- ## TROUBLESHOOTING
125
-
126
- ### Issue: MFE not appearing in screenset selector
127
- - Run `npm run generate:mfe-manifests` to regenerate manifests
128
- - Check mfe.json manifest is properly exported
129
- - Verify extensions are registered in manifest
130
- - Check browser console for errors
131
-
132
- ### Issue: dev:all not picking up MFE port
133
- - Verify `preview` script has `--port NNNN` (e.g., `"vite preview --port 3010"`)
134
- - Check port is not in use (`lsof -i :3010`)
135
- - Restart dev server
136
-
137
- ### Issue: Hot reload not working
138
- - Verify dev script uses `vite --port` (not `vite build && vite preview`)
139
- - Check port is not in use
140
- - Restart dev server
141
-
142
- ### Issue: Redux/useSelector errors
143
- - MFE must use mock data (no Redux Provider in isolation)
144
- - Use `useState` for local state management
145
- - Do not import Redux hooks (@gears-frontx/react)
146
-
147
- ## BEST PRACTICES
148
-
149
- ✅ **DO:**
150
- - Set `preview` script with `--port NNNN` for port auto-discovery
151
- - Use mock data with useState for UI-only MFEs
152
- - Keep MFE logic isolated and simple
153
- - Use local components (e.g. components/ui/)
154
- - Run `npm run generate:mfe-manifests` after creating the MFE
155
-
156
- ❌ **DON'T:**
157
- - Import Redux hooks directly
158
- - Use vite build && vite preview in dev mode
159
- - Create complex state management in MFE
160
- - Hardcode ports without updating package.json preview script
161
-
162
- ---
163
-
164
- See also:
165
- - `/packages/cli/template-sources/mfe-package/` for templates
166
- - `hai3-new-screenset.md` for screenset creation
@@ -1,39 +0,0 @@
1
- <!-- @standalone -->
2
- # hai3:new-screen - Add New Screen
3
-
4
- ## AI WORKFLOW (REQUIRED)
5
- 1) Read .ai/targets/SCREENSETS.md and .ai/targets/EVENTS.md before starting.
6
- 2) Gather requirements from user (including UI sections).
7
- 3) Implement.
8
-
9
- ## GATHER REQUIREMENTS
10
- Ask user for:
11
- - Screenset path (e.g., src/screensets/chat).
12
- - Screen name (camelCase).
13
- - UI sections (e.g., "header, form, data table").
14
- - Add to menu? (Y/N)
15
-
16
- ## STEP 1: Implementation
17
- 1) Add screen ID to ids.ts.
18
- 2) Create components BEFORE screen file per Component Plan.
19
- 3) Create screen following data flow rules from .ai/targets/EVENTS.md:
20
- - Use actions to trigger state changes
21
- - FORBIDDEN: Direct slice dispatch from screen
22
- 4) Add i18n with useScreenTranslations(). Export default.
23
- 5) Add to menu if requested.
24
- 6) Validate: `npm run type-check && npm run lint`.
25
- 7) Test via Chrome DevTools MCP (REQUIRED):
26
- - Navigate to new screen
27
- - Verify screen renders without console errors
28
- - Test UI interactions and data flow
29
- - Verify translations load correctly
30
- - STOP if MCP connection fails
31
-
32
- ## COMPONENT PLAN
33
- - REQUIRED: Use local components (e.g. `components/ui/`) — no shared UI kit package.
34
- - components/ui/: base UI primitives (shadcn components or custom)
35
- - screens/{screen}/components/: screen-specific components
36
-
37
- ## DATA FLOW
38
- - Uses existing screenset events/slices per EVENTS.md
39
- - Screen dispatches actions, never direct slice updates
@@ -1,47 +0,0 @@
1
- <!-- @standalone -->
2
- # hai3:new-screenset - Create New Screenset
3
-
4
- ## PREREQUISITES (CRITICAL - STOP IF FAILED)
5
- Run `hai3 --version`.
6
- STOP: If fails, tell user to install.
7
- FORBIDDEN: Creating screenset manually or by copying peers.
8
-
9
- ## AI WORKFLOW (REQUIRED)
10
- 1) Check prerequisites above.
11
- 2) Read .ai/targets/SCREENSETS.md and .ai/targets/EVENTS.md before starting.
12
- 3) Gather requirements from user (including UI sections).
13
- 4) Implement.
14
-
15
- ## GATHER REQUIREMENTS
16
- Ask user for:
17
- - Screenset name (camelCase).
18
- - Category: Drafts | Mockups | Production.
19
- - Initial screens.
20
- - UI sections per screen (e.g., "stats cards, charts, activity feed").
21
-
22
- ## STEP 1: Implementation
23
- 1) Create screenset via `hai3 screenset create` (REQUIRED).
24
- 2) Create components BEFORE screen file per Component Plan.
25
- 3) Implement data flow per .ai/targets/EVENTS.md:
26
- - Actions emit events via eventBus.emit()
27
- - Effects subscribe and update slices
28
- - FORBIDDEN: Direct slice dispatch from components
29
- 4) Add API service with mocks.
30
- 5) Validate: `npm run type-check && npm run arch:check && npm run lint`.
31
- 6) Test via Chrome DevTools MCP (REQUIRED):
32
- - Navigate to new screenset
33
- - Verify screen renders without console errors
34
- - Test user interactions trigger correct events
35
- - Verify state updates via Redux DevTools
36
- - STOP if MCP connection fails
37
-
38
- ## COMPONENT PLAN
39
- - REQUIRED: Use local components (e.g. `components/ui/`) — no shared UI kit package.
40
- - components/ui/: base UI primitives (shadcn components or custom)
41
- - components/: multi-screen shared components
42
- - screens/{screen}/components/: screen-specific components
43
-
44
- ## DATA FLOW
45
- - Events: {domain events per EVENTS.md}
46
- - State: slices/, events/, effects/, actions/
47
- - API: api/{Name}ApiService.ts with mocks
@@ -1,136 +0,0 @@
1
- import * as React from 'react';
2
- import { ReactNode } from 'react';
3
- import { ChildMfeBridge, HAI3Config, HAI3App, RootState, Formatters, Language } from '@gears-frontx/framework';
4
-
5
- /**
6
- * MFE Context Value
7
- * Contains bridge and metadata about the MFE instance.
8
- */
9
- interface MfeContextValue {
10
- /** Child bridge for communication with host */
11
- bridge: ChildMfeBridge;
12
- /** Extension ID */
13
- extensionId: string;
14
- /** Domain ID where MFE is mounted */
15
- domainId: string;
16
- }
17
- /**
18
- * MFE Context
19
- * Holds the MFE bridge and metadata for child components.
20
- */
21
- declare const MfeContext: React.Context<MfeContextValue | null>;
22
- /**
23
- * Use the MFE context.
24
- * Throws if used outside of MFE context.
25
- *
26
- * @returns The MFE context value
27
- */
28
- declare function useMfeContext(): MfeContextValue;
29
-
30
- /**
31
- * @gears-frontx/react - Type Definitions
32
- *
33
- * Core types for HAI3 React bindings.
34
- * Provides type-safe hooks and components.
35
- *
36
- * Now using real imports from @gears-frontx/framework since packages are built together.
37
- */
38
-
39
- type Selector<TResult, TState = RootState> = (state: TState) => TResult;
40
- type TranslationParams = Record<string, string | number | boolean>;
41
- /**
42
- * HAI3 Provider Props
43
- * Props for the main HAI3Provider component.
44
- *
45
- * @example
46
- * ```tsx
47
- * <HAI3Provider config={{ devMode: true }}>
48
- * <App />
49
- * </HAI3Provider>
50
- *
51
- * // With pre-built app
52
- * const app = createHAI3().use(screensets()).use(microfrontends()).build();
53
- * <HAI3Provider app={app}>
54
- * <App />
55
- * </HAI3Provider>
56
- *
57
- * // With MFE bridge (for MFE components)
58
- * <HAI3Provider mfeBridge={{ bridge, extensionId, domainId }}>
59
- * <MyMfeApp />
60
- * </HAI3Provider>
61
- * ```
62
- */
63
- interface HAI3ProviderProps {
64
- /** Child components */
65
- children: ReactNode;
66
- /** HAI3 configuration */
67
- config?: HAI3Config;
68
- /** Pre-built HAI3 app instance (optional) */
69
- app?: HAI3App;
70
- /** MFE bridge context (for MFE components) */
71
- mfeBridge?: MfeContextValue;
72
- }
73
- /**
74
- * useHAI3 Hook Return Type
75
- * Returns the HAI3 app instance from context.
76
- */
77
- type UseHAI3Return = HAI3App;
78
- /**
79
- * useAppSelector Hook
80
- * Type-safe selector hook for Redux state.
81
- *
82
- * @template TResult - The result type of the selector
83
- */
84
- type UseAppSelector = <TResult>(selector: Selector<TResult>) => TResult;
85
- /**
86
- * useAppDispatch Hook Return Type
87
- * Returns the typed dispatch function.
88
- */
89
- type UseAppDispatchReturn = (action: unknown) => unknown;
90
- /**
91
- * useTranslation Hook Return Type
92
- * Translation utilities.
93
- */
94
- interface UseTranslationReturn {
95
- /** Translate a key */
96
- t: (key: string, params?: TranslationParams) => string;
97
- /** Current language */
98
- language: Language | null;
99
- /** Change language */
100
- setLanguage: (language: Language) => void;
101
- /** Check if current language is RTL */
102
- isRTL: boolean;
103
- }
104
- /**
105
- * useScreenTranslations Hook Return Type
106
- * Screen-level translation loading state.
107
- */
108
- interface UseScreenTranslationsReturn {
109
- /** Whether translations are loaded */
110
- isLoaded: boolean;
111
- /** Loading error (if any) */
112
- error: Error | null;
113
- }
114
- /**
115
- * useTheme Hook Return Type
116
- * Theme utilities.
117
- */
118
- interface UseThemeReturn {
119
- /** Current theme ID */
120
- currentTheme: string | undefined;
121
- /** All available themes */
122
- themes: Array<{
123
- id: string;
124
- name: string;
125
- }>;
126
- /** Change theme */
127
- setTheme: (themeId: string) => void;
128
- }
129
- /**
130
- * useFormatters Hook Return Type
131
- * Locale-aware formatters (locale from i18nRegistry.getLanguage()).
132
- * References @gears-frontx/i18n Formatters so signatures stay in sync.
133
- */
134
- type UseFormattersReturn = Formatters;
135
-
136
- export { type HAI3ProviderProps as H, type MfeContextValue as M, type UseTranslationReturn as U, type UseScreenTranslationsReturn as a, type UseFormattersReturn as b, type UseThemeReturn as c, MfeContext as d, type UseAppDispatchReturn as e, type UseAppSelector as f, type UseHAI3Return as g, useMfeContext as u };
@@ -1,136 +0,0 @@
1
- import * as React from 'react';
2
- import { ReactNode } from 'react';
3
- import { ChildMfeBridge, HAI3Config, HAI3App, RootState, Formatters, Language } from '@gears-frontx/framework';
4
-
5
- /**
6
- * MFE Context Value
7
- * Contains bridge and metadata about the MFE instance.
8
- */
9
- interface MfeContextValue {
10
- /** Child bridge for communication with host */
11
- bridge: ChildMfeBridge;
12
- /** Extension ID */
13
- extensionId: string;
14
- /** Domain ID where MFE is mounted */
15
- domainId: string;
16
- }
17
- /**
18
- * MFE Context
19
- * Holds the MFE bridge and metadata for child components.
20
- */
21
- declare const MfeContext: React.Context<MfeContextValue | null>;
22
- /**
23
- * Use the MFE context.
24
- * Throws if used outside of MFE context.
25
- *
26
- * @returns The MFE context value
27
- */
28
- declare function useMfeContext(): MfeContextValue;
29
-
30
- /**
31
- * @gears-frontx/react - Type Definitions
32
- *
33
- * Core types for HAI3 React bindings.
34
- * Provides type-safe hooks and components.
35
- *
36
- * Now using real imports from @gears-frontx/framework since packages are built together.
37
- */
38
-
39
- type Selector<TResult, TState = RootState> = (state: TState) => TResult;
40
- type TranslationParams = Record<string, string | number | boolean>;
41
- /**
42
- * HAI3 Provider Props
43
- * Props for the main HAI3Provider component.
44
- *
45
- * @example
46
- * ```tsx
47
- * <HAI3Provider config={{ devMode: true }}>
48
- * <App />
49
- * </HAI3Provider>
50
- *
51
- * // With pre-built app
52
- * const app = createHAI3().use(screensets()).use(microfrontends()).build();
53
- * <HAI3Provider app={app}>
54
- * <App />
55
- * </HAI3Provider>
56
- *
57
- * // With MFE bridge (for MFE components)
58
- * <HAI3Provider mfeBridge={{ bridge, extensionId, domainId }}>
59
- * <MyMfeApp />
60
- * </HAI3Provider>
61
- * ```
62
- */
63
- interface HAI3ProviderProps {
64
- /** Child components */
65
- children: ReactNode;
66
- /** HAI3 configuration */
67
- config?: HAI3Config;
68
- /** Pre-built HAI3 app instance (optional) */
69
- app?: HAI3App;
70
- /** MFE bridge context (for MFE components) */
71
- mfeBridge?: MfeContextValue;
72
- }
73
- /**
74
- * useHAI3 Hook Return Type
75
- * Returns the HAI3 app instance from context.
76
- */
77
- type UseHAI3Return = HAI3App;
78
- /**
79
- * useAppSelector Hook
80
- * Type-safe selector hook for Redux state.
81
- *
82
- * @template TResult - The result type of the selector
83
- */
84
- type UseAppSelector = <TResult>(selector: Selector<TResult>) => TResult;
85
- /**
86
- * useAppDispatch Hook Return Type
87
- * Returns the typed dispatch function.
88
- */
89
- type UseAppDispatchReturn = (action: unknown) => unknown;
90
- /**
91
- * useTranslation Hook Return Type
92
- * Translation utilities.
93
- */
94
- interface UseTranslationReturn {
95
- /** Translate a key */
96
- t: (key: string, params?: TranslationParams) => string;
97
- /** Current language */
98
- language: Language | null;
99
- /** Change language */
100
- setLanguage: (language: Language) => void;
101
- /** Check if current language is RTL */
102
- isRTL: boolean;
103
- }
104
- /**
105
- * useScreenTranslations Hook Return Type
106
- * Screen-level translation loading state.
107
- */
108
- interface UseScreenTranslationsReturn {
109
- /** Whether translations are loaded */
110
- isLoaded: boolean;
111
- /** Loading error (if any) */
112
- error: Error | null;
113
- }
114
- /**
115
- * useTheme Hook Return Type
116
- * Theme utilities.
117
- */
118
- interface UseThemeReturn {
119
- /** Current theme ID */
120
- currentTheme: string | undefined;
121
- /** All available themes */
122
- themes: Array<{
123
- id: string;
124
- name: string;
125
- }>;
126
- /** Change theme */
127
- setTheme: (themeId: string) => void;
128
- }
129
- /**
130
- * useFormatters Hook Return Type
131
- * Locale-aware formatters (locale from i18nRegistry.getLanguage()).
132
- * References @gears-frontx/i18n Formatters so signatures stay in sync.
133
- */
134
- type UseFormattersReturn = Formatters;
135
-
136
- export { type HAI3ProviderProps as H, type MfeContextValue as M, type UseTranslationReturn as U, type UseScreenTranslationsReturn as a, type UseFormattersReturn as b, type UseThemeReturn as c, MfeContext as d, type UseAppDispatchReturn as e, type UseAppSelector as f, type UseHAI3Return as g, useMfeContext as u };