@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 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 surfaces into your application.
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 l, jsx as t } from "react/jsx-runtime";
2
- import { memo as p, useCallback as C } from "react";
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
- const g = p(function({
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: m,
10
- label: r,
11
- value: s
10
+ componentId: o,
11
+ label: s,
12
+ value: a
12
13
  }) {
13
- const o = d(e, r, ""), [i, n] = x(e, s, !1), a = C(
14
- (h) => {
15
- n(h);
14
+ const c = k(e, s, ""), [i, t] = d(e, a, !1), r = f(), h = C(
15
+ (l) => {
16
+ t(l);
16
17
  },
17
- [n]
18
- ), c = `checkbox-${m}`;
19
- return /* @__PURE__ */ l("div", { className: b("flex items-center gap-3"), children: [
20
- /* @__PURE__ */ t(k, { id: c, checked: i, onCheckedChange: a }),
21
- o && /* @__PURE__ */ t(f, { htmlFor: c, className: "cursor-pointer", children: o })
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
- g.displayName = "A2UI.CheckBox";
25
+ B.displayName = "A2UI.CheckBox";
25
26
  export {
26
- g as CheckBoxComponent
27
+ B as CheckBoxComponent
27
28
  };
@@ -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 x } from "./standard-catalog/index.js";
5
- import { useDispatchAction as d } from "./hooks/useDispatchAction.js";
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 c } from "./contexts/SurfaceContext.js";
8
- import { useDataModelContext as A } from "./contexts/DataModelContext.js";
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
- x as standardCatalog,
15
+ a as standardCatalog,
16
+ v as useActionContext,
14
17
  s as useDataBinding,
15
- A as useDataModelContext,
16
- d as useDispatchAction,
18
+ g as useDataModelContext,
19
+ i as useDispatchAction,
17
20
  u as useFormBinding,
18
- c as useSurfaceContext
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 v, useCallback as g } from "react";
3
- import { useStringBinding as u, useFormBinding as b } from "../../hooks/useDataBinding.js";
4
- import { useValidation as B } from "../../hooks/useValidation.js";
5
- import { Checkbox as N } from "../../../components/ui/checkbox.js";
6
- import { Label as j } from "../../../components/ui/label.js";
7
- import { cn as y } from "../../../lib/utils.js";
8
- const F = v(function({
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: s,
11
- label: a,
11
+ componentId: r,
12
+ label: h,
12
13
  value: d,
13
- checks: h,
14
- weight: t
14
+ checks: p,
15
+ weight: c
15
16
  }) {
16
- const r = u(o, a, ""), [p, i] = b(
17
+ const i = b(o, h, ""), [x, n] = B(
17
18
  o,
18
19
  d,
19
20
  !1
20
- ), { valid: x, errors: c } = B(o, h), f = g(
21
- (n) => {
22
- i(n);
21
+ ), { valid: f, errors: s } = N(o, p), a = $(), C = v(
22
+ (t) => {
23
+ n(t);
23
24
  },
24
- [i]
25
- ), l = `checkbox-${s}`, C = t ? { flexGrow: t } : void 0;
26
- return /* @__PURE__ */ m("div", { className: y("flex flex-col gap-1"), style: C, children: [
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
- N,
30
+ j,
30
31
  {
31
32
  id: l,
32
- checked: p,
33
- onCheckedChange: f,
34
- "aria-invalid": !x
33
+ checked: x,
34
+ onCheckedChange: C,
35
+ "aria-invalid": !f
35
36
  }
36
37
  ),
37
- r && /* @__PURE__ */ e(j, { htmlFor: l, className: "cursor-pointer", children: r })
38
+ i && /* @__PURE__ */ e(y, { htmlFor: l, className: "cursor-pointer", children: i })
38
39
  ] }),
39
- c.length > 0 && /* @__PURE__ */ e("div", { className: "text-sm text-destructive ml-6", children: c.map((n, k) => /* @__PURE__ */ e("p", { children: n }, k)) })
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
- F.displayName = "A2UI.CheckBox";
43
+ P.displayName = "A2UI.CheckBox";
43
44
  export {
44
- F as CheckBoxComponent
45
+ P as CheckBoxComponent
45
46
  };
@@ -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 p } from "./components/ComponentRenderer.js";
3
+ import { ComponentRenderer as a } from "./components/ComponentRenderer.js";
4
4
  import { standardCatalog as s } from "./standard-catalog/index.js";
5
- import { useDispatchAction as d } from "./hooks/useDispatchAction.js";
6
- import { useDataBinding as u, useDataModel as x, useFormBinding as c, useStringBinding as g } from "./hooks/useDataBinding.js";
7
- import { useValidation as S } from "./hooks/useValidation.js";
8
- import { useSurfaceContext as A } from "./contexts/SurfaceContext.js";
9
- import { useScope as D, useScopeBasePath as h } from "./contexts/ScopeContext.js";
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
- p as ComponentRenderer,
14
+ v as ActionProvider,
15
+ a as ComponentRenderer,
14
16
  s as standardCatalog,
15
- u as useDataBinding,
16
- x as useDataModel,
17
- d as useDispatchAction,
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
- h as useScopeBasePath,
23
+ P as useScopeBasePath,
21
24
  g as useStringBinding,
22
- A as useSurfaceContext,
23
- S as useValidation
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.2.2",
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.2.2",
70
- "@a2ui-sdk/utils": "0.2.2",
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",