@a2ui-sdk/react 0.2.2 → 0.3.1
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 +49 -1
- package/dist/0.8/components/interactive/CheckBoxComponent.js +21 -20
- package/dist/0.8/index.d.ts +1 -0
- package/dist/0.8/index.js +11 -8
- package/dist/0.9/components/interactive/CheckBoxComponent.js +27 -26
- package/dist/0.9/index.d.ts +1 -0
- package/dist/0.9/index.js +16 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @a2ui-sdk/react
|
|
2
2
|
|
|
3
|
-
React implementation for rendering A2UI protocol. This package provides React components and hooks for integrating A2UI
|
|
3
|
+
React implementation for rendering A2UI protocol. This package provides React components and hooks for integrating A2UI renderer into your application.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -221,6 +221,10 @@ import {
|
|
|
221
221
|
useScope,
|
|
222
222
|
useScopeBasePath,
|
|
223
223
|
|
|
224
|
+
// Context Providers & Hooks
|
|
225
|
+
ActionProvider,
|
|
226
|
+
useActionContext,
|
|
227
|
+
|
|
224
228
|
// Types
|
|
225
229
|
type A2UIMessage,
|
|
226
230
|
type A2UIAction,
|
|
@@ -265,6 +269,10 @@ import {
|
|
|
265
269
|
useScope,
|
|
266
270
|
useScopeBasePath,
|
|
267
271
|
|
|
272
|
+
// Context Providers & Hooks
|
|
273
|
+
ActionProvider,
|
|
274
|
+
useActionContext,
|
|
275
|
+
|
|
268
276
|
// Types
|
|
269
277
|
type A2UIMessage,
|
|
270
278
|
type A2UIAction,
|
|
@@ -332,6 +340,46 @@ const { valid, errors } = useValidation(checks)
|
|
|
332
340
|
// errors: string[] - list of failed validation messages
|
|
333
341
|
```
|
|
334
342
|
|
|
343
|
+
### ActionProvider & useActionContext
|
|
344
|
+
|
|
345
|
+
For advanced use cases, you can create custom action handling middleware by using `ActionProvider` and `useActionContext` directly. This is useful when you need to intercept, transform, or augment actions before they reach your action handler.
|
|
346
|
+
|
|
347
|
+
```tsx
|
|
348
|
+
import {
|
|
349
|
+
A2UIProvider,
|
|
350
|
+
A2UIRenderer,
|
|
351
|
+
ActionProvider,
|
|
352
|
+
useActionContext,
|
|
353
|
+
} from '@a2ui-sdk/react/0.9'
|
|
354
|
+
|
|
355
|
+
function ActionLogger({ children }: { children: React.ReactNode }) {
|
|
356
|
+
const { onAction } = useActionContext()
|
|
357
|
+
|
|
358
|
+
// You can access the action handler here
|
|
359
|
+
// and potentially wrap it with logging or other middleware logic
|
|
360
|
+
|
|
361
|
+
return <>{children}</>
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
function App() {
|
|
365
|
+
const handleAction = (action: A2UIAction) => {
|
|
366
|
+
console.log('Action:', action)
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return (
|
|
370
|
+
<A2UIProvider messages={messages}>
|
|
371
|
+
<ActionProvider onAction={handleAction}>
|
|
372
|
+
<ActionLogger>
|
|
373
|
+
<A2UIRenderer />
|
|
374
|
+
</ActionLogger>
|
|
375
|
+
</ActionProvider>
|
|
376
|
+
</A2UIProvider>
|
|
377
|
+
)
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
**Note:** In most cases, you don't need to use `ActionProvider` directly as `A2UIProvider` already includes it. Use this only for advanced customization scenarios.
|
|
382
|
+
|
|
335
383
|
## License
|
|
336
384
|
|
|
337
385
|
Apache-2.0
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { memo as
|
|
3
|
-
import { useDataBinding as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import { jsxs as p, jsx as m } from "react/jsx-runtime";
|
|
2
|
+
import { memo as x, useCallback as C } from "react";
|
|
3
|
+
import { useDataBinding as k, useFormBinding as d } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { useScopeBasePath as f } from "../../contexts/ScopeContext.js";
|
|
5
|
+
import { Checkbox as b } from "../../../components/ui/checkbox.js";
|
|
6
|
+
import { Label as g } from "../../../components/ui/label.js";
|
|
7
|
+
import { cn as u } from "../../../lib/utils.js";
|
|
8
|
+
const B = x(function({
|
|
8
9
|
surfaceId: e,
|
|
9
|
-
componentId:
|
|
10
|
-
label:
|
|
11
|
-
value:
|
|
10
|
+
componentId: o,
|
|
11
|
+
label: s,
|
|
12
|
+
value: a
|
|
12
13
|
}) {
|
|
13
|
-
const
|
|
14
|
-
(
|
|
15
|
-
|
|
14
|
+
const c = k(e, s, ""), [i, t] = d(e, a, !1), r = f(), h = C(
|
|
15
|
+
(l) => {
|
|
16
|
+
t(l);
|
|
16
17
|
},
|
|
17
|
-
[
|
|
18
|
-
),
|
|
19
|
-
return /* @__PURE__ */
|
|
20
|
-
/* @__PURE__ */
|
|
21
|
-
|
|
18
|
+
[t]
|
|
19
|
+
), n = r ? `checkbox-${o}-${r.replace(/\//g, "-")}` : `checkbox-${o}`;
|
|
20
|
+
return /* @__PURE__ */ p("div", { className: u("flex items-center gap-3"), children: [
|
|
21
|
+
/* @__PURE__ */ m(b, { id: n, checked: i, onCheckedChange: h }),
|
|
22
|
+
c && /* @__PURE__ */ m(g, { htmlFor: n, className: "cursor-pointer", children: c })
|
|
22
23
|
] });
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
+
B.displayName = "A2UI.CheckBox";
|
|
25
26
|
export {
|
|
26
|
-
|
|
27
|
+
B as CheckBoxComponent
|
|
27
28
|
};
|
package/dist/0.8/index.d.ts
CHANGED
|
@@ -44,3 +44,4 @@ export { useDispatchAction } from './hooks/useDispatchAction';
|
|
|
44
44
|
export { useDataBinding, useFormBinding } from './hooks/useDataBinding';
|
|
45
45
|
export { useSurfaceContext } from './contexts/SurfaceContext';
|
|
46
46
|
export { useDataModelContext } from './contexts/DataModelContext';
|
|
47
|
+
export { ActionProvider, useActionContext } from './contexts/ActionContext';
|
package/dist/0.8/index.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { A2UIProvider as r } from "./contexts/A2UIProvider.js";
|
|
2
2
|
import { A2UIRenderer as n } from "./A2UIRenderer.js";
|
|
3
3
|
import { ComponentRenderer as m } from "./components/ComponentRenderer.js";
|
|
4
|
-
import { standardCatalog as
|
|
5
|
-
import { useDispatchAction as
|
|
4
|
+
import { standardCatalog as a } from "./standard-catalog/index.js";
|
|
5
|
+
import { useDispatchAction as i } from "./hooks/useDispatchAction.js";
|
|
6
6
|
import { useDataBinding as s, useFormBinding as u } from "./hooks/useDataBinding.js";
|
|
7
|
-
import { useSurfaceContext as
|
|
8
|
-
import { useDataModelContext as
|
|
7
|
+
import { useSurfaceContext as A } from "./contexts/SurfaceContext.js";
|
|
8
|
+
import { useDataModelContext as g } from "./contexts/DataModelContext.js";
|
|
9
|
+
import { ActionProvider as l, useActionContext as v } from "./contexts/ActionContext.js";
|
|
9
10
|
export {
|
|
10
11
|
r as A2UIProvider,
|
|
11
12
|
n as A2UIRenderer,
|
|
13
|
+
l as ActionProvider,
|
|
12
14
|
m as ComponentRenderer,
|
|
13
|
-
|
|
15
|
+
a as standardCatalog,
|
|
16
|
+
v as useActionContext,
|
|
14
17
|
s as useDataBinding,
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
g as useDataModelContext,
|
|
19
|
+
i as useDispatchAction,
|
|
17
20
|
u as useFormBinding,
|
|
18
|
-
|
|
21
|
+
A as useSurfaceContext
|
|
19
22
|
};
|
|
@@ -1,45 +1,46 @@
|
|
|
1
1
|
import { jsxs as m, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import { memo as
|
|
3
|
-
import { useStringBinding as
|
|
4
|
-
import { useValidation as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
2
|
+
import { memo as u, useCallback as v } from "react";
|
|
3
|
+
import { useStringBinding as b, useFormBinding as B } from "../../hooks/useDataBinding.js";
|
|
4
|
+
import { useValidation as N } from "../../hooks/useValidation.js";
|
|
5
|
+
import { useScopeBasePath as $ } from "../../contexts/ScopeContext.js";
|
|
6
|
+
import { Checkbox as j } from "../../../components/ui/checkbox.js";
|
|
7
|
+
import { Label as y } from "../../../components/ui/label.js";
|
|
8
|
+
import { cn as F } from "../../../lib/utils.js";
|
|
9
|
+
const P = u(function({
|
|
9
10
|
surfaceId: o,
|
|
10
|
-
componentId:
|
|
11
|
-
label:
|
|
11
|
+
componentId: r,
|
|
12
|
+
label: h,
|
|
12
13
|
value: d,
|
|
13
|
-
checks:
|
|
14
|
-
weight:
|
|
14
|
+
checks: p,
|
|
15
|
+
weight: c
|
|
15
16
|
}) {
|
|
16
|
-
const
|
|
17
|
+
const i = b(o, h, ""), [x, n] = B(
|
|
17
18
|
o,
|
|
18
19
|
d,
|
|
19
20
|
!1
|
|
20
|
-
), { valid:
|
|
21
|
-
(
|
|
22
|
-
|
|
21
|
+
), { valid: f, errors: s } = N(o, p), a = $(), C = v(
|
|
22
|
+
(t) => {
|
|
23
|
+
n(t);
|
|
23
24
|
},
|
|
24
|
-
[
|
|
25
|
-
), l = `checkbox-${
|
|
26
|
-
return /* @__PURE__ */ m("div", { className:
|
|
25
|
+
[n]
|
|
26
|
+
), l = a ? `checkbox-${r}-${a.replace(/\//g, "-")}` : `checkbox-${r}`, k = c ? { flexGrow: c } : void 0;
|
|
27
|
+
return /* @__PURE__ */ m("div", { className: F("flex flex-col gap-1"), style: k, children: [
|
|
27
28
|
/* @__PURE__ */ m("div", { className: "flex items-center gap-3", children: [
|
|
28
29
|
/* @__PURE__ */ e(
|
|
29
|
-
|
|
30
|
+
j,
|
|
30
31
|
{
|
|
31
32
|
id: l,
|
|
32
|
-
checked:
|
|
33
|
-
onCheckedChange:
|
|
34
|
-
"aria-invalid": !
|
|
33
|
+
checked: x,
|
|
34
|
+
onCheckedChange: C,
|
|
35
|
+
"aria-invalid": !f
|
|
35
36
|
}
|
|
36
37
|
),
|
|
37
|
-
|
|
38
|
+
i && /* @__PURE__ */ e(y, { htmlFor: l, className: "cursor-pointer", children: i })
|
|
38
39
|
] }),
|
|
39
|
-
|
|
40
|
+
s.length > 0 && /* @__PURE__ */ e("div", { className: "text-sm text-destructive ml-6", children: s.map((t, g) => /* @__PURE__ */ e("p", { children: t }, g)) })
|
|
40
41
|
] });
|
|
41
42
|
});
|
|
42
|
-
|
|
43
|
+
P.displayName = "A2UI.CheckBox";
|
|
43
44
|
export {
|
|
44
|
-
|
|
45
|
+
P as CheckBoxComponent
|
|
45
46
|
};
|
package/dist/0.9/index.d.ts
CHANGED
|
@@ -34,3 +34,4 @@ export { useDataBinding, useFormBinding, useStringBinding, useDataModel, } from
|
|
|
34
34
|
export { useValidation } from './hooks/useValidation';
|
|
35
35
|
export { useSurfaceContext } from './contexts/SurfaceContext';
|
|
36
36
|
export { useScope, useScopeBasePath } from './contexts/ScopeContext';
|
|
37
|
+
export { ActionProvider, useActionContext } from './contexts/ActionContext';
|
package/dist/0.9/index.js
CHANGED
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { A2UIProvider as r } from "./contexts/A2UIProvider.js";
|
|
2
2
|
import { A2UIRenderer as n } from "./A2UIRenderer.js";
|
|
3
|
-
import { ComponentRenderer as
|
|
3
|
+
import { ComponentRenderer as a } from "./components/ComponentRenderer.js";
|
|
4
4
|
import { standardCatalog as s } from "./standard-catalog/index.js";
|
|
5
|
-
import { useDispatchAction as
|
|
6
|
-
import { useDataBinding as
|
|
7
|
-
import { useValidation as
|
|
8
|
-
import { useSurfaceContext as
|
|
9
|
-
import { useScope as D, useScopeBasePath as
|
|
5
|
+
import { useDispatchAction as x } from "./hooks/useDispatchAction.js";
|
|
6
|
+
import { useDataBinding as f, useDataModel as u, useFormBinding as c, useStringBinding as g } from "./hooks/useDataBinding.js";
|
|
7
|
+
import { useValidation as B } from "./hooks/useValidation.js";
|
|
8
|
+
import { useSurfaceContext as S } from "./contexts/SurfaceContext.js";
|
|
9
|
+
import { useScope as D, useScopeBasePath as P } from "./contexts/ScopeContext.js";
|
|
10
|
+
import { ActionProvider as v, useActionContext as I } from "./contexts/ActionContext.js";
|
|
10
11
|
export {
|
|
11
12
|
r as A2UIProvider,
|
|
12
13
|
n as A2UIRenderer,
|
|
13
|
-
|
|
14
|
+
v as ActionProvider,
|
|
15
|
+
a as ComponentRenderer,
|
|
14
16
|
s as standardCatalog,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
I as useActionContext,
|
|
18
|
+
f as useDataBinding,
|
|
19
|
+
u as useDataModel,
|
|
20
|
+
x as useDispatchAction,
|
|
18
21
|
c as useFormBinding,
|
|
19
22
|
D as useScope,
|
|
20
|
-
|
|
23
|
+
P as useScopeBasePath,
|
|
21
24
|
g as useStringBinding,
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
S as useSurfaceContext,
|
|
26
|
+
B as useValidation
|
|
24
27
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a2ui-sdk/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A2UI SDK for React",
|
|
5
5
|
"homepage": "https://a2ui-sdk.js.org/",
|
|
6
6
|
"repository": {
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"vitest": "^4.0.16"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"@a2ui-sdk/types": "0.
|
|
70
|
-
"@a2ui-sdk/utils": "0.
|
|
69
|
+
"@a2ui-sdk/types": "0.3.1",
|
|
70
|
+
"@a2ui-sdk/utils": "0.3.1",
|
|
71
71
|
"@radix-ui/react-checkbox": "^1.3.3",
|
|
72
72
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
73
73
|
"@radix-ui/react-label": "^2.1.8",
|