@hai3/framework 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.
@@ -0,0 +1,440 @@
1
+ import { HAI3Store as HAI3Store$1, EffectInitializer } from '@hai3/state';
2
+ import { Reducer } from '@reduxjs/toolkit';
3
+ import { ScreensetRegistry } from '@hai3/screensets';
4
+ export { ScreensetRegistry } from '@hai3/screensets';
5
+ import { ApiRegistry } from '@hai3/api';
6
+ import { I18nRegistry } from '@hai3/i18n';
7
+
8
+ /**
9
+ * @hai3/framework - Type Definitions
10
+ *
11
+ * Core types for HAI3 framework with plugin architecture.
12
+ * Integrates all SDK packages into a cohesive framework.
13
+ */
14
+
15
+ type HAI3Store = HAI3Store$1;
16
+ /**
17
+ * HAI3 Application Configuration
18
+ * Configuration options for creating a HAI3 application.
19
+ */
20
+ interface HAI3Config {
21
+ /** Application name */
22
+ name?: string;
23
+ /** Enable development mode */
24
+ devMode?: boolean;
25
+ /** Enable strict mode (throws on errors) */
26
+ strictMode?: boolean;
27
+ /**
28
+ * Auto-navigate to first screenset on mount.
29
+ * When false, stays on "/" until navigateToScreen/navigateToScreenset is called.
30
+ * @default true
31
+ */
32
+ autoNavigate?: boolean;
33
+ }
34
+ /**
35
+ * Registerable Slice Interface
36
+ * Minimal interface for slices that can be registered with the framework.
37
+ * Used for heterogeneous slice collections where different state types are mixed.
38
+ *
39
+ * This is an internal framework type - plugins provide slices matching this structure.
40
+ * The Reducer type uses RTK's default, avoiding explicit `any` in HAI3 code.
41
+ */
42
+ interface RegisterableSlice {
43
+ /** Slice name - becomes the state key */
44
+ readonly name: string;
45
+ /** Slice reducer function */
46
+ readonly reducer: Reducer;
47
+ /** Slice action creators (optional for registration) */
48
+ readonly actions?: Record<string, unknown>;
49
+ }
50
+ /**
51
+ * HAI3 Actions Interface
52
+ * Central registry of all actions available in the application.
53
+ *
54
+ * Built-in actions are defined here. Consumers can extend this interface
55
+ * via module augmentation to add custom actions:
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * declare module '@hai3/framework' {
60
+ * interface HAI3Actions {
61
+ * myCustomAction: (payload: MyPayload) => void;
62
+ * }
63
+ * }
64
+ * ```
65
+ *
66
+ * Design: Interface (not type) enables TypeScript declaration merging.
67
+ */
68
+ interface HAI3Actions {
69
+ navigateToScreen: (payload: NavigateToScreenPayload) => void;
70
+ navigateToScreenset: (payload: NavigateToScreensetPayload) => void;
71
+ changeTheme: (payload: ChangeThemePayload) => void;
72
+ setLanguage: (payload: SetLanguagePayload) => void;
73
+ showPopup: (payload: ShowPopupPayload) => void;
74
+ hidePopup: () => void;
75
+ showOverlay: (payload: {
76
+ id: string;
77
+ }) => void;
78
+ hideOverlay: () => void;
79
+ toggleMenuCollapsed: (payload: {
80
+ collapsed: boolean;
81
+ }) => void;
82
+ toggleSidebarCollapsed: (payload: {
83
+ collapsed: boolean;
84
+ }) => void;
85
+ setHeaderVisible: (payload: boolean) => void;
86
+ setFooterVisible: (payload: boolean) => void;
87
+ setMenuCollapsed: (payload: boolean) => void;
88
+ setSidebarCollapsed: (payload: boolean) => void;
89
+ setActiveScreen: (payload: string) => void;
90
+ setScreenLoading: (payload: boolean) => void;
91
+ }
92
+ /**
93
+ * Plugin Provides Interface
94
+ * What a plugin contributes to the application.
95
+ */
96
+ interface PluginProvides {
97
+ /** Registry contributions */
98
+ registries?: Record<string, unknown>;
99
+ /** Redux slices to register */
100
+ slices?: RegisterableSlice[];
101
+ /** Effect initializers to register */
102
+ effects?: EffectInitializer[];
103
+ /** Actions provided by the plugin (subset of HAI3Actions) */
104
+ actions?: Partial<HAI3Actions>;
105
+ }
106
+ /**
107
+ * Plugin Lifecycle Interface
108
+ * Lifecycle hooks for plugin initialization.
109
+ */
110
+ interface PluginLifecycle {
111
+ /**
112
+ * Called when plugin is registered (before app starts).
113
+ *
114
+ * @param app - The app builder instance
115
+ * @param config - Plugin configuration
116
+ */
117
+ onRegister?(app: HAI3AppBuilder, config: unknown): void;
118
+ /**
119
+ * Called after all plugins registered, before app starts.
120
+ *
121
+ * @param app - The built app instance
122
+ */
123
+ onInit?(app: HAI3App): void | Promise<void>;
124
+ /**
125
+ * Called when app is destroyed.
126
+ *
127
+ * @param app - The app instance
128
+ */
129
+ onDestroy?(app: HAI3App): void;
130
+ }
131
+ /**
132
+ * HAI3 Plugin Interface
133
+ * All plugins implement this contract.
134
+ * Follows Liskov Substitution Principle - any plugin can be used interchangeably.
135
+ *
136
+ * @template TConfig - Plugin configuration type
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * const screensetsPlugin: HAI3Plugin = {
141
+ * name: 'screensets',
142
+ * dependencies: [],
143
+ * provides: {
144
+ * registries: { screensetRegistry: createScreensetRegistry() },
145
+ * slices: [screenSlice],
146
+ * },
147
+ * onInit(app) {
148
+ * discoverScreensets(app.screensetRegistry);
149
+ * },
150
+ * };
151
+ * ```
152
+ */
153
+ interface HAI3Plugin<TConfig = unknown> extends PluginLifecycle {
154
+ /** Unique plugin identifier */
155
+ name: string;
156
+ /** Other plugins this plugin requires */
157
+ dependencies?: string[];
158
+ /** What this plugin provides to the app */
159
+ provides?: PluginProvides;
160
+ /** Plugin configuration type marker (used for type inference) */
161
+ _configType?: TConfig;
162
+ }
163
+ /**
164
+ * Plugin Factory Function
165
+ * Factory function that creates a plugin with optional configuration.
166
+ *
167
+ * @template TConfig - Plugin configuration type
168
+ */
169
+ type PluginFactory<TConfig = unknown> = (config?: TConfig) => HAI3Plugin<TConfig>;
170
+ /**
171
+ * HAI3 App Builder Interface
172
+ * Fluent builder for composing HAI3 applications with plugins.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * const app = createHAI3()
177
+ * .use(screensets())
178
+ * .use(themes())
179
+ * .use(layout())
180
+ * .build();
181
+ * ```
182
+ */
183
+ interface HAI3AppBuilder {
184
+ /**
185
+ * Add a plugin to the application.
186
+ *
187
+ * @param plugin - Plugin instance or factory
188
+ * @returns Builder for chaining
189
+ */
190
+ use(plugin: HAI3Plugin | PluginFactory): HAI3AppBuilder;
191
+ /**
192
+ * Add multiple plugins at once.
193
+ *
194
+ * @param plugins - Array of plugins or factories
195
+ * @returns Builder for chaining
196
+ */
197
+ useAll(plugins: Array<HAI3Plugin | PluginFactory>): HAI3AppBuilder;
198
+ /**
199
+ * Build the application.
200
+ * Resolves dependencies, initializes plugins, and returns the app.
201
+ *
202
+ * @returns The built HAI3 application
203
+ */
204
+ build(): HAI3App;
205
+ }
206
+
207
+ /**
208
+ * Theme Configuration
209
+ * Configuration for a theme.
210
+ */
211
+ interface ThemeConfig {
212
+ /** Theme ID */
213
+ id: string;
214
+ /** Theme name */
215
+ name: string;
216
+ /** CSS custom properties */
217
+ variables: Record<string, string>;
218
+ /** Whether this is the default theme */
219
+ default?: boolean;
220
+ }
221
+ /**
222
+ * Legacy Theme type (from @hai3/uikit)
223
+ * Used for backward compatibility with old register(id, theme) pattern.
224
+ * Using 'unknown' as the base type to accept any theme structure.
225
+ */
226
+ type LegacyTheme = unknown;
227
+ /**
228
+ * Theme apply function type
229
+ * Generic to accept any theme type from UI kit implementations.
230
+ * @internal - uses generic function signature for compatibility with various theme implementations
231
+ */
232
+ interface ThemeApplyFn {
233
+ (theme: unknown, themeName?: string): void;
234
+ }
235
+ /**
236
+ * Theme Registry Interface
237
+ * Registry for managing themes.
238
+ */
239
+ interface ThemeRegistry {
240
+ /**
241
+ * Register a theme.
242
+ * Supports both new API (config only) and legacy API (id + theme).
243
+ *
244
+ * @param configOrId - ThemeConfig or theme ID (for legacy API)
245
+ * @param legacyTheme - Legacy Theme object (optional, for backward compatibility)
246
+ */
247
+ register(configOrId: ThemeConfig | string, legacyTheme?: LegacyTheme): void;
248
+ /**
249
+ * Set the apply function (legacy API).
250
+ * @deprecated Use the built-in apply or provide applyFn at construction.
251
+ */
252
+ setApplyFunction(applyFn: ThemeApplyFn): void;
253
+ /** Get theme by ID */
254
+ get(id: string): ThemeConfig | undefined;
255
+ /** Get all themes */
256
+ getAll(): ThemeConfig[];
257
+ /** Apply a theme */
258
+ apply(id: string): void;
259
+ /** Get current theme */
260
+ getCurrent(): ThemeConfig | undefined;
261
+ /**
262
+ * Subscribe to theme changes.
263
+ * @param callback - Called when theme changes
264
+ * @returns Unsubscribe function
265
+ */
266
+ subscribe(callback: () => void): () => void;
267
+ /**
268
+ * Get current version number.
269
+ * Used by React for re-rendering on theme changes.
270
+ */
271
+ getVersion(): number;
272
+ }
273
+ /**
274
+ * Route Registry Interface
275
+ * Registry for managing routes (auto-synced from screensets).
276
+ */
277
+ interface RouteRegistry {
278
+ /** Check if a screen exists by screenId only (globally unique) */
279
+ hasScreenById(screenId: string): boolean;
280
+ /** Check if a screen exists (legacy, requires both IDs) */
281
+ hasScreen(screensetId: string, screenId: string): boolean;
282
+ /** Get screenset ID for a given screen ID (reverse lookup) */
283
+ getScreensetForScreen(screenId: string): string | undefined;
284
+ /** Get screen loader by screenId only */
285
+ getScreenById(screenId: string): (() => Promise<{
286
+ default: React.ComponentType;
287
+ }>) | undefined;
288
+ /** Get screen loader (legacy, requires both IDs) */
289
+ getScreen(screensetId: string, screenId: string): (() => Promise<{
290
+ default: React.ComponentType;
291
+ }>) | undefined;
292
+ /** Get all routes */
293
+ getAll(): Array<{
294
+ screensetId: string;
295
+ screenId: string;
296
+ }>;
297
+ }
298
+ /**
299
+ * HAI3 App Interface
300
+ * The built application with all features available.
301
+ *
302
+ * @example
303
+ * ```typescript
304
+ * const app = createHAI3App();
305
+ *
306
+ * // Access registries
307
+ * const screensets = app.screensetRegistry.getAll();
308
+ *
309
+ * // Access store
310
+ * const state = app.store.getState();
311
+ *
312
+ * // Access actions
313
+ * app.actions.navigateToScreen({ screensetId: 'demo', screenId: 'home' });
314
+ * ```
315
+ */
316
+ interface HAI3App {
317
+ /** Application configuration */
318
+ config: HAI3Config;
319
+ /** Redux store */
320
+ store: HAI3Store;
321
+ /** Screenset registry */
322
+ screensetRegistry: ScreensetRegistry;
323
+ /** Theme registry */
324
+ themeRegistry: ThemeRegistry;
325
+ /** Route registry */
326
+ routeRegistry: RouteRegistry;
327
+ /** API registry */
328
+ apiRegistry: ApiRegistry;
329
+ /** I18n registry */
330
+ i18nRegistry: I18nRegistry;
331
+ /** All registered actions (type-safe via HAI3Actions interface) */
332
+ actions: HAI3Actions;
333
+ /** Destroy the application and cleanup resources */
334
+ destroy(): void;
335
+ }
336
+ /**
337
+ * Create HAI3 App Function Signature
338
+ * Creates a fully configured HAI3 application using the full preset.
339
+ *
340
+ * @param config - Optional configuration
341
+ * @returns The built HAI3 application
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * // Default - uses full() preset
346
+ * const app = createHAI3App();
347
+ *
348
+ * // With configuration
349
+ * const app = createHAI3App({ devMode: true });
350
+ * ```
351
+ */
352
+ type CreateHAI3App = (config?: HAI3Config) => HAI3App;
353
+ /**
354
+ * Create HAI3 Function Signature
355
+ * Creates a HAI3 app builder for custom plugin composition.
356
+ *
357
+ * @returns App builder for plugin composition
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const app = createHAI3()
362
+ * .use(screensets())
363
+ * .use(themes())
364
+ * .build();
365
+ * ```
366
+ */
367
+ type CreateHAI3 = () => HAI3AppBuilder;
368
+ /**
369
+ * Preset Type
370
+ * A preset is a function that returns an array of plugins.
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * const minimal: Preset = () => [
375
+ * screensets({ autoDiscover: true }),
376
+ * themes(),
377
+ * ];
378
+ * ```
379
+ */
380
+ type Preset = () => HAI3Plugin[];
381
+ /**
382
+ * Presets Collection
383
+ * Available presets for different use cases.
384
+ */
385
+ interface Presets {
386
+ /** All plugins - default for hai3 create */
387
+ full: Preset;
388
+ /** Screensets + themes only */
389
+ minimal: Preset;
390
+ /** Screensets only - for external platform integration */
391
+ headless: Preset;
392
+ }
393
+ /**
394
+ * Screensets Plugin Configuration
395
+ * Configuration options for the screensets plugin.
396
+ */
397
+ interface ScreensetsConfig {
398
+ /** Auto-discover screensets via glob */
399
+ autoDiscover?: boolean;
400
+ /** Glob pattern for screenset discovery */
401
+ globPattern?: string;
402
+ }
403
+ /**
404
+ * Navigate to Screen Payload
405
+ */
406
+ interface NavigateToScreenPayload {
407
+ screensetId: string;
408
+ screenId: string;
409
+ }
410
+ /**
411
+ * Navigate to Screenset Payload
412
+ */
413
+ interface NavigateToScreensetPayload {
414
+ screensetId: string;
415
+ }
416
+ /**
417
+ * Show Popup Payload
418
+ */
419
+ interface ShowPopupPayload {
420
+ id: string;
421
+ title?: string;
422
+ content?: () => Promise<{
423
+ default: React.ComponentType;
424
+ }>;
425
+ size?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
426
+ }
427
+ /**
428
+ * Change Theme Payload
429
+ */
430
+ interface ChangeThemePayload {
431
+ themeId: string;
432
+ }
433
+ /**
434
+ * Set Language Payload
435
+ */
436
+ interface SetLanguagePayload {
437
+ language: string;
438
+ }
439
+
440
+ export type { ChangeThemePayload, CreateHAI3, CreateHAI3App, HAI3Actions, HAI3App, HAI3AppBuilder, HAI3Config, HAI3Plugin, HAI3Store, LegacyTheme, NavigateToScreenPayload, NavigateToScreensetPayload, PluginFactory, PluginLifecycle, PluginProvides, Preset, Presets, RegisterableSlice, RouteRegistry, ScreensetsConfig, SetLanguagePayload, ShowPopupPayload, ThemeApplyFn, ThemeConfig, ThemeRegistry };
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,52 @@
1
+ # @hai3/framework
2
+
3
+ > Plugin-based application framework for HAI3 SDK. Orchestrates SDK packages into cohesive applications.
4
+
5
+ Part of the HAI3 Framework Layer (L2) - depends on all SDK packages (@hai3/state, @hai3/screensets, @hai3/api, @hai3/i18n) and @hai3/uicore for layout state management.
6
+
7
+ ## Core API
8
+
9
+ - [createHAI3](https://hai3.dev/docs/framework/create): App builder with plugin composition
10
+ - [createHAI3App](https://hai3.dev/docs/framework/app): Convenience function (full preset)
11
+ - [presets](https://hai3.dev/docs/framework/presets): Pre-configured plugin combinations (full, minimal, headless)
12
+
13
+ ## Available Plugins
14
+
15
+ | Plugin | Provides |
16
+ |--------|----------|
17
+ | `screensets()` | screensetRegistry, screen slice |
18
+ | `themes()` | themeRegistry, changeTheme action |
19
+ | `layout()` | header, footer, menu, sidebar, popup, overlay slices |
20
+ | `navigation()` | navigateToScreen, navigateToScreenset actions |
21
+ | `routing()` | routeRegistry, URL sync |
22
+ | `i18n()` | i18nRegistry, setLanguage action |
23
+ | `effects()` | Core effect coordination |
24
+
25
+ ## Quick Start
26
+
27
+ ```typescript
28
+ import { createHAI3, screensets, themes, layout, navigation, i18n } from '@hai3/framework';
29
+
30
+ // Compose plugins
31
+ const app = createHAI3()
32
+ .use(screensets())
33
+ .use(themes())
34
+ .use(layout())
35
+ .use(navigation())
36
+ .use(i18n())
37
+ .build();
38
+
39
+ // Or use preset (equivalent to above)
40
+ import { createHAI3App } from '@hai3/framework';
41
+ const app = createHAI3App();
42
+
43
+ // Access registries and actions
44
+ app.screensetRegistry.getAll();
45
+ app.actions.navigateToScreen({ screensetId: 'demo', screenId: 'home' });
46
+ app.actions.changeTheme({ themeId: 'dark' });
47
+ ```
48
+
49
+ ## Optional
50
+
51
+ - [Custom Plugins](https://hai3.dev/docs/framework/plugins): Creating custom plugins
52
+ - [Migration Guide](https://hai3.dev/docs/framework/migration): Migrating from @hai3/uicore
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@hai3/framework",
3
+ "version": "0.2.0-alpha.0",
4
+ "description": "HAI3 framework integrating all SDK packages with plugin architecture",
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
+ },
36
+ "peerDependencies": {
37
+ "@hai3/state": "*",
38
+ "@hai3/screensets": "*",
39
+ "@hai3/api": "*",
40
+ "@hai3/i18n": "*"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@hai3/state": { "optional": false },
44
+ "@hai3/screensets": { "optional": false },
45
+ "@hai3/api": { "optional": false },
46
+ "@hai3/i18n": { "optional": false }
47
+ },
48
+ "keywords": [
49
+ "hai3",
50
+ "framework",
51
+ "plugin",
52
+ "screenset",
53
+ "typescript"
54
+ ],
55
+ "author": "HAI3",
56
+ "license": "Apache-2.0"
57
+ }