@easyops-cn/a2ui-react 0.0.4 → 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 +15 -7
- package/dist/0.8/A2UIRenderer.d.ts +43 -35
- package/dist/0.8/A2UIRenderer.js +12 -34
- package/dist/0.8/components/display/AudioPlayerComponent.js +2 -2
- package/dist/0.8/components/display/DividerComponent.js +1 -1
- package/dist/0.8/components/display/IconComponent.js +2 -2
- package/dist/0.8/components/display/ImageComponent.js +2 -2
- package/dist/0.8/components/display/TextComponent.js +2 -2
- package/dist/0.8/components/display/VideoComponent.js +2 -2
- package/dist/0.8/components/interactive/ButtonComponent.js +2 -2
- package/dist/0.8/components/interactive/CheckBoxComponent.js +4 -4
- package/dist/0.8/components/interactive/DateTimeInputComponent.js +6 -6
- package/dist/0.8/components/interactive/MultipleChoiceComponent.js +5 -5
- package/dist/0.8/components/interactive/SliderComponent.js +3 -3
- package/dist/0.8/components/interactive/TextFieldComponent.js +5 -5
- package/dist/0.8/components/layout/CardComponent.js +1 -1
- package/dist/0.8/components/layout/ColumnComponent.js +3 -3
- package/dist/0.8/components/layout/ListComponent.js +3 -3
- package/dist/0.8/components/layout/ModalComponent.js +1 -1
- package/dist/0.8/components/layout/RowComponent.js +3 -3
- package/dist/0.8/components/layout/TabsComponent.js +2 -2
- package/dist/0.8/contexts/A2UIProvider.d.ts +40 -13
- package/dist/0.8/contexts/A2UIProvider.js +32 -7
- package/dist/0.8/hooks/useDataBinding.js +17 -12
- package/dist/0.8/index.d.ts +20 -2
- package/dist/0.8/index.js +13 -9
- package/dist/components/ui/button.js +53 -0
- package/dist/components/ui/calendar.js +173 -0
- package/dist/components/ui/card.js +29 -0
- package/dist/components/ui/checkbox.js +31 -0
- package/dist/components/ui/dialog.js +77 -0
- package/dist/components/ui/input.js +21 -0
- package/dist/components/ui/label.js +22 -0
- package/dist/components/ui/popover.js +38 -0
- package/dist/components/ui/select.js +144 -0
- package/dist/components/ui/separator.js +26 -0
- package/dist/components/ui/slider.js +63 -0
- package/dist/components/ui/tabs.js +67 -0
- package/dist/components/ui/textarea.js +18 -0
- package/dist/lib/utils.js +8 -0
- 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} 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
|
|
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
|
-
<
|
|
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
|
-
*
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* <
|
|
43
|
+
* <A2UIProvider messages={messages} onAction={handleAction}>
|
|
44
|
+
* <A2UIRenderer />
|
|
45
|
+
* </A2UIProvider>
|
|
33
46
|
*
|
|
34
|
-
* // With custom
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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(
|
|
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
|
}
|
package/dist/0.8/A2UIRenderer.js
CHANGED
|
@@ -1,40 +1,18 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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:
|
|
18
|
-
componentId:
|
|
9
|
+
surfaceId: e,
|
|
10
|
+
componentId: n.root
|
|
19
11
|
},
|
|
20
|
-
|
|
12
|
+
e
|
|
21
13
|
) : null) });
|
|
22
14
|
}
|
|
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";
|
|
15
|
+
f.displayName = "A2UI.Renderer";
|
|
38
16
|
export {
|
|
39
|
-
|
|
17
|
+
f as A2UIRenderer
|
|
40
18
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as s, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as m } from "react";
|
|
3
|
-
import { useDataBinding as n } from "
|
|
4
|
-
import { cn as a } from "
|
|
3
|
+
import { useDataBinding as n } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as a } from "../../../lib/utils.js";
|
|
5
5
|
const u = m(function({
|
|
6
6
|
surfaceId: o,
|
|
7
7
|
url: i,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import { memo as t } from "react";
|
|
3
|
-
import { Separator as e } from "
|
|
3
|
+
import { Separator as e } from "../../../components/ui/separator.js";
|
|
4
4
|
const i = t(function({
|
|
5
5
|
axis: o = "horizontal"
|
|
6
6
|
}) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as i } from "react";
|
|
3
|
-
import { useDataBinding as l } from "
|
|
3
|
+
import { useDataBinding as l } from "../../hooks/useDataBinding.js";
|
|
4
4
|
import { AlertTriangle as c, EyeOff as f, Eye as s, Upload as m, StarOff as p, StarHalf as d, Star as h, ShoppingCart as C, Share2 as u, Settings as w, Send as O, Search as g, RefreshCw as k, Printer as y, Image as H, Phone as o, User as I, CreditCard as S, Bell as U, BellOff as A, MoreHorizontal as M, MoreVertical as P, Menu as v, Mail as B, Unlock as D, Lock as F, MapPin as N, Info as T, Home as b, HelpCircle as x, Folder as z, HeartOff as E, Heart as L, AlertCircle as R, CalendarDays as V, Pencil as j, Download as X, Trash2 as $, X as q, Check as G, Camera as J, Calendar as K, Paperclip as Q, ArrowRight as W, ArrowLeft as Y, Plus as Z, UserCircle as _ } from "lucide-react";
|
|
5
|
-
import { cn as ee } from "
|
|
5
|
+
import { cn as ee } from "../../../lib/utils.js";
|
|
6
6
|
const re = {
|
|
7
7
|
accountCircle: _,
|
|
8
8
|
add: Z,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import { memo as m } from "react";
|
|
3
|
-
import { useDataBinding as i } from "
|
|
4
|
-
import { cn as s } from "
|
|
3
|
+
import { useDataBinding as i } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as s } from "../../../lib/utils.js";
|
|
5
5
|
const t = {
|
|
6
6
|
contain: "object-contain",
|
|
7
7
|
cover: "object-cover",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as h } from "react/jsx-runtime";
|
|
2
2
|
import { memo as x } from "react";
|
|
3
|
-
import { useDataBinding as l } from "
|
|
4
|
-
import { cn as r } from "
|
|
3
|
+
import { useDataBinding as l } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as r } from "../../../lib/utils.js";
|
|
5
5
|
const o = {
|
|
6
6
|
h1: "text-3xl font-bold tracking-tight",
|
|
7
7
|
h2: "text-2xl font-semibold tracking-tight",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as t, jsx as n } from "react/jsx-runtime";
|
|
2
2
|
import { memo as i } from "react";
|
|
3
|
-
import { useDataBinding as s } from "
|
|
4
|
-
import { cn as m } from "
|
|
3
|
+
import { useDataBinding as s } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as m } from "../../../lib/utils.js";
|
|
5
5
|
const d = i(function({
|
|
6
6
|
surfaceId: r,
|
|
7
7
|
url: e
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as m } from "react/jsx-runtime";
|
|
2
2
|
import { memo as p, useCallback as s } from "react";
|
|
3
|
-
import { useDispatchAction as c } from "
|
|
4
|
-
import { Button as u } from "
|
|
3
|
+
import { useDispatchAction as c } from "../../hooks/useDispatchAction.js";
|
|
4
|
+
import { Button as u } from "../../../components/ui/button.js";
|
|
5
5
|
import { ComponentRenderer as a } from "../ComponentRenderer.js";
|
|
6
6
|
const f = p(function({
|
|
7
7
|
surfaceId: t,
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsxs as l, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as p, useCallback as C } from "react";
|
|
3
|
-
import { useDataBinding as d, useFormBinding as x } from "
|
|
4
|
-
import { Checkbox as k } from "
|
|
5
|
-
import { Label as f } from "
|
|
6
|
-
import { cn as b } from "
|
|
3
|
+
import { useDataBinding as d, useFormBinding as x } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { Checkbox as k } from "../../../components/ui/checkbox.js";
|
|
5
|
+
import { Label as f } from "../../../components/ui/label.js";
|
|
6
|
+
import { cn as b } from "../../../lib/utils.js";
|
|
7
7
|
const g = p(function({
|
|
8
8
|
surfaceId: e,
|
|
9
9
|
componentId: m,
|
|
@@ -2,12 +2,12 @@ import { jsx as i, jsxs as f } from "react/jsx-runtime";
|
|
|
2
2
|
import { memo as V, useMemo as l, useCallback as M } from "react";
|
|
3
3
|
import { CalendarIcon as j } from "lucide-react";
|
|
4
4
|
import { parse as p, isValid as P, format as m } from "date-fns";
|
|
5
|
-
import { useFormBinding as B } from "
|
|
6
|
-
import { cn as y } from "
|
|
7
|
-
import { Button as F } from "
|
|
8
|
-
import { Calendar as S } from "
|
|
9
|
-
import { Popover as k, PopoverTrigger as A, PopoverContent as L } from "
|
|
10
|
-
import { Input as g } from "
|
|
5
|
+
import { useFormBinding as B } from "../../hooks/useDataBinding.js";
|
|
6
|
+
import { cn as y } from "../../../lib/utils.js";
|
|
7
|
+
import { Button as F } from "../../../components/ui/button.js";
|
|
8
|
+
import { Calendar as S } from "../../../components/ui/calendar.js";
|
|
9
|
+
import { Popover as k, PopoverTrigger as A, PopoverContent as L } from "../../../components/ui/popover.js";
|
|
10
|
+
import { Input as g } from "../../../components/ui/input.js";
|
|
11
11
|
const U = V(function({
|
|
12
12
|
surfaceId: v,
|
|
13
13
|
componentId: w,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as r, jsxs as g, Fragment as M } from "react/jsx-runtime";
|
|
2
2
|
import { memo as N, useCallback as p } from "react";
|
|
3
|
-
import { useFormBinding as V, useDataBinding as S } from "
|
|
4
|
-
import { Select as F, SelectTrigger as $, SelectValue as j, SelectContent as B, SelectItem as D } from "
|
|
5
|
-
import { Checkbox as L } from "
|
|
6
|
-
import { Label as T } from "
|
|
7
|
-
import { cn as h } from "
|
|
3
|
+
import { useFormBinding as V, useDataBinding as S } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { Select as F, SelectTrigger as $, SelectValue as j, SelectContent as B, SelectItem as D } from "../../../components/ui/select.js";
|
|
5
|
+
import { Checkbox as L } from "../../../components/ui/checkbox.js";
|
|
6
|
+
import { Label as T } from "../../../components/ui/label.js";
|
|
7
|
+
import { cn as h } from "../../../lib/utils.js";
|
|
8
8
|
const A = N(function({
|
|
9
9
|
surfaceId: a,
|
|
10
10
|
componentId: o,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as l, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import { memo as a, useCallback as c } from "react";
|
|
3
|
-
import { useFormBinding as p } from "
|
|
4
|
-
import { Slider as f } from "
|
|
5
|
-
import { cn as h } from "
|
|
3
|
+
import { useFormBinding as p } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { Slider as f } from "../../../components/ui/slider.js";
|
|
5
|
+
import { cn as h } from "../../../lib/utils.js";
|
|
6
6
|
const u = a(function({
|
|
7
7
|
surfaceId: m,
|
|
8
8
|
value: s,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsxs as u, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as T, useCallback as f } from "react";
|
|
3
|
-
import { useDataBinding as g, useFormBinding as h } from "
|
|
4
|
-
import { Input as b } from "
|
|
5
|
-
import { Textarea as C } from "
|
|
6
|
-
import { Label as F } from "
|
|
7
|
-
import { cn as v } from "
|
|
3
|
+
import { useDataBinding as g, useFormBinding as h } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { Input as b } from "../../../components/ui/input.js";
|
|
5
|
+
import { Textarea as C } from "../../../components/ui/textarea.js";
|
|
6
|
+
import { Label as F } from "../../../components/ui/label.js";
|
|
7
|
+
import { cn as v } from "../../../lib/utils.js";
|
|
8
8
|
const y = {
|
|
9
9
|
shortText: "text",
|
|
10
10
|
longText: "text",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as r } from "react/jsx-runtime";
|
|
2
2
|
import { memo as m } from "react";
|
|
3
|
-
import { Card as n, CardContent as t } from "
|
|
3
|
+
import { Card as n, CardContent as t } from "../../../components/ui/card.js";
|
|
4
4
|
import { ComponentRenderer as p } from "../ComponentRenderer.js";
|
|
5
5
|
const a = m(function({
|
|
6
6
|
surfaceId: e,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as u } from "react";
|
|
3
|
-
import { useDataModel as d } from "
|
|
4
|
-
import { cn as y } from "
|
|
5
|
-
import { getValueByPath as j } from "
|
|
3
|
+
import { useDataModel as d } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as y } from "../../../lib/utils.js";
|
|
5
|
+
import { getValueByPath as j } from "../../utils/pathUtils.js";
|
|
6
6
|
import { ComponentRenderer as r } from "../ComponentRenderer.js";
|
|
7
7
|
const v = {
|
|
8
8
|
start: "justify-start",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as d } from "react";
|
|
3
|
-
import { useDataModel as x } from "
|
|
4
|
-
import { cn as u } from "
|
|
5
|
-
import { getValueByPath as v } from "
|
|
3
|
+
import { useDataModel as x } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as u } from "../../../lib/utils.js";
|
|
5
|
+
import { getValueByPath as v } from "../../utils/pathUtils.js";
|
|
6
6
|
import { ComponentRenderer as r } from "../ComponentRenderer.js";
|
|
7
7
|
const L = {
|
|
8
8
|
start: "items-start",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as p, jsx as o } from "react/jsx-runtime";
|
|
2
2
|
import { memo as l, useState as a } from "react";
|
|
3
|
-
import { Dialog as s, DialogTrigger as d, DialogContent as c } from "
|
|
3
|
+
import { Dialog as s, DialogTrigger as d, DialogContent as c } from "../../../components/ui/dialog.js";
|
|
4
4
|
import { ComponentRenderer as t } from "../ComponentRenderer.js";
|
|
5
5
|
const f = l(function({
|
|
6
6
|
surfaceId: e,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { memo as l } from "react";
|
|
3
|
-
import { useDataModel as u } from "
|
|
4
|
-
import { cn as y } from "
|
|
5
|
-
import { getValueByPath as j } from "
|
|
3
|
+
import { useDataModel as u } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { cn as y } from "../../../lib/utils.js";
|
|
5
|
+
import { getValueByPath as j } from "../../utils/pathUtils.js";
|
|
6
6
|
import { ComponentRenderer as r } from "../ComponentRenderer.js";
|
|
7
7
|
const v = {
|
|
8
8
|
start: "justify-start",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as a, jsx as o, Fragment as c } from "react/jsx-runtime";
|
|
2
2
|
import { memo as d } from "react";
|
|
3
|
-
import { useDataBinding as m } from "
|
|
4
|
-
import { Tabs as p, TabsList as s, TabsTrigger as T, TabsContent as h } from "
|
|
3
|
+
import { useDataBinding as m } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { Tabs as p, TabsList as s, TabsTrigger as T, TabsContent as h } from "../../../components/ui/tabs.js";
|
|
5
5
|
import { ComponentRenderer as u } from "../ComponentRenderer.js";
|
|
6
6
|
const f = d(function({
|
|
7
7
|
surfaceId: r,
|
|
@@ -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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
34
|
+
x as A2UIProvider
|
|
10
35
|
};
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
import { useDataModelContext as
|
|
3
|
-
import { resolveValue as
|
|
1
|
+
import { useMemo as i } from "react";
|
|
2
|
+
import { useDataModelContext as l } from "../contexts/DataModelContext.js";
|
|
3
|
+
import { resolveValue as m } from "../utils/dataBinding.js";
|
|
4
4
|
function s(n, t, o) {
|
|
5
|
-
const { getDataModel: e } =
|
|
6
|
-
return
|
|
5
|
+
const { getDataModel: e } = l();
|
|
6
|
+
return i(() => {
|
|
7
7
|
const a = e(n);
|
|
8
|
-
return
|
|
8
|
+
return m(t, a, o);
|
|
9
9
|
}, [e, n, t, o]);
|
|
10
10
|
}
|
|
11
|
+
function u(n) {
|
|
12
|
+
const { getDataModel: t } = l();
|
|
13
|
+
return i(() => t(n), [t, n]);
|
|
14
|
+
}
|
|
11
15
|
function h(n, t, o) {
|
|
12
|
-
const { getDataModel: e, setDataValue: a } =
|
|
13
|
-
const
|
|
14
|
-
return
|
|
15
|
-
}, [e, n, t, o]),
|
|
16
|
-
t && "path" in t && a(n, t.path,
|
|
16
|
+
const { getDataModel: e, setDataValue: a } = l(), M = i(() => {
|
|
17
|
+
const r = e(n);
|
|
18
|
+
return m(t, r, o);
|
|
19
|
+
}, [e, n, t, o]), D = i(() => (r) => {
|
|
20
|
+
t && "path" in t && a(n, t.path, r);
|
|
17
21
|
}, [a, n, t]);
|
|
18
|
-
return [
|
|
22
|
+
return [M, D];
|
|
19
23
|
}
|
|
20
24
|
export {
|
|
21
25
|
s as useDataBinding,
|
|
26
|
+
u as useDataModel,
|
|
22
27
|
h as useFormBinding
|
|
23
28
|
};
|
package/dist/0.8/index.d.ts
CHANGED
|
@@ -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
|
|
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';
|