@easyops-cn/a2ui-react 0.0.5 → 0.0.7
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/README.md +14 -10
- package/dist/0.8/A2UIRenderer.d.ts +15 -33
- package/dist/0.8/A2UIRenderer.js +13 -34
- package/dist/0.8/contexts/A2UIProvider.d.ts +38 -16
- package/dist/0.8/contexts/A2UIProvider.js +30 -7
- package/dist/0.8/contexts/ActionContext.js +3 -3
- package/dist/0.8/index.d.ts +21 -2
- package/dist/0.8/index.js +13 -9
- package/package.json +1 -1
- package/dist/0.8/A2UIRenderer.test.d.ts +0 -6
- package/dist/0.8/components/ComponentRenderer.test.d.ts +0 -6
- package/dist/0.8/components/display/display.test.d.ts +0 -7
- package/dist/0.8/components/interactive/interactive.test.d.ts +0 -7
- package/dist/0.8/components/layout/layout.test.d.ts +0 -7
- package/dist/0.8/contexts/A2UIProvider.test.d.ts +0 -6
- package/dist/0.8/contexts/ActionContext.test.d.ts +0 -6
- package/dist/0.8/contexts/DataModelContext.test.d.ts +0 -6
- package/dist/0.8/contexts/SurfaceContext.test.d.ts +0 -6
- package/dist/0.8/hooks/useA2UIMessageHandler.test.d.ts +0 -6
- package/dist/0.8/hooks/useComponent.test.d.ts +0 -6
- package/dist/0.8/hooks/useDataBinding.test.d.ts +0 -6
- package/dist/0.8/hooks/useDispatchAction.test.d.ts +0 -6
- package/dist/0.8/hooks/useSurface.test.d.ts +0 -6
- package/dist/0.8/utils/dataBinding.test.d.ts +0 -6
- package/dist/0.8/utils/pathUtils.test.d.ts +0 -6
package/README.md
CHANGED
|
@@ -22,10 +22,11 @@ First, use the `@source` directive to tell Tailwind to scan the library code for
|
|
|
22
22
|
@source "../node_modules/@easyops-cn/a2ui-react";
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
Next, use
|
|
25
|
+
Next, use `A2UIProvider` and `A2UIRenderer` to render A2UI messages:
|
|
26
26
|
|
|
27
27
|
```tsx
|
|
28
28
|
import {
|
|
29
|
+
A2UIProvider,
|
|
29
30
|
A2UIRenderer,
|
|
30
31
|
type A2UIMessage,
|
|
31
32
|
type A2UIAction,
|
|
@@ -38,19 +39,24 @@ function App() {
|
|
|
38
39
|
console.log('Action received:', action)
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
return
|
|
42
|
+
return (
|
|
43
|
+
<A2UIProvider messages={messages}>
|
|
44
|
+
<A2UIRenderer onAction={handleAction} />
|
|
45
|
+
</A2UIProvider>
|
|
46
|
+
)
|
|
42
47
|
}
|
|
43
48
|
```
|
|
44
49
|
|
|
45
50
|
### Custom components
|
|
46
51
|
|
|
47
|
-
You can override default components or add new custom components via the `components` prop
|
|
52
|
+
You can override default components or add new custom components via the `components` prop on `A2UIProvider`, which takes a `Map<string, React.ComponentType>`.
|
|
48
53
|
|
|
49
54
|
```tsx
|
|
50
55
|
import {
|
|
56
|
+
A2UIProvider,
|
|
51
57
|
A2UIRenderer,
|
|
52
|
-
A2UIMessage,
|
|
53
|
-
A2UIAction,
|
|
58
|
+
type A2UIMessage,
|
|
59
|
+
type A2UIAction,
|
|
54
60
|
} from '@easyops-cn/a2ui-react/0.8'
|
|
55
61
|
|
|
56
62
|
const ComponentsMap = new Map<string, React.ComponentType<any>>([
|
|
@@ -63,11 +69,9 @@ const ComponentsMap = new Map<string, React.ComponentType<any>>([
|
|
|
63
69
|
|
|
64
70
|
function App() {
|
|
65
71
|
return (
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onAction={handleAction}
|
|
70
|
-
/>
|
|
72
|
+
<A2UIProvider components={ComponentsMap} messages={messages}>
|
|
73
|
+
<A2UIRenderer onAction={handleAction} />
|
|
74
|
+
</A2UIProvider>
|
|
71
75
|
)
|
|
72
76
|
}
|
|
73
77
|
```
|
|
@@ -1,49 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A2UIMessage, ActionPayload, BaseComponentProps } from './types';
|
|
1
|
+
import { ActionHandler } from './types';
|
|
3
2
|
/**
|
|
4
|
-
*
|
|
3
|
+
* Props for A2UIRenderer.
|
|
5
4
|
*/
|
|
6
|
-
export
|
|
7
|
-
/**
|
|
8
|
-
* Props for A2UIRenderer component.
|
|
9
|
-
*/
|
|
10
|
-
export interface A2UIRenderProps {
|
|
11
|
-
/** Array of A2UI messages to render */
|
|
12
|
-
messages: A2UIMessage[];
|
|
5
|
+
export interface A2UIRendererProps {
|
|
13
6
|
/** Callback when an action is dispatched */
|
|
14
|
-
onAction?:
|
|
15
|
-
/** Custom component overrides */
|
|
16
|
-
components?: ComponentsMap;
|
|
7
|
+
onAction?: ActionHandler;
|
|
17
8
|
}
|
|
18
9
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* Processes an array of A2UIMessage objects and renders the resulting UI.
|
|
22
|
-
* Supports custom component overrides via the components prop.
|
|
10
|
+
* Component for rendering A2UI surfaces.
|
|
23
11
|
*
|
|
24
|
-
*
|
|
25
|
-
* @param props.messages - Array of A2UI messages to render
|
|
26
|
-
* @param props.onAction - Optional callback when an action is dispatched
|
|
27
|
-
* @param props.components - Optional custom component overrides
|
|
12
|
+
* Renders all surfaces from the A2UI context. Must be used within an A2UIProvider.
|
|
28
13
|
*
|
|
29
14
|
* @example
|
|
30
15
|
* ```tsx
|
|
31
16
|
* // Basic usage
|
|
32
|
-
* <
|
|
17
|
+
* <A2UIProvider messages={messages}>
|
|
18
|
+
* <A2UIRenderer onAction={handleAction} />
|
|
19
|
+
* </A2UIProvider>
|
|
33
20
|
*
|
|
34
|
-
* // With custom
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* <A2UIRenderer
|
|
40
|
-
* messages={messages}
|
|
41
|
-
* onAction={handleAction}
|
|
42
|
-
* components={customComponents}
|
|
43
|
-
* />
|
|
21
|
+
* // With custom middleware for hooks access
|
|
22
|
+
* <A2UIProvider messages={messages}>
|
|
23
|
+
* <MyCustomComponent />
|
|
24
|
+
* <A2UIRenderer onAction={handleAction} />
|
|
25
|
+
* </A2UIProvider>
|
|
44
26
|
* ```
|
|
45
27
|
*/
|
|
46
|
-
export declare function A2UIRenderer({
|
|
28
|
+
export declare function A2UIRenderer({ onAction }: A2UIRendererProps): import("react/jsx-runtime").JSX.Element | null;
|
|
47
29
|
export declare namespace A2UIRenderer {
|
|
48
30
|
var displayName: string;
|
|
49
31
|
}
|
package/dist/0.8/A2UIRenderer.js
CHANGED
|
@@ -1,40 +1,19 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const { processMessages: n, clear: o } = l(), { surfaces: t } = u();
|
|
10
|
-
p(() => {
|
|
11
|
-
o(), r && r.length > 0 && n(r);
|
|
12
|
-
}, [r, n, o]);
|
|
13
|
-
const s = Array.from(t.entries());
|
|
14
|
-
return s.length === 0 ? null : /* @__PURE__ */ e(f, { children: s.map(([i, m]) => m.root ? /* @__PURE__ */ e(
|
|
15
|
-
g,
|
|
1
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import { useSurfaceContext as m } from "./contexts/SurfaceContext.js";
|
|
3
|
+
import { ActionProvider as f } from "./contexts/ActionContext.js";
|
|
4
|
+
import { ComponentRenderer as p } from "./components/ComponentRenderer.js";
|
|
5
|
+
function u({ onAction: t }) {
|
|
6
|
+
const { surfaces: i } = m(), r = Array.from(i.entries());
|
|
7
|
+
return r.length === 0 ? null : /* @__PURE__ */ n(f, { onAction: t, children: r.map(([e, o]) => o.root ? /* @__PURE__ */ n(
|
|
8
|
+
p,
|
|
16
9
|
{
|
|
17
|
-
surfaceId:
|
|
18
|
-
componentId:
|
|
10
|
+
surfaceId: e,
|
|
11
|
+
componentId: o.root
|
|
19
12
|
},
|
|
20
|
-
|
|
13
|
+
e
|
|
21
14
|
) : null) });
|
|
22
15
|
}
|
|
23
|
-
|
|
24
|
-
messages: r,
|
|
25
|
-
onAction: n,
|
|
26
|
-
components: o
|
|
27
|
-
}) {
|
|
28
|
-
return /* @__PURE__ */ e(c, { onAction: n, children: /* @__PURE__ */ e(
|
|
29
|
-
a,
|
|
30
|
-
{
|
|
31
|
-
components: o,
|
|
32
|
-
defaultComponents: d,
|
|
33
|
-
children: /* @__PURE__ */ e(A, { messages: r ?? [] })
|
|
34
|
-
}
|
|
35
|
-
) });
|
|
36
|
-
}
|
|
37
|
-
I.displayName = "A2UI.Render";
|
|
16
|
+
u.displayName = "A2UI.Renderer";
|
|
38
17
|
export {
|
|
39
|
-
|
|
18
|
+
u as A2UIRenderer
|
|
40
19
|
};
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { ReactNode, ComponentType } from 'react';
|
|
2
|
+
import { A2UIMessage, BaseComponentProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Type for custom component map.
|
|
5
|
+
*/
|
|
6
|
+
export type ComponentsMap = Map<string, ComponentType<BaseComponentProps & Record<string, unknown>>>;
|
|
3
7
|
/**
|
|
4
8
|
* Props for A2UIProvider.
|
|
5
9
|
*/
|
|
6
10
|
export interface A2UIProviderProps {
|
|
7
|
-
/**
|
|
8
|
-
|
|
11
|
+
/** Array of A2UI messages to render */
|
|
12
|
+
messages: A2UIMessage[];
|
|
13
|
+
/** Custom component overrides */
|
|
14
|
+
components?: ComponentsMap;
|
|
9
15
|
children: ReactNode;
|
|
10
16
|
}
|
|
11
17
|
/**
|
|
@@ -14,21 +20,37 @@ export interface A2UIProviderProps {
|
|
|
14
20
|
* Provides:
|
|
15
21
|
* - SurfaceContext: Component tree management
|
|
16
22
|
* - DataModelContext: Data model state
|
|
17
|
-
* -
|
|
23
|
+
* - ComponentsMapContext: Custom component overrides
|
|
24
|
+
*
|
|
25
|
+
* @param props - Component props
|
|
26
|
+
* @param props.messages - Array of A2UI messages to render
|
|
27
|
+
* @param props.components - Optional custom component overrides
|
|
28
|
+
* @param props.children - Child components (typically A2UIRenderer)
|
|
18
29
|
*
|
|
19
30
|
* @example
|
|
20
31
|
* ```tsx
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
32
|
+
* // Basic usage
|
|
33
|
+
* <A2UIProvider messages={messages}>
|
|
34
|
+
* <A2UIRenderer onAction={handleAction} />
|
|
35
|
+
* </A2UIProvider>
|
|
36
|
+
*
|
|
37
|
+
* // With custom components
|
|
38
|
+
* const customComponents = new Map([
|
|
39
|
+
* ['Button', CustomButton],
|
|
40
|
+
* ['Switch', CustomSwitch],
|
|
41
|
+
* ])
|
|
42
|
+
* <A2UIProvider
|
|
43
|
+
* messages={messages}
|
|
44
|
+
* components={customComponents}
|
|
45
|
+
* >
|
|
46
|
+
* <A2UIRenderer onAction={handleAction} />
|
|
47
|
+
* </A2UIProvider>
|
|
25
48
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* }
|
|
49
|
+
* // With custom middleware for hooks access
|
|
50
|
+
* <A2UIProvider messages={messages}>
|
|
51
|
+
* <MyCustomComponent />
|
|
52
|
+
* <A2UIRenderer onAction={handleAction} />
|
|
53
|
+
* </A2UIProvider>
|
|
32
54
|
* ```
|
|
33
55
|
*/
|
|
34
|
-
export declare function A2UIProvider({
|
|
56
|
+
export declare function A2UIProvider({ messages, components, children, }: A2UIProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,10 +1,33 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { jsx as e, Fragment as n } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect as i } from "react";
|
|
3
|
+
import { SurfaceProvider as f } from "./SurfaceContext.js";
|
|
4
|
+
import { DataModelProvider as m } from "./DataModelContext.js";
|
|
5
|
+
import { ComponentsMapProvider as a } from "./ComponentsMapContext.js";
|
|
6
|
+
import { componentRegistry as c } from "../components/ComponentRenderer.js";
|
|
7
|
+
import { useA2UIMessageHandler as p } from "../hooks/useA2UIMessageHandler.js";
|
|
8
|
+
function d({
|
|
9
|
+
messages: r,
|
|
10
|
+
children: t
|
|
11
|
+
}) {
|
|
12
|
+
const { processMessages: o, clear: s } = p();
|
|
13
|
+
return i(() => {
|
|
14
|
+
s(), r && r.length > 0 && o(r);
|
|
15
|
+
}, [r, o, s]), /* @__PURE__ */ e(n, { children: t });
|
|
16
|
+
}
|
|
17
|
+
function A({
|
|
18
|
+
messages: r,
|
|
19
|
+
components: t,
|
|
20
|
+
children: o
|
|
21
|
+
}) {
|
|
22
|
+
return /* @__PURE__ */ e(f, { children: /* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(
|
|
23
|
+
a,
|
|
24
|
+
{
|
|
25
|
+
components: t,
|
|
26
|
+
defaultComponents: c,
|
|
27
|
+
children: /* @__PURE__ */ e(d, { messages: r ?? [], children: o })
|
|
28
|
+
}
|
|
29
|
+
) }) });
|
|
7
30
|
}
|
|
8
31
|
export {
|
|
9
|
-
|
|
32
|
+
A as A2UIProvider
|
|
10
33
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useContext as x, createContext as C, useCallback as p, useMemo as f } from "react";
|
|
3
3
|
import { useDataModelContext as v } from "./DataModelContext.js";
|
|
4
4
|
import { resolveActionContext as A } from "../utils/dataBinding.js";
|
|
5
|
-
const s =
|
|
5
|
+
const s = C(null);
|
|
6
6
|
function P({ onAction: t, children: c }) {
|
|
7
7
|
const { getDataModel: o } = v(), e = p(
|
|
8
8
|
(n, a, r) => {
|
|
@@ -29,7 +29,7 @@ function P({ onAction: t, children: c }) {
|
|
|
29
29
|
return /* @__PURE__ */ m(s.Provider, { value: i, children: c });
|
|
30
30
|
}
|
|
31
31
|
function g() {
|
|
32
|
-
const t =
|
|
32
|
+
const t = x(s);
|
|
33
33
|
if (!t)
|
|
34
34
|
throw new Error("useActionContext must be used within an ActionProvider");
|
|
35
35
|
return t;
|
package/dist/0.8/index.d.ts
CHANGED
|
@@ -6,19 +6,38 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
9
|
-
* import { A2UIRenderer, A2UIMessage, A2UIAction } from '@easyops-cn/a2ui-react/0.8'
|
|
9
|
+
* import { A2UIProvider, A2UIRenderer, A2UIMessage, A2UIAction } from '@easyops-cn/a2ui-react/0.8'
|
|
10
10
|
*
|
|
11
11
|
* function App() {
|
|
12
12
|
* const messages: A2UIMessage[] = [...]
|
|
13
13
|
* const handleAction = (action: A2UIAction) => {
|
|
14
14
|
* console.log('Action:', action)
|
|
15
15
|
* }
|
|
16
|
-
* return
|
|
16
|
+
* return (
|
|
17
|
+
* <A2UIProvider messages={messages} onAction={handleAction}>
|
|
18
|
+
* <A2UIRenderer />
|
|
19
|
+
* </A2UIProvider>
|
|
20
|
+
* )
|
|
21
|
+
* }
|
|
22
|
+
*
|
|
23
|
+
* // With custom middleware component that uses hooks
|
|
24
|
+
* function AppWithMiddleware() {
|
|
25
|
+
* return (
|
|
26
|
+
* <A2UIProvider messages={messages} onAction={handleAction}>
|
|
27
|
+
* <MyCustomMiddleware>
|
|
28
|
+
* <A2UIRenderer />
|
|
29
|
+
* </MyCustomMiddleware>
|
|
30
|
+
* </A2UIProvider>
|
|
31
|
+
* )
|
|
17
32
|
* }
|
|
18
33
|
* ```
|
|
19
34
|
*/
|
|
20
35
|
export type { A2UIMessage, ActionPayload as A2UIAction, Action, ValueSource, } from './types';
|
|
36
|
+
export type { A2UIProviderProps, ComponentsMap } from './contexts/A2UIProvider';
|
|
37
|
+
export type { A2UIRendererProps } from './A2UIRenderer';
|
|
38
|
+
export { A2UIProvider } from './contexts/A2UIProvider';
|
|
21
39
|
export { A2UIRenderer } from './A2UIRenderer';
|
|
22
40
|
export { ComponentRenderer } from './components/ComponentRenderer';
|
|
23
41
|
export { useDispatchAction } from './hooks/useDispatchAction';
|
|
24
42
|
export { useDataBinding, useFormBinding } from './hooks/useDataBinding';
|
|
43
|
+
export { useA2UIMessageHandler } from './hooks/useA2UIMessageHandler';
|
package/dist/0.8/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { A2UIProvider as o } from "./contexts/A2UIProvider.js";
|
|
2
|
+
import { A2UIRenderer as t } from "./A2UIRenderer.js";
|
|
3
|
+
import { ComponentRenderer as p } from "./components/ComponentRenderer.js";
|
|
4
|
+
import { useDispatchAction as s } from "./hooks/useDispatchAction.js";
|
|
5
|
+
import { useDataBinding as f, useFormBinding as x } from "./hooks/useDataBinding.js";
|
|
6
|
+
import { useA2UIMessageHandler as u } from "./hooks/useA2UIMessageHandler.js";
|
|
5
7
|
export {
|
|
6
|
-
o as
|
|
7
|
-
t as
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
f as
|
|
8
|
+
o as A2UIProvider,
|
|
9
|
+
t as A2UIRenderer,
|
|
10
|
+
p as ComponentRenderer,
|
|
11
|
+
u as useA2UIMessageHandler,
|
|
12
|
+
f as useDataBinding,
|
|
13
|
+
s as useDispatchAction,
|
|
14
|
+
x as useFormBinding
|
|
11
15
|
};
|
package/package.json
CHANGED