@easyops-cn/a2ui-react 0.0.5 → 0.0.6

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 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 the `A2UIRenderer` component to render A2UI messages:
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 <A2UIRenderer messages={messages} onAction={handleAction} />
42
+ return (
43
+ <A2UIProvider messages={messages} onAction={handleAction}>
44
+ <A2UIRenderer />
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, which takes a `Map<string, React.ComponentType>`.
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,13 @@ const ComponentsMap = new Map<string, React.ComponentType<any>>([
63
69
 
64
70
  function App() {
65
71
  return (
66
- <A2UIRenderer
72
+ <A2UIProvider
67
73
  components={ComponentsMap}
68
74
  messages={messages}
69
75
  onAction={handleAction}
70
- />
76
+ >
77
+ <A2UIRenderer />
78
+ </A2UIProvider>
71
79
  )
72
80
  }
73
81
  ```
@@ -1,49 +1,57 @@
1
- import { ComponentType } from 'react';
2
- import { A2UIMessage, ActionPayload, BaseComponentProps } from './types';
3
1
  /**
4
- * Type for custom component map.
5
- */
6
- export type ComponentsMap = Map<string, ComponentType<BaseComponentProps & Record<string, unknown>>>;
7
- /**
8
- * Props for A2UIRenderer component.
2
+ * A2UIRenderer - Component for rendering A2UI surfaces.
3
+ *
4
+ * This component renders the surfaces from the A2UI context.
5
+ * It must be used within an A2UIProvider.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { A2UIProvider, A2UIRenderer, A2UIMessage, A2UIAction } from '@easyops-cn/a2ui-react/0.8'
10
+ *
11
+ * function App() {
12
+ * const messages: A2UIMessage[] = [...]
13
+ * const handleAction = (action: A2UIAction) => {
14
+ * console.log('Action:', action)
15
+ * }
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
+ * )
32
+ * }
33
+ * ```
9
34
  */
10
- export interface A2UIRenderProps {
11
- /** Array of A2UI messages to render */
12
- messages: A2UIMessage[];
13
- /** Callback when an action is dispatched */
14
- onAction?: (action: ActionPayload) => void;
15
- /** Custom component overrides */
16
- components?: ComponentsMap;
17
- }
18
35
  /**
19
- * Main entry component for rendering A2UI messages.
20
- *
21
- * Processes an array of A2UIMessage objects and renders the resulting UI.
22
- * Supports custom component overrides via the components prop.
36
+ * Component for rendering A2UI surfaces.
23
37
  *
24
- * @param props - Component props
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
38
+ * Renders all surfaces from the A2UI context. Must be used within an A2UIProvider.
28
39
  *
29
40
  * @example
30
41
  * ```tsx
31
42
  * // Basic usage
32
- * <A2UIRenderer messages={messages} onAction={handleAction} />
43
+ * <A2UIProvider messages={messages} onAction={handleAction}>
44
+ * <A2UIRenderer />
45
+ * </A2UIProvider>
33
46
  *
34
- * // With custom components
35
- * const customComponents = new Map([
36
- * ['Button', CustomButton],
37
- * ['Switch', CustomSwitch],
38
- * ])
39
- * <A2UIRenderer
40
- * messages={messages}
41
- * onAction={handleAction}
42
- * components={customComponents}
43
- * />
47
+ * // With custom middleware for hooks access
48
+ * <A2UIProvider messages={messages} onAction={handleAction}>
49
+ * <MyCustomComponent />
50
+ * <A2UIRenderer />
51
+ * </A2UIProvider>
44
52
  * ```
45
53
  */
46
- export declare function A2UIRenderer({ messages, onAction, components, }: A2UIRenderProps): import("react/jsx-runtime").JSX.Element;
54
+ export declare function A2UIRenderer(): import("react/jsx-runtime").JSX.Element | null;
47
55
  export declare namespace A2UIRenderer {
48
56
  var displayName: string;
49
57
  }
@@ -1,40 +1,18 @@
1
- import { jsx as e, Fragment as f } from "react/jsx-runtime";
2
- import { useEffect as p } from "react";
3
- import { A2UIProvider as c } from "./contexts/A2UIProvider.js";
4
- import { ComponentsMapProvider as a } from "./contexts/ComponentsMapContext.js";
5
- import { useSurfaceContext as u } from "./contexts/SurfaceContext.js";
6
- import { useA2UIMessageHandler as l } from "./hooks/useA2UIMessageHandler.js";
7
- import { componentRegistry as d, ComponentRenderer as g } from "./components/ComponentRenderer.js";
8
- function A({ messages: r }) {
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 t, Fragment as m } from "react/jsx-runtime";
2
+ import { useSurfaceContext as i } from "./contexts/SurfaceContext.js";
3
+ import { ComponentRenderer as u } from "./components/ComponentRenderer.js";
4
+ function f() {
5
+ const { surfaces: o } = i(), r = Array.from(o.entries());
6
+ return r.length === 0 ? null : /* @__PURE__ */ t(m, { children: r.map(([e, n]) => n.root ? /* @__PURE__ */ t(
7
+ u,
16
8
  {
17
- surfaceId: i,
18
- componentId: m.root
9
+ surfaceId: e,
10
+ componentId: n.root
19
11
  },
20
- i
12
+ e
21
13
  ) : null) });
22
14
  }
23
- function I({
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";
15
+ f.displayName = "A2UI.Renderer";
38
16
  export {
39
- I as A2UIRenderer
17
+ f as A2UIRenderer
40
18
  };
@@ -1,11 +1,19 @@
1
- import { ReactNode } from 'react';
2
- import { ActionHandler } from '../types';
1
+ import { ReactNode, ComponentType } from 'react';
2
+ import { ActionHandler, 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 {
11
+ /** Array of A2UI messages to render */
12
+ messages: A2UIMessage[];
7
13
  /** Callback when an action is dispatched */
8
14
  onAction?: ActionHandler;
15
+ /** Custom component overrides */
16
+ components?: ComponentsMap;
9
17
  children: ReactNode;
10
18
  }
11
19
  /**
@@ -15,20 +23,39 @@ export interface A2UIProviderProps {
15
23
  * - SurfaceContext: Component tree management
16
24
  * - DataModelContext: Data model state
17
25
  * - ActionContext: Action dispatching
26
+ * - ComponentsMapContext: Custom component overrides
27
+ *
28
+ * @param props - Component props
29
+ * @param props.messages - Array of A2UI messages to render
30
+ * @param props.onAction - Optional callback when an action is dispatched
31
+ * @param props.components - Optional custom component overrides
32
+ * @param props.children - Child components (typically A2UIRenderer)
18
33
  *
19
34
  * @example
20
35
  * ```tsx
21
- * function App() {
22
- * const handleAction = (action) => {
23
- * console.log('Action:', action);
24
- * };
36
+ * // Basic usage
37
+ * <A2UIProvider messages={messages} onAction={handleAction}>
38
+ * <A2UIRenderer />
39
+ * </A2UIProvider>
40
+ *
41
+ * // With custom components
42
+ * const customComponents = new Map([
43
+ * ['Button', CustomButton],
44
+ * ['Switch', CustomSwitch],
45
+ * ])
46
+ * <A2UIProvider
47
+ * messages={messages}
48
+ * onAction={handleAction}
49
+ * components={customComponents}
50
+ * >
51
+ * <A2UIRenderer />
52
+ * </A2UIProvider>
25
53
  *
26
- * return (
27
- * <A2UIProvider onAction={handleAction}>
28
- * <A2UIReactRenderer messages={messages} />
29
- * </A2UIProvider>
30
- * );
31
- * }
54
+ * // With custom middleware for hooks access
55
+ * <A2UIProvider messages={messages} onAction={handleAction}>
56
+ * <MyCustomComponent />
57
+ * <A2UIRenderer />
58
+ * </A2UIProvider>
32
59
  * ```
33
60
  */
34
- export declare function A2UIProvider({ onAction, children }: A2UIProviderProps): import("react/jsx-runtime").JSX.Element;
61
+ export declare function A2UIProvider({ messages, onAction, components, children, }: A2UIProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,35 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { SurfaceProvider as e } from "./SurfaceContext.js";
3
- import { DataModelProvider as t } from "./DataModelContext.js";
4
- import { ActionProvider as m } from "./ActionContext.js";
5
- function p({ onAction: o, children: i }) {
6
- return /* @__PURE__ */ r(e, { children: /* @__PURE__ */ r(t, { children: /* @__PURE__ */ r(m, { onAction: o, children: i }) }) });
1
+ import { jsx as o, Fragment as n } from "react/jsx-runtime";
2
+ import { useEffect as s } from "react";
3
+ import { SurfaceProvider as m } from "./SurfaceContext.js";
4
+ import { DataModelProvider as f } from "./DataModelContext.js";
5
+ import { ActionProvider as c } from "./ActionContext.js";
6
+ import { ComponentsMapProvider as p } from "./ComponentsMapContext.js";
7
+ import { componentRegistry as a } from "../components/ComponentRenderer.js";
8
+ import { useA2UIMessageHandler as d } from "../hooks/useA2UIMessageHandler.js";
9
+ function l({
10
+ messages: r,
11
+ children: i
12
+ }) {
13
+ const { processMessages: e, clear: t } = d();
14
+ return s(() => {
15
+ t(), r && r.length > 0 && e(r);
16
+ }, [r, e, t]), /* @__PURE__ */ o(n, { children: i });
17
+ }
18
+ function x({
19
+ messages: r,
20
+ onAction: i,
21
+ components: e,
22
+ children: t
23
+ }) {
24
+ return /* @__PURE__ */ o(m, { children: /* @__PURE__ */ o(f, { children: /* @__PURE__ */ o(c, { onAction: i, children: /* @__PURE__ */ o(
25
+ p,
26
+ {
27
+ components: e,
28
+ defaultComponents: a,
29
+ children: /* @__PURE__ */ o(l, { messages: r ?? [], children: t })
30
+ }
31
+ ) }) }) });
7
32
  }
8
33
  export {
9
- p as A2UIProvider
34
+ x as A2UIProvider
10
35
  };
@@ -6,19 +6,37 @@
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 <A2UIRenderer messages={messages} onAction={handleAction} />
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 { A2UIProvider } from './contexts/A2UIProvider';
21
38
  export { A2UIRenderer } from './A2UIRenderer';
22
39
  export { ComponentRenderer } from './components/ComponentRenderer';
23
40
  export { useDispatchAction } from './hooks/useDispatchAction';
24
41
  export { useDataBinding, useFormBinding } from './hooks/useDataBinding';
42
+ export { useA2UIMessageHandler } from './hooks/useA2UIMessageHandler';
package/dist/0.8/index.js CHANGED
@@ -1,11 +1,15 @@
1
- import { A2UIRenderer as o } from "./A2UIRenderer.js";
2
- import { ComponentRenderer as t } from "./components/ComponentRenderer.js";
3
- import { useDispatchAction as m } from "./hooks/useDispatchAction.js";
4
- import { useDataBinding as d, useFormBinding as f } from "./hooks/useDataBinding.js";
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 A2UIRenderer,
7
- t as ComponentRenderer,
8
- d as useDataBinding,
9
- m as useDispatchAction,
10
- f as useFormBinding
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/a2ui-react",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A2UI React Renderer",
5
5
  "homepage": "https://easyops-cn.github.io/a2ui-react/",
6
6
  "repository": {
@@ -1,6 +0,0 @@
1
- /**
2
- * A2UIRenderer Tests
3
- *
4
- * Tests for the main A2UIRenderer component.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * ComponentRenderer Tests
3
- *
4
- * Tests for the ComponentRenderer component that routes rendering based on type.
5
- */
6
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Display Components Tests
3
- *
4
- * Tests for TextComponent, ImageComponent, IconComponent, VideoComponent,
5
- * AudioPlayerComponent, and DividerComponent.
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Interactive Components Tests
3
- *
4
- * Tests for ButtonComponent, CheckBoxComponent, TextFieldComponent,
5
- * DateTimeInputComponent, MultipleChoiceComponent, and SliderComponent.
6
- */
7
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Layout Components Tests
3
- *
4
- * Tests for RowComponent, ColumnComponent, ListComponent, CardComponent,
5
- * TabsComponent, and ModalComponent.
6
- */
7
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * A2UIProvider Tests
3
- *
4
- * Tests for the combined A2UI provider component.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * ActionContext Tests
3
- *
4
- * Tests for the Action context provider and hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * DataModelContext Tests
3
- *
4
- * Tests for the DataModel context provider and hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * SurfaceContext Tests
3
- *
4
- * Tests for the Surface context provider and hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * useA2UIMessageHandler Tests
3
- *
4
- * Tests for the useA2UIMessageHandler hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * useComponent Tests
3
- *
4
- * Tests for the useComponent hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * useDataBinding Tests
3
- *
4
- * Tests for the useDataBinding, useDataModel, and useFormBinding hooks.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * useDispatchAction Tests
3
- *
4
- * Tests for the useDispatchAction hooks.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * useSurface Tests
3
- *
4
- * Tests for the useSurface hook.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * dataBinding Tests
3
- *
4
- * Tests for data binding utility functions used in A2UI.
5
- */
6
- export {};
@@ -1,6 +0,0 @@
1
- /**
2
- * pathUtils Tests
3
- *
4
- * Tests for path utility functions used in A2UI data model operations.
5
- */
6
- export {};