@gears-frontx/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/llms.txt ADDED
@@ -0,0 +1,122 @@
1
+ # @gears-frontx/react
2
+
3
+ > React bindings, hooks, and components for HAI3 SDK. Provides type-safe integration with React applications including MFE (Microfrontend) support.
4
+
5
+ Part of the HAI3 React Layer (L3) - depends on @gears-frontx/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
+ - [MFE Components](https://hai3.dev/docs/react/mfe): ExtensionDomainSlot, MfeProvider, RefContainerProvider
11
+
12
+ ## Hooks
13
+
14
+ | Hook | Purpose |
15
+ |------|---------|
16
+ | `useHAI3()` | Access app instance |
17
+ | `useAppDispatch()` | Type-safe dispatch |
18
+ | `useAppSelector()` | Type-safe selector |
19
+ | `useTranslation()` | Translation utilities (t, language, setLanguage, isRTL) |
20
+ | `useScreenTranslations()` | Lazy load screen translations |
21
+ | `useTheme()` | Theme utilities (currentTheme, themes, setTheme) |
22
+
23
+ ## MFE Hooks
24
+
25
+ | Hook | Purpose |
26
+ |------|---------|
27
+ | `useMfeBridge()` | Access MFE bridge (child MFEs) |
28
+ | `useSharedProperty()` | Subscribe to shared property changes |
29
+ | `useHostAction()` | Invoke actions on host application |
30
+ | `useDomainExtensions()` | Subscribe to extensions in a domain |
31
+
32
+ ## Quick Start
33
+
34
+ ```tsx
35
+ import { HAI3Provider, ExtensionDomainSlot, useTranslation, useHAI3 } from '@gears-frontx/react';
36
+
37
+ // Wrap app with provider
38
+ function App() {
39
+ return (
40
+ <HAI3Provider>
41
+ <Layout>
42
+ <ExtensionDomainSlot domainId="screen" fallback={<Loading />} />
43
+ </Layout>
44
+ </HAI3Provider>
45
+ );
46
+ }
47
+
48
+ // Use hooks in components
49
+ function MyComponent() {
50
+ const { t, isRTL } = useTranslation();
51
+ const app = useHAI3();
52
+
53
+ return (
54
+ <div dir={isRTL ? 'rtl' : 'ltr'}>
55
+ <h1>{t('common:title')}</h1>
56
+ </div>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ## MFE Patterns
62
+
63
+ ### Using ExtensionDomainSlot
64
+
65
+ ```tsx
66
+ import { ExtensionDomainSlot } from '@gears-frontx/react';
67
+
68
+ function LayoutScreen() {
69
+ const screenContainerRef = useRef<HTMLDivElement>(null);
70
+
71
+ return (
72
+ <ExtensionDomainSlot
73
+ domainId="screen"
74
+ containerRef={screenContainerRef}
75
+ fallback={<Loading />}
76
+ />
77
+ );
78
+ }
79
+ ```
80
+
81
+ ### Using MFE Bridge
82
+
83
+ ```tsx
84
+ import { useMfeBridge, useSharedProperty, HAI3_ACTION_LOAD_EXT, HAI3_SHARED_PROPERTY_THEME } from '@gears-frontx/react';
85
+
86
+ function MyExtension() {
87
+ const bridge = useMfeBridge();
88
+ const theme = useSharedProperty(HAI3_SHARED_PROPERTY_THEME);
89
+
90
+ const handleAction = async () => {
91
+ await bridge.executeActionsChain({
92
+ action: { type: HAI3_ACTION_LOAD_EXT, target: 'screen', payload: { extensionId: 'other' } }
93
+ });
94
+ };
95
+
96
+ return <div style={{ backgroundColor: theme?.primaryColor }}>...</div>;
97
+ }
98
+ ```
99
+
100
+ ### Subscribing to Domain Extensions
101
+
102
+ ```tsx
103
+ import { useDomainExtensions } from '@gears-frontx/react';
104
+
105
+ function ScreenList() {
106
+ const screenExtensions = useDomainExtensions('screen');
107
+
108
+ return (
109
+ <ul>
110
+ {screenExtensions.map((ext) => (
111
+ <li key={ext.id}>{ext.title}</li>
112
+ ))}
113
+ </ul>
114
+ );
115
+ }
116
+ ```
117
+
118
+ ## Optional
119
+
120
+ - [Screen Translations](https://hai3.dev/docs/react/translations): Per-screen lazy loading
121
+ - [Custom Hooks](https://hai3.dev/docs/react/hooks): Building on HAI3 hooks
122
+ - [MFE Bridge Communication](https://hai3.dev/docs/react/mfe-bridge): Parent-child patterns
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@gears-frontx/react",
3
+ "version": "0.1.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
+ "test": "vitest run",
31
+ "test:watch": "vitest"
32
+ },
33
+ "dependencies": {},
34
+ "devDependencies": {
35
+ "tsup": "^8.0.0",
36
+ "typescript": "^5.4.2",
37
+ "react": "^19.2.4",
38
+ "@types/react": "^19.0.8",
39
+ "react-redux": "^9.1.0",
40
+ "@types/react-redux": "^7.1.33",
41
+ "vitest": "^4.0.18",
42
+ "@vitest/coverage-v8": "^4.0.18",
43
+ "@testing-library/react": "^16.1.0",
44
+ "@reduxjs/toolkit": "^2.5.0",
45
+ "jsdom": "^25.0.1"
46
+ },
47
+ "peerDependencies": {
48
+ "@gears-frontx/framework": "*",
49
+ "react": "^19.2.4",
50
+ "react-redux": ">=8.0.0"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "@gears-frontx/framework": {
54
+ "optional": false
55
+ },
56
+ "react": {
57
+ "optional": false
58
+ },
59
+ "react-redux": {
60
+ "optional": false
61
+ }
62
+ },
63
+ "publishConfig": {
64
+ "access": "public"
65
+ },
66
+ "keywords": [
67
+ "hai3",
68
+ "react",
69
+ "hooks",
70
+ "provider",
71
+ "typescript"
72
+ ],
73
+ "author": "HAI3",
74
+ "license": "Apache-2.0"
75
+ }