@hai3/framework 0.2.0-alpha.4 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @hai3/framework
2
2
 
3
- Plugin-based application framework for HAI3 applications. Orchestrates SDK packages into cohesive applications.
3
+ Plugin-based application framework for HAI3 applications. Orchestrates SDK packages into cohesive applications with MFE (Microfrontend) support.
4
4
 
5
5
  ## Framework Layer
6
6
 
@@ -15,13 +15,13 @@ This package is part of the **Framework Layer (L2)** - it depends on SDK package
15
15
  Build applications by composing plugins:
16
16
 
17
17
  ```typescript
18
- import { createHAI3, screensets, themes, layout, navigation, i18n } from '@hai3/framework';
18
+ import { createHAI3, screensets, themes, layout, microfrontends, i18n } from '@hai3/framework';
19
19
 
20
20
  const app = createHAI3()
21
21
  .use(screensets())
22
22
  .use(themes())
23
23
  .use(layout())
24
- .use(navigation())
24
+ .use(microfrontends())
25
25
  .use(i18n())
26
26
  .build();
27
27
  ```
@@ -33,7 +33,7 @@ Pre-configured plugin combinations:
33
33
  ```typescript
34
34
  import { createHAI3App, presets } from '@hai3/framework';
35
35
 
36
- // Full preset (default) - all plugins
36
+ // Full preset (default) - all plugins including MFE support
37
37
  const fullApp = createHAI3App();
38
38
 
39
39
  // Or explicitly use presets
@@ -50,11 +50,10 @@ const headlessApp = createHAI3()
50
50
 
51
51
  | Plugin | Provides | Dependencies |
52
52
  |--------|----------|--------------|
53
- | `screensets()` | screensetRegistry, screenSlice | - |
53
+ | `screensets()` | screensetsRegistry (MFE-enabled), layout domain slices | - |
54
54
  | `themes()` | themeRegistry, changeTheme action | - |
55
- | `layout()` | header, footer, menu, sidebar, popup, overlay slices | screensets |
56
- | `navigation()` | navigateToScreen, navigateToScreenset actions | screensets, routing |
57
- | `routing()` | routeRegistry, URL sync | screensets |
55
+ | `layout()` | header, footer, menu, sidebar, popup, overlay state | screensets |
56
+ | `microfrontends()` | MFE actions, selectors, domain constants | screensets |
58
57
  | `i18n()` | i18nRegistry, setLanguage action | - |
59
58
  | `effects()` | Core effect coordination | - |
60
59
  | `mock()` | mockSlice, toggleMockMode action | effects |
@@ -89,23 +88,34 @@ Services register mock plugins using `registerPlugin()` in their constructor. Th
89
88
 
90
89
  ### Built Application
91
90
 
92
- After calling `.build()`, access registries and actions:
91
+ After calling `.build()`, access registries, actions, and the MFE-enabled screensetsRegistry:
93
92
 
94
93
  ```typescript
95
94
  const app = createHAI3App();
96
95
 
97
- // Access registries
98
- app.screensetRegistry.getAll();
96
+ // Access MFE-enabled registry
97
+ app.screensetsRegistry.registerDomain(screenDomain, containerProvider);
98
+ await app.screensetsRegistry.registerExtension(homeExtension);
99
+ await app.screensetsRegistry.executeActionsChain({
100
+ action: { type: HAI3_ACTION_MOUNT_EXT, target: 'screen', payload: { extensionId: 'home' } }
101
+ });
102
+
103
+ // Access other registries
99
104
  app.themeRegistry.getCurrent();
100
- app.routeRegistry.hasScreen('demo', 'home');
101
105
  app.i18nRegistry.t('common:title');
102
106
 
103
107
  // Access store
104
108
  const state = app.store.getState();
105
109
  app.store.dispatch(someAction);
106
110
 
107
- // Access actions
108
- app.actions.navigateToScreen({ screensetId: 'demo', screenId: 'home' });
111
+ // Access MFE actions
112
+ app.actions.loadExtension({ extensionId: 'home' });
113
+ app.actions.mountExtension({ extensionId: 'home', domainId: 'screen', container });
114
+ app.actions.unmountExtension({ extensionId: 'home', domainId: 'screen' });
115
+ app.actions.registerExtension(homeExtension);
116
+ app.actions.unregisterExtension({ extensionId: 'home' });
117
+
118
+ // Access theme and i18n actions
109
119
  app.actions.changeTheme({ themeId: 'dark' });
110
120
  app.actions.setLanguage({ language: 'es' });
111
121
 
@@ -113,6 +123,108 @@ app.actions.setLanguage({ language: 'es' });
113
123
  app.destroy();
114
124
  ```
115
125
 
126
+ ## MFE Plugin
127
+
128
+ The `microfrontends()` plugin provides MFE support:
129
+
130
+ ### MFE Actions
131
+
132
+ ```typescript
133
+ import {
134
+ loadExtension,
135
+ mountExtension,
136
+ unmountExtension,
137
+ registerExtension,
138
+ unregisterExtension,
139
+ } from '@hai3/framework';
140
+
141
+ // Load extension code
142
+ await loadExtension({ extensionId: 'home' });
143
+
144
+ // Mount extension into domain
145
+ await mountExtension({
146
+ extensionId: 'home',
147
+ domainId: 'screen',
148
+ container: document.getElementById('screen-container')!,
149
+ });
150
+
151
+ // Unmount extension from domain
152
+ await unmountExtension({ extensionId: 'home', domainId: 'screen' });
153
+
154
+ // Register/unregister extensions dynamically
155
+ registerExtension(homeExtension);
156
+ unregisterExtension({ extensionId: 'home' });
157
+ ```
158
+
159
+ ### MFE Selectors
160
+
161
+ ```typescript
162
+ import {
163
+ selectExtensionState,
164
+ selectRegisteredExtensions,
165
+ selectExtensionError,
166
+ } from '@hai3/framework';
167
+
168
+ // Get extension state
169
+ const extensionState = selectExtensionState(state, 'home');
170
+
171
+ // Get all registered extensions
172
+ const extensions = selectRegisteredExtensions(state);
173
+
174
+ // Get extension error
175
+ const error = selectExtensionError(state, 'home');
176
+ ```
177
+
178
+ ### Domain Constants
179
+
180
+ ```typescript
181
+ import {
182
+ HAI3_SCREEN_DOMAIN,
183
+ HAI3_SIDEBAR_DOMAIN,
184
+ HAI3_POPUP_DOMAIN,
185
+ HAI3_OVERLAY_DOMAIN,
186
+ screenDomain,
187
+ sidebarDomain,
188
+ popupDomain,
189
+ overlayDomain,
190
+ } from '@hai3/framework';
191
+
192
+ // String constants (GTS instance IDs)
193
+ HAI3_SCREEN_DOMAIN // 'gts.hai3.mfes.ext.domain.v1~hai3.screensets.layout.screen.v1'
194
+ HAI3_SIDEBAR_DOMAIN // 'gts.hai3.mfes.ext.domain.v1~hai3.screensets.layout.sidebar.v1'
195
+ HAI3_POPUP_DOMAIN // 'gts.hai3.mfes.ext.domain.v1~hai3.screensets.layout.popup.v1'
196
+ HAI3_OVERLAY_DOMAIN // 'gts.hai3.mfes.ext.domain.v1~hai3.screensets.layout.overlay.v1'
197
+
198
+ // Domain objects (ExtensionDomain interface: id, actions, extensionsActions,
199
+ // sharedProperties, defaultActionTimeout, lifecycleStages, extensionsLifecycleStages,
200
+ // extensionsTypeId, lifecycle)
201
+ screenDomain // screen: swap semantics (load_ext, mount_ext only, NO unmount_ext)
202
+ sidebarDomain // sidebar: toggle semantics (load_ext, mount_ext, unmount_ext)
203
+ popupDomain // popup: toggle semantics (load_ext, mount_ext, unmount_ext)
204
+ overlayDomain // overlay: toggle semantics (load_ext, mount_ext, unmount_ext)
205
+ ```
206
+
207
+ ### Action and Property Constants
208
+
209
+ ```typescript
210
+ import {
211
+ HAI3_ACTION_LOAD_EXT,
212
+ HAI3_ACTION_MOUNT_EXT,
213
+ HAI3_ACTION_UNMOUNT_EXT,
214
+ HAI3_SHARED_PROPERTY_THEME,
215
+ HAI3_SHARED_PROPERTY_LANGUAGE,
216
+ } from '@hai3/framework';
217
+
218
+ // Action IDs
219
+ HAI3_ACTION_LOAD_EXT // 'gts.hai3.mfes.comm.action.v1~hai3.mfes.ext.load_ext.v1'
220
+ HAI3_ACTION_MOUNT_EXT // 'gts.hai3.mfes.comm.action.v1~hai3.mfes.ext.mount_ext.v1'
221
+ HAI3_ACTION_UNMOUNT_EXT // 'gts.hai3.mfes.comm.action.v1~hai3.mfes.ext.unmount_ext.v1'
222
+
223
+ // Shared property IDs
224
+ HAI3_SHARED_PROPERTY_THEME // 'gts.hai3.mfes.comm.shared_property.v1~hai3.mfes.comm.theme.v1~'
225
+ HAI3_SHARED_PROPERTY_LANGUAGE // 'gts.hai3.mfes.comm.shared_property.v1~hai3.mfes.comm.language.v1~'
226
+ ```
227
+
116
228
  ## Creating Custom Plugins
117
229
 
118
230
  Extend HAI3 with custom functionality:
@@ -142,18 +254,19 @@ export function myPlugin(): HAI3Plugin {
142
254
 
143
255
  ## Key Rules
144
256
 
145
- 1. **Use presets for common cases** - `createHAI3App()` for full apps
257
+ 1. **Use presets for common cases** - `createHAI3App()` for full apps with MFE support
146
258
  2. **Compose plugins for customization** - Use `createHAI3().use()` pattern
147
259
  3. **Dependencies are auto-resolved** - Plugin order doesn't matter
148
260
  4. **Access via app instance** - All registries and actions on `app.*`
149
261
  5. **NO React in this package** - Framework is headless, use @hai3/react for React bindings
262
+ 6. **MFE is the primary architecture** - Use `screensetsRegistry` for domain/extension management
150
263
 
151
264
  ## Re-exports
152
265
 
153
266
  For convenience, this package re-exports from SDK packages:
154
267
 
155
268
  - From @hai3/state: `eventBus`, `createStore`, `getStore`, `registerSlice`, `hasSlice`, `createSlice`
156
- - From @hai3/screensets: `LayoutDomain`, `ScreensetCategory`, `screensetRegistry`, contracts/types
269
+ - From @hai3/screensets: `LayoutDomain`, `ScreensetsRegistry`, `Extension`, `ScreenExtension`, `ExtensionDomain`, `MfeHandler`, `MfeBridgeFactory`, `ParentMfeBridge`, `ChildMfeBridge`, action/property constants, contracts/types
157
270
  - From @hai3/api: `apiRegistry`, `BaseApiService`, `RestProtocol`, `RestMockPlugin`, `SseMockPlugin`, `MOCK_PLUGIN`, `isMockPlugin`
158
271
  - From @hai3/i18n: `i18nRegistry`, `Language`, `SUPPORTED_LANGUAGES`, `getLanguageMetadata`
159
272
 
@@ -163,7 +276,12 @@ For convenience, this package re-exports from SDK packages:
163
276
  - Domain actions: `headerActions`, `footerActions`, `menuActions`, `sidebarActions`, `screenActions`, `popupActions`, `overlayActions`
164
277
  - Individual reducer functions: `setMenuCollapsed`, `toggleSidebar`, `setActiveScreen`, etc.
165
278
 
166
- **NOTE:** `createAction` is NOT exported to consumers. Actions should be handwritten functions in screensets that contain business logic and emit events via `eventBus.emit()`.
279
+ **MFE Exports:**
280
+ - `MfeHandlerMF` - Concrete MFE handler for Module Federation
281
+ - `gtsPlugin` - GTS (Global Type System) plugin for type validation
282
+ - `createShadowRoot`, `injectCssVariables` - Shadow DOM utilities
283
+
284
+ **NOTE:** `createAction` is NOT exported to consumers. Actions should be handwritten functions in extensions that contain business logic and emit events via `eventBus.emit()`.
167
285
 
168
286
  **NOTE:** "Selector" is Redux terminology and is not used in HAI3. Access state via `useAppSelector` hook from @hai3/react:
169
287
  ```typescript
@@ -178,13 +296,70 @@ const menu = useAppSelector((state: RootStateWithLayout) => state.layout.menu);
178
296
  - `presets` - Available presets (full, minimal, headless)
179
297
 
180
298
  ### Plugins
181
- - `screensets`, `themes`, `layout`, `navigation`, `routing`, `i18n`, `effects`, `mock`
299
+ - `screensets`, `themes`, `layout`, `microfrontends`, `i18n`, `effects`, `mock`
182
300
 
183
301
  ### Registries
184
- - `createScreensetRegistry`, `createThemeRegistry`, `createRouteRegistry`
302
+ - `createThemeRegistry` - Theme registry factory
185
303
 
186
304
  ### Types
187
305
  - `HAI3Config`, `HAI3Plugin`, `HAI3App`, `HAI3AppBuilder`
188
306
  - `PluginFactory`, `PluginProvides`, `PluginLifecycle`
189
307
  - `Preset`, `Presets`, `ScreensetsConfig`
190
308
  - All re-exported types from SDK packages
309
+
310
+ ## Migration from Legacy API
311
+
312
+ The legacy screenset navigation API has been removed. HAI3 now uses the MFE architecture exclusively:
313
+
314
+ ### Removed APIs
315
+ - `screensetRegistry` (replaced by `screensetsRegistry`)
316
+ - `createScreensetRegistry()` (replaced by `ScreensetsRegistry` class)
317
+ - `navigation()` plugin (replaced by MFE actions)
318
+ - `routing()` plugin (replaced by extension route presentation)
319
+ - `routeRegistry` (replaced by extension route management)
320
+ - `navigateToScreen()` / `navigateToScreenset()` actions (replaced by `mountExtension()`)
321
+
322
+ ### Migration Examples
323
+
324
+ **OLD**: Navigate to screen
325
+ ```typescript
326
+ app.actions.navigateToScreen({ screensetId: 'demo', screenId: 'home' });
327
+ ```
328
+
329
+ **NEW**: Mount extension
330
+ ```typescript
331
+ await app.actions.mountExtension({
332
+ extensionId: 'home',
333
+ domainId: 'screen',
334
+ container: document.getElementById('screen-container')!,
335
+ });
336
+ ```
337
+
338
+ **OLD**: Register screenset
339
+ ```typescript
340
+ import { screensetRegistry, ScreensetDefinition } from '@hai3/framework';
341
+
342
+ const screenset: ScreensetDefinition = {
343
+ id: 'demo',
344
+ name: 'Demo',
345
+ category: ScreensetCategory.Production,
346
+ defaultScreen: 'home',
347
+ menu: [/* ... */],
348
+ };
349
+
350
+ screensetRegistry.register(screenset);
351
+ ```
352
+
353
+ **NEW**: Register domain and extensions
354
+ ```typescript
355
+ import { screensetsRegistry, ExtensionDomain, Extension } from '@hai3/framework';
356
+
357
+ // Register domain
358
+ app.screensetsRegistry.registerDomain(screenDomain, containerProvider);
359
+
360
+ // Register extensions
361
+ await app.screensetsRegistry.registerExtension(homeExtension);
362
+ await app.screensetsRegistry.registerExtension(profileExtension);
363
+ ```
364
+
365
+ See the MFE migration guide in the project documentation for detailed migration steps.