@a2ui-sdk/react 0.0.0

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.
Files changed (174) hide show
  1. package/dist/0.8/A2UIRenderer.d.ts +31 -0
  2. package/dist/0.8/A2UIRenderer.js +19 -0
  3. package/dist/0.8/components/ComponentRenderer.d.ts +39 -0
  4. package/dist/0.8/components/ComponentRenderer.js +76 -0
  5. package/dist/0.8/components/UnknownComponent.d.ts +18 -0
  6. package/dist/0.8/components/display/AudioPlayerComponent.d.ts +5 -0
  7. package/dist/0.8/components/display/AudioPlayerComponent.js +19 -0
  8. package/dist/0.8/components/display/DividerComponent.d.ts +5 -0
  9. package/dist/0.8/components/display/DividerComponent.js +18 -0
  10. package/dist/0.8/components/display/IconComponent.d.ts +5 -0
  11. package/dist/0.8/components/display/IconComponent.js +68 -0
  12. package/dist/0.8/components/display/ImageComponent.d.ts +6 -0
  13. package/dist/0.8/components/display/ImageComponent.js +36 -0
  14. package/dist/0.8/components/display/TextComponent.d.ts +6 -0
  15. package/dist/0.8/components/display/TextComponent.js +32 -0
  16. package/dist/0.8/components/display/VideoComponent.d.ts +5 -0
  17. package/dist/0.8/components/display/VideoComponent.js +18 -0
  18. package/dist/0.8/components/display/index.d.ts +9 -0
  19. package/dist/0.8/components/index.d.ts +7 -0
  20. package/dist/0.8/components/interactive/ButtonComponent.d.ts +5 -0
  21. package/dist/0.8/components/interactive/ButtonComponent.js +29 -0
  22. package/dist/0.8/components/interactive/CheckBoxComponent.d.ts +5 -0
  23. package/dist/0.8/components/interactive/CheckBoxComponent.js +27 -0
  24. package/dist/0.8/components/interactive/DateTimeInputComponent.d.ts +5 -0
  25. package/dist/0.8/components/interactive/DateTimeInputComponent.js +46 -0
  26. package/dist/0.8/components/interactive/MultipleChoiceComponent.d.ts +7 -0
  27. package/dist/0.8/components/interactive/MultipleChoiceComponent.js +89 -0
  28. package/dist/0.8/components/interactive/SliderComponent.d.ts +5 -0
  29. package/dist/0.8/components/interactive/SliderComponent.js +48 -0
  30. package/dist/0.8/components/interactive/TextFieldComponent.d.ts +5 -0
  31. package/dist/0.8/components/interactive/TextFieldComponent.js +44 -0
  32. package/dist/0.8/components/interactive/index.d.ts +9 -0
  33. package/dist/0.8/components/layout/CardComponent.d.ts +5 -0
  34. package/dist/0.8/components/layout/CardComponent.js +14 -0
  35. package/dist/0.8/components/layout/ColumnComponent.d.ts +5 -0
  36. package/dist/0.8/components/layout/ColumnComponent.js +58 -0
  37. package/dist/0.8/components/layout/ListComponent.d.ts +5 -0
  38. package/dist/0.8/components/layout/ListComponent.js +51 -0
  39. package/dist/0.8/components/layout/ModalComponent.d.ts +5 -0
  40. package/dist/0.8/components/layout/ModalComponent.js +25 -0
  41. package/dist/0.8/components/layout/RowComponent.d.ts +5 -0
  42. package/dist/0.8/components/layout/RowComponent.js +58 -0
  43. package/dist/0.8/components/layout/TabsComponent.d.ts +5 -0
  44. package/dist/0.8/components/layout/TabsComponent.js +29 -0
  45. package/dist/0.8/components/layout/index.d.ts +9 -0
  46. package/dist/0.8/contexts/A2UIProvider.d.ts +56 -0
  47. package/dist/0.8/contexts/A2UIProvider.js +33 -0
  48. package/dist/0.8/contexts/ActionContext.d.ts +33 -0
  49. package/dist/0.8/contexts/ActionContext.js +41 -0
  50. package/dist/0.8/contexts/ComponentsMapContext.d.ts +63 -0
  51. package/dist/0.8/contexts/ComponentsMapContext.js +21 -0
  52. package/dist/0.8/contexts/DataModelContext.d.ts +43 -0
  53. package/dist/0.8/contexts/DataModelContext.js +86 -0
  54. package/dist/0.8/contexts/SurfaceContext.d.ts +45 -0
  55. package/dist/0.8/contexts/SurfaceContext.js +88 -0
  56. package/dist/0.8/hooks/useA2UIMessageHandler.d.ts +41 -0
  57. package/dist/0.8/hooks/useA2UIMessageHandler.js +54 -0
  58. package/dist/0.8/hooks/useComponent.d.ts +23 -0
  59. package/dist/0.8/hooks/useComponent.js +9 -0
  60. package/dist/0.8/hooks/useDataBinding.d.ts +50 -0
  61. package/dist/0.8/hooks/useDataBinding.js +28 -0
  62. package/dist/0.8/hooks/useDispatchAction.d.ts +22 -0
  63. package/dist/0.8/hooks/useDispatchAction.js +8 -0
  64. package/dist/0.8/index.d.ts +44 -0
  65. package/dist/0.8/index.js +17 -0
  66. package/dist/0.8/utils/dataBinding.d.ts +95 -0
  67. package/dist/0.8/utils/dataBinding.js +46 -0
  68. package/dist/0.8/utils/pathUtils.d.ts +63 -0
  69. package/dist/0.8/utils/pathUtils.js +44 -0
  70. package/dist/0.9/A2UIRenderer.d.ts +54 -0
  71. package/dist/0.9/A2UIRenderer.js +41 -0
  72. package/dist/0.9/components/ComponentRenderer.d.ts +39 -0
  73. package/dist/0.9/components/ComponentRenderer.js +34 -0
  74. package/dist/0.9/components/UnknownComponent.d.ts +11 -0
  75. package/dist/0.9/components/UnknownComponent.js +35 -0
  76. package/dist/0.9/components/display/AudioPlayerComponent.d.ts +5 -0
  77. package/dist/0.9/components/display/AudioPlayerComponent.js +21 -0
  78. package/dist/0.9/components/display/DividerComponent.d.ts +5 -0
  79. package/dist/0.9/components/display/DividerComponent.js +19 -0
  80. package/dist/0.9/components/display/IconComponent.d.ts +5 -0
  81. package/dist/0.9/components/display/IconComponent.js +68 -0
  82. package/dist/0.9/components/display/ImageComponent.d.ts +6 -0
  83. package/dist/0.9/components/display/ImageComponent.js +43 -0
  84. package/dist/0.9/components/display/TextComponent.d.ts +6 -0
  85. package/dist/0.9/components/display/TextComponent.js +31 -0
  86. package/dist/0.9/components/display/VideoComponent.d.ts +5 -0
  87. package/dist/0.9/components/display/VideoComponent.js +30 -0
  88. package/dist/0.9/components/display/index.d.ts +9 -0
  89. package/dist/0.9/components/index.d.ts +12 -0
  90. package/dist/0.9/components/index.js +68 -0
  91. package/dist/0.9/components/interactive/ButtonComponent.d.ts +6 -0
  92. package/dist/0.9/components/interactive/ButtonComponent.js +29 -0
  93. package/dist/0.9/components/interactive/CheckBoxComponent.d.ts +5 -0
  94. package/dist/0.9/components/interactive/CheckBoxComponent.js +41 -0
  95. package/dist/0.9/components/interactive/ChoicePickerComponent.d.ts +7 -0
  96. package/dist/0.9/components/interactive/ChoicePickerComponent.js +80 -0
  97. package/dist/0.9/components/interactive/DateTimeInputComponent.d.ts +5 -0
  98. package/dist/0.9/components/interactive/DateTimeInputComponent.js +50 -0
  99. package/dist/0.9/components/interactive/SliderComponent.d.ts +6 -0
  100. package/dist/0.9/components/interactive/SliderComponent.js +47 -0
  101. package/dist/0.9/components/interactive/TextFieldComponent.d.ts +5 -0
  102. package/dist/0.9/components/interactive/TextFieldComponent.js +57 -0
  103. package/dist/0.9/components/interactive/index.d.ts +9 -0
  104. package/dist/0.9/components/layout/CardComponent.d.ts +5 -0
  105. package/dist/0.9/components/layout/CardComponent.js +15 -0
  106. package/dist/0.9/components/layout/ColumnComponent.d.ts +6 -0
  107. package/dist/0.9/components/layout/ColumnComponent.js +50 -0
  108. package/dist/0.9/components/layout/ListComponent.d.ts +17 -0
  109. package/dist/0.9/components/layout/ListComponent.js +42 -0
  110. package/dist/0.9/components/layout/ModalComponent.d.ts +5 -0
  111. package/dist/0.9/components/layout/ModalComponent.js +30 -0
  112. package/dist/0.9/components/layout/RowComponent.d.ts +6 -0
  113. package/dist/0.9/components/layout/RowComponent.js +50 -0
  114. package/dist/0.9/components/layout/TabsComponent.d.ts +5 -0
  115. package/dist/0.9/components/layout/TabsComponent.js +30 -0
  116. package/dist/0.9/components/layout/TemplateRenderer.d.ts +25 -0
  117. package/dist/0.9/components/layout/TemplateRenderer.js +49 -0
  118. package/dist/0.9/components/layout/index.d.ts +10 -0
  119. package/dist/0.9/contexts/A2UIProvider.d.ts +58 -0
  120. package/dist/0.9/contexts/A2UIProvider.js +34 -0
  121. package/dist/0.9/contexts/ActionContext.d.ts +33 -0
  122. package/dist/0.9/contexts/ActionContext.js +47 -0
  123. package/dist/0.9/contexts/ComponentsMapContext.d.ts +73 -0
  124. package/dist/0.9/contexts/ComponentsMapContext.js +21 -0
  125. package/dist/0.9/contexts/ScopeContext.d.ts +53 -0
  126. package/dist/0.9/contexts/ScopeContext.js +22 -0
  127. package/dist/0.9/contexts/SurfaceContext.d.ts +50 -0
  128. package/dist/0.9/contexts/SurfaceContext.js +118 -0
  129. package/dist/0.9/hooks/useA2UIMessageHandler.d.ts +44 -0
  130. package/dist/0.9/hooks/useA2UIMessageHandler.js +87 -0
  131. package/dist/0.9/hooks/useComponent.d.ts +23 -0
  132. package/dist/0.9/hooks/useComponent.js +9 -0
  133. package/dist/0.9/hooks/useDataBinding.d.ts +59 -0
  134. package/dist/0.9/hooks/useDataBinding.js +43 -0
  135. package/dist/0.9/hooks/useDispatchAction.d.ts +22 -0
  136. package/dist/0.9/hooks/useDispatchAction.js +17 -0
  137. package/dist/0.9/hooks/useValidation.d.ts +25 -0
  138. package/dist/0.9/hooks/useValidation.js +14 -0
  139. package/dist/0.9/index.d.ts +35 -0
  140. package/dist/0.9/index.js +26 -0
  141. package/dist/0.9/utils/dataBinding.d.ts +126 -0
  142. package/dist/0.9/utils/dataBinding.js +41 -0
  143. package/dist/0.9/utils/pathUtils.d.ts +109 -0
  144. package/dist/0.9/utils/pathUtils.js +74 -0
  145. package/dist/0.9/utils/validation.d.ts +49 -0
  146. package/dist/0.9/utils/validation.js +75 -0
  147. package/dist/components/ui/button.d.ts +10 -0
  148. package/dist/components/ui/button.js +53 -0
  149. package/dist/components/ui/card.d.ts +9 -0
  150. package/dist/components/ui/card.js +29 -0
  151. package/dist/components/ui/checkbox.d.ts +4 -0
  152. package/dist/components/ui/checkbox.js +31 -0
  153. package/dist/components/ui/dialog.d.ts +15 -0
  154. package/dist/components/ui/dialog.js +77 -0
  155. package/dist/components/ui/input.d.ts +3 -0
  156. package/dist/components/ui/input.js +21 -0
  157. package/dist/components/ui/label.d.ts +4 -0
  158. package/dist/components/ui/label.js +22 -0
  159. package/dist/components/ui/native-select.d.ts +7 -0
  160. package/dist/components/ui/select.d.ts +15 -0
  161. package/dist/components/ui/select.js +144 -0
  162. package/dist/components/ui/separator.d.ts +4 -0
  163. package/dist/components/ui/separator.js +26 -0
  164. package/dist/components/ui/slider.d.ts +4 -0
  165. package/dist/components/ui/slider.js +63 -0
  166. package/dist/components/ui/tabs.d.ts +7 -0
  167. package/dist/components/ui/tabs.js +67 -0
  168. package/dist/components/ui/textarea.d.ts +3 -0
  169. package/dist/components/ui/textarea.js +18 -0
  170. package/dist/index.d.ts +2 -0
  171. package/dist/index.js +6 -0
  172. package/dist/lib/utils.d.ts +2 -0
  173. package/dist/lib/utils.js +8 -0
  174. package/package.json +75 -0
@@ -0,0 +1,42 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { memo as d } from "react";
3
+ import { useDataModel as f } from "../../hooks/useDataBinding.js";
4
+ import { useScope as h } from "../../contexts/ScopeContext.js";
5
+ import { cn as x } from "../../../lib/utils.js";
6
+ import { ComponentRenderer as g } from "../ComponentRenderer.js";
7
+ import { TemplateRenderer as v } from "./TemplateRenderer.js";
8
+ const y = {
9
+ start: "items-start",
10
+ center: "items-center",
11
+ end: "items-end",
12
+ stretch: "items-stretch"
13
+ }, w = d(function({
14
+ surfaceId: r,
15
+ component: s
16
+ }) {
17
+ const e = s, c = f(r), { basePath: l } = h(), a = e.direction ?? "vertical", p = e.align ?? "stretch", n = x(
18
+ "flex gap-3",
19
+ a === "vertical" ? "flex-col" : "flex-row flex-wrap",
20
+ y[p]
21
+ ), i = e.weight ? { flexGrow: e.weight } : void 0, t = e.children;
22
+ return Array.isArray(t) ? /* @__PURE__ */ o("div", { className: n, style: i, children: t.map((m) => /* @__PURE__ */ o(
23
+ g,
24
+ {
25
+ surfaceId: r,
26
+ componentId: m
27
+ },
28
+ m
29
+ )) }) : t && typeof t == "object" && "componentId" in t ? /* @__PURE__ */ o("div", { className: n, style: i, children: /* @__PURE__ */ o(
30
+ v,
31
+ {
32
+ surfaceId: r,
33
+ template: t,
34
+ dataModel: c,
35
+ basePath: l
36
+ }
37
+ ) }) : /* @__PURE__ */ o("div", { className: n, style: i });
38
+ });
39
+ w.displayName = "A2UI.List";
40
+ export {
41
+ w as ListComponent
42
+ };
@@ -0,0 +1,5 @@
1
+ import { A2UIComponentProps } from '../../contexts/ComponentsMapContext';
2
+ /**
3
+ * Modal component - dialog container with trigger.
4
+ */
5
+ export declare const ModalComponent: import('react').NamedExoticComponent<A2UIComponentProps>;
@@ -0,0 +1,30 @@
1
+ import { jsxs as l, jsx as o } from "react/jsx-runtime";
2
+ import { memo as p, useState as a } from "react";
3
+ import { Dialog as c, DialogTrigger as d, DialogContent as s } from "../../../components/ui/dialog.js";
4
+ import { ComponentRenderer as t } from "../ComponentRenderer.js";
5
+ const g = p(function({
6
+ surfaceId: e,
7
+ component: r
8
+ }) {
9
+ const n = r, [i, m] = a(!1);
10
+ return !n.trigger || !n.content ? null : /* @__PURE__ */ l(c, { open: i, onOpenChange: m, children: [
11
+ /* @__PURE__ */ o(d, { asChild: !0, children: /* @__PURE__ */ o("div", { className: "cursor-pointer", children: /* @__PURE__ */ o(
12
+ t,
13
+ {
14
+ surfaceId: e,
15
+ componentId: n.trigger
16
+ }
17
+ ) }) }),
18
+ /* @__PURE__ */ o(s, { children: /* @__PURE__ */ o(
19
+ t,
20
+ {
21
+ surfaceId: e,
22
+ componentId: n.content
23
+ }
24
+ ) })
25
+ ] });
26
+ });
27
+ g.displayName = "A2UI.Modal";
28
+ export {
29
+ g as ModalComponent
30
+ };
@@ -0,0 +1,6 @@
1
+ import { A2UIComponentProps } from '../../contexts/ComponentsMapContext';
2
+ /**
3
+ * Row component - horizontal flex container.
4
+ * Supports both static children and template binding for dynamic children.
5
+ */
6
+ export declare const RowComponent: import('react').NamedExoticComponent<A2UIComponentProps>;
@@ -0,0 +1,50 @@
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { memo as l } from "react";
3
+ import { useDataModel as y } from "../../hooks/useDataBinding.js";
4
+ import { useScope as d } from "../../contexts/ScopeContext.js";
5
+ import { cn as u } from "../../../lib/utils.js";
6
+ import { ComponentRenderer as j } from "../ComponentRenderer.js";
7
+ import { TemplateRenderer as h } from "./TemplateRenderer.js";
8
+ const w = {
9
+ start: "justify-start",
10
+ center: "justify-center",
11
+ end: "justify-end",
12
+ spaceBetween: "justify-between",
13
+ spaceAround: "justify-around",
14
+ spaceEvenly: "justify-evenly",
15
+ stretch: "justify-stretch"
16
+ }, g = {
17
+ start: "items-start",
18
+ center: "items-center",
19
+ end: "items-end",
20
+ stretch: "items-stretch"
21
+ }, v = l(function({
22
+ surfaceId: n,
23
+ component: c
24
+ }) {
25
+ const e = c, m = y(n), { basePath: a } = d(), p = e.justify ?? "start", f = e.align ?? "stretch", r = u(
26
+ "flex flex-row gap-3",
27
+ w[p],
28
+ g[f]
29
+ ), s = e.weight ? { flexGrow: e.weight } : void 0, t = e.children;
30
+ return Array.isArray(t) ? /* @__PURE__ */ o("div", { className: r, style: s, children: t.map((i) => /* @__PURE__ */ o(
31
+ j,
32
+ {
33
+ surfaceId: n,
34
+ componentId: i
35
+ },
36
+ i
37
+ )) }) : t && typeof t == "object" && "componentId" in t ? /* @__PURE__ */ o("div", { className: r, style: s, children: /* @__PURE__ */ o(
38
+ h,
39
+ {
40
+ surfaceId: n,
41
+ template: t,
42
+ dataModel: m,
43
+ basePath: a
44
+ }
45
+ ) }) : /* @__PURE__ */ o("div", { className: r, style: s });
46
+ });
47
+ v.displayName = "A2UI.Row";
48
+ export {
49
+ v as RowComponent
50
+ };
@@ -0,0 +1,5 @@
1
+ import { A2UIComponentProps } from '../../contexts/ComponentsMapContext';
2
+ /**
3
+ * Tabs component - tabbed content container.
4
+ */
5
+ export declare const TabsComponent: import('react').NamedExoticComponent<A2UIComponentProps>;
@@ -0,0 +1,30 @@
1
+ import { jsxs as m, jsx as n, Fragment as d } from "react/jsx-runtime";
2
+ import { memo as h } from "react";
3
+ import { useStringBinding as p } from "../../hooks/useDataBinding.js";
4
+ import { Tabs as b, TabsList as T, TabsTrigger as u, TabsContent as f } from "../../../components/ui/tabs.js";
5
+ import { ComponentRenderer as g } from "../ComponentRenderer.js";
6
+ function x({
7
+ surfaceId: r,
8
+ title: l,
9
+ index: i
10
+ }) {
11
+ const e = p(r, l, `Tab ${i + 1}`);
12
+ return /* @__PURE__ */ n(d, { children: e });
13
+ }
14
+ const C = h(function({
15
+ surfaceId: l,
16
+ component: i
17
+ }) {
18
+ const e = i, o = e.tabs;
19
+ if (!o || o.length === 0)
20
+ return null;
21
+ const a = e.weight ? { flexGrow: e.weight } : void 0, s = o[0].child;
22
+ return /* @__PURE__ */ m(b, { defaultValue: s, className: "w-full", style: a, children: [
23
+ /* @__PURE__ */ n(T, { children: o.map((t, c) => /* @__PURE__ */ n(u, { value: t.child, children: /* @__PURE__ */ n(x, { surfaceId: l, title: t.title, index: c }) }, t.child)) }),
24
+ o.map((t) => /* @__PURE__ */ n(f, { value: t.child, children: /* @__PURE__ */ n(g, { surfaceId: l, componentId: t.child }) }, t.child))
25
+ ] });
26
+ });
27
+ C.displayName = "A2UI.Tabs";
28
+ export {
29
+ C as TabsComponent
30
+ };
@@ -0,0 +1,25 @@
1
+ import { TemplateBinding, DataModel } from '@a2ui-sdk/types/0.9';
2
+ /**
3
+ * Props for TemplateRenderer.
4
+ */
5
+ export interface TemplateRendererProps {
6
+ surfaceId: string;
7
+ template: TemplateBinding;
8
+ dataModel: DataModel;
9
+ basePath: string | null;
10
+ }
11
+ /**
12
+ * Renders children from a template binding.
13
+ *
14
+ * For each item in the array at the template path, renders the template
15
+ * component with a ScopeContext that sets the base path to the item's path.
16
+ *
17
+ * @example
18
+ * Given template: { componentId: "item-template", path: "/items" }
19
+ * And data: { items: [{ name: "A" }, { name: "B" }] }
20
+ *
21
+ * Renders:
22
+ * - item-template with basePath "/items/0"
23
+ * - item-template with basePath "/items/1"
24
+ */
25
+ export declare const TemplateRenderer: import('react').NamedExoticComponent<TemplateRendererProps>;
@@ -0,0 +1,49 @@
1
+ import { jsx as r, Fragment as i } from "react/jsx-runtime";
2
+ import { memo as f } from "react";
3
+ import { ScopeProvider as p } from "../../contexts/ScopeContext.js";
4
+ import { ComponentRenderer as s } from "../ComponentRenderer.js";
5
+ import { resolvePath as $, getValueByPath as P } from "../../utils/pathUtils.js";
6
+ const b = f(function({
7
+ surfaceId: l,
8
+ template: c,
9
+ dataModel: d,
10
+ basePath: h
11
+ }) {
12
+ const { componentId: o, path: u } = c, t = $(u, h), e = P(d, t);
13
+ if (e == null)
14
+ return console.warn(
15
+ `[A2UI 0.9] Template binding path "${t}" resolved to undefined or null.`
16
+ ), null;
17
+ if (Array.isArray(e))
18
+ return /* @__PURE__ */ r(i, { children: e.map((m, n) => {
19
+ const a = `${t}/${n}`;
20
+ return /* @__PURE__ */ r(p, { basePath: a, children: /* @__PURE__ */ r(
21
+ s,
22
+ {
23
+ surfaceId: l,
24
+ componentId: o
25
+ }
26
+ ) }, `${o}-${n}`);
27
+ }) });
28
+ if (typeof e == "object") {
29
+ const m = Object.keys(e);
30
+ return /* @__PURE__ */ r(i, { children: m.map((n) => {
31
+ const a = `${t}/${n}`;
32
+ return /* @__PURE__ */ r(p, { basePath: a, children: /* @__PURE__ */ r(
33
+ s,
34
+ {
35
+ surfaceId: l,
36
+ componentId: o
37
+ }
38
+ ) }, `${o}-${n}`);
39
+ }) });
40
+ }
41
+ return console.warn(
42
+ `[A2UI 0.9] Template binding path "${t}" resolved to non-iterable value:`,
43
+ e
44
+ ), null;
45
+ });
46
+ b.displayName = "A2UI.TemplateRenderer";
47
+ export {
48
+ b as TemplateRenderer
49
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Layout components exports.
3
+ */
4
+ export { RowComponent } from './RowComponent';
5
+ export { ColumnComponent } from './ColumnComponent';
6
+ export { ListComponent } from './ListComponent';
7
+ export { CardComponent } from './CardComponent';
8
+ export { TabsComponent } from './TabsComponent';
9
+ export { ModalComponent } from './ModalComponent';
10
+ export { TemplateRenderer } from './TemplateRenderer';
@@ -0,0 +1,58 @@
1
+ import { ReactNode } from 'react';
2
+ import { ComponentsMap } from './ComponentsMapContext';
3
+ import { A2UIMessage, ActionHandler } from '@a2ui-sdk/types/0.9';
4
+ export type { ComponentsMap };
5
+ /**
6
+ * Props for A2UIProvider.
7
+ */
8
+ export interface A2UIProviderProps {
9
+ /** Array of A2UI messages to render */
10
+ messages: A2UIMessage[];
11
+ /** Callback when an action is dispatched */
12
+ onAction?: ActionHandler;
13
+ /** Custom component overrides */
14
+ components?: ComponentsMap;
15
+ children: ReactNode;
16
+ }
17
+ /**
18
+ * Combined provider for all A2UI 0.9 contexts.
19
+ *
20
+ * Provides:
21
+ * - SurfaceContext: Multi-surface state management
22
+ * - ActionContext: Action dispatch handling
23
+ * - ComponentsMapContext: Custom component overrides
24
+ *
25
+ * @param props - Component props
26
+ * @param props.messages - Array of A2UI messages to render
27
+ * @param props.onAction - Callback when an action is dispatched
28
+ * @param props.components - Optional custom component overrides
29
+ * @param props.children - Child components (typically A2UIRenderer)
30
+ *
31
+ * @example
32
+ * ```tsx
33
+ * // Basic usage
34
+ * <A2UIProvider messages={messages} onAction={handleAction}>
35
+ * <A2UIRenderer />
36
+ * </A2UIProvider>
37
+ *
38
+ * // With custom components
39
+ * const customComponents = new Map([
40
+ * ['Button', CustomButton],
41
+ * ['Switch', CustomSwitch],
42
+ * ])
43
+ * <A2UIProvider
44
+ * messages={messages}
45
+ * onAction={handleAction}
46
+ * components={customComponents}
47
+ * >
48
+ * <A2UIRenderer />
49
+ * </A2UIProvider>
50
+ *
51
+ * // Render specific surfaces
52
+ * <A2UIProvider messages={messages} onAction={handleAction}>
53
+ * <A2UIRenderer surfaceId="sidebar" />
54
+ * <A2UIRenderer surfaceId="main" />
55
+ * </A2UIProvider>
56
+ * ```
57
+ */
58
+ export declare function A2UIProvider({ messages, onAction, components, children, }: A2UIProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,34 @@
1
+ import { jsx as e, Fragment as s } from "react/jsx-runtime";
2
+ import { useEffect as i } from "react";
3
+ import { SurfaceProvider as f } from "./SurfaceContext.js";
4
+ import { ActionProvider as m } from "./ActionContext.js";
5
+ import { ComponentsMapProvider as c } from "./ComponentsMapContext.js";
6
+ import { useA2UIMessageHandler as p } from "../hooks/useA2UIMessageHandler.js";
7
+ import { componentRegistry as a } from "../components/index.js";
8
+ function d({
9
+ messages: r,
10
+ children: n
11
+ }) {
12
+ const { processMessages: o, clear: t } = p();
13
+ return i(() => {
14
+ t(), r && r.length > 0 && o(r);
15
+ }, [r, o, t]), /* @__PURE__ */ e(s, { children: n });
16
+ }
17
+ function I({
18
+ messages: r,
19
+ onAction: n,
20
+ components: o,
21
+ children: t
22
+ }) {
23
+ return /* @__PURE__ */ e(f, { children: /* @__PURE__ */ e(m, { onAction: n, children: /* @__PURE__ */ e(
24
+ c,
25
+ {
26
+ components: o,
27
+ defaultComponents: a,
28
+ children: /* @__PURE__ */ e(d, { messages: r ?? [], children: t })
29
+ }
30
+ ) }) });
31
+ }
32
+ export {
33
+ I as A2UIProvider
34
+ };
@@ -0,0 +1,33 @@
1
+ import { ReactNode } from 'react';
2
+ import { Action, ActionHandler, DataModel } from '@a2ui-sdk/types/0.9';
3
+ /**
4
+ * Action context value interface.
5
+ */
6
+ export interface ActionContextValue {
7
+ /** Dispatches an action with resolved context */
8
+ dispatchAction: (surfaceId: string, componentId: string, action: Action, dataModel: DataModel, basePath?: string | null) => void;
9
+ /** The action handler callback (if set) */
10
+ onAction: ActionHandler | null;
11
+ }
12
+ /**
13
+ * Action context for A2UI 0.9 rendering.
14
+ */
15
+ export declare const ActionContext: import('react').Context<ActionContextValue | null>;
16
+ /**
17
+ * Props for ActionProvider.
18
+ */
19
+ export interface ActionProviderProps {
20
+ /** Callback when an action is dispatched */
21
+ onAction?: ActionHandler;
22
+ children: ReactNode;
23
+ }
24
+ /**
25
+ * Provider component for Action dispatching.
26
+ */
27
+ export declare function ActionProvider({ onAction, children }: ActionProviderProps): import("react/jsx-runtime").JSX.Element;
28
+ /**
29
+ * Hook to access the Action context.
30
+ *
31
+ * @throws Error if used outside of ActionProvider
32
+ */
33
+ export declare function useActionContext(): ActionContextValue;
@@ -0,0 +1,47 @@
1
+ import { jsx as d } from "react/jsx-runtime";
2
+ import { createContext as x, useContext as p, useCallback as C, useMemo as f } from "react";
3
+ import { resolveContext as v } from "../utils/dataBinding.js";
4
+ const n = x(null);
5
+ function b({ onAction: t, children: r }) {
6
+ const e = C(
7
+ (i, c, o, u, a = null) => {
8
+ if (!t) {
9
+ console.warn(
10
+ "[A2UI 0.9] Action dispatched but no handler is registered"
11
+ );
12
+ return;
13
+ }
14
+ const l = v(
15
+ o.context,
16
+ u,
17
+ a
18
+ ), m = {
19
+ surfaceId: i,
20
+ name: o.name,
21
+ context: l,
22
+ sourceComponentId: c,
23
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
24
+ };
25
+ t(m);
26
+ },
27
+ [t]
28
+ ), s = f(
29
+ () => ({
30
+ dispatchAction: e,
31
+ onAction: t ?? null
32
+ }),
33
+ [e, t]
34
+ );
35
+ return /* @__PURE__ */ d(n.Provider, { value: s, children: r });
36
+ }
37
+ function I() {
38
+ const t = p(n);
39
+ if (!t)
40
+ throw new Error("useActionContext must be used within an ActionProvider");
41
+ return t;
42
+ }
43
+ export {
44
+ n as ActionContext,
45
+ b as ActionProvider,
46
+ I as useActionContext
47
+ };
@@ -0,0 +1,73 @@
1
+ import { ReactNode, ComponentType } from 'react';
2
+ import { Component } from '@a2ui-sdk/types/0.9';
3
+ /**
4
+ * Props passed to A2UI components.
5
+ * Includes the component definition and surfaceId.
6
+ */
7
+ export interface A2UIComponentProps {
8
+ /** The surface ID this component belongs to */
9
+ surfaceId: string;
10
+ /** The component definition from the protocol */
11
+ component: Component;
12
+ }
13
+ /**
14
+ * Type for a component in the components map.
15
+ */
16
+ export type A2UIComponent = ComponentType<A2UIComponentProps>;
17
+ /**
18
+ * Map of component type names to React components.
19
+ */
20
+ export type ComponentsMap = Map<string, A2UIComponent>;
21
+ /**
22
+ * Context value for ComponentsMapContext.
23
+ */
24
+ export interface ComponentsMapContextValue {
25
+ /** Custom components provided by the user */
26
+ customComponents: ComponentsMap;
27
+ /** Get a component by type name (custom first, then default) */
28
+ getComponent: (type: string) => A2UIComponent | undefined;
29
+ }
30
+ /**
31
+ * Context for custom component overrides.
32
+ */
33
+ export declare const ComponentsMapContext: import('react').Context<ComponentsMapContextValue | null>;
34
+ /**
35
+ * Props for ComponentsMapProvider.
36
+ */
37
+ export interface ComponentsMapProviderProps {
38
+ /** Custom components to override or extend defaults */
39
+ components?: ComponentsMap;
40
+ /** Default component registry */
41
+ defaultComponents: Record<string, A2UIComponent>;
42
+ children: ReactNode;
43
+ }
44
+ /**
45
+ * Provider for custom component overrides.
46
+ *
47
+ * @example
48
+ * ```tsx
49
+ * const customComponents = new Map([
50
+ * ['Button', CustomButton],
51
+ * ['Switch', CustomSwitch],
52
+ * ])
53
+ *
54
+ * <ComponentsMapProvider components={customComponents} defaultComponents={defaultRegistry}>
55
+ * <App />
56
+ * </ComponentsMapProvider>
57
+ * ```
58
+ */
59
+ export declare function ComponentsMapProvider({ components, defaultComponents, children, }: ComponentsMapProviderProps): import("react/jsx-runtime").JSX.Element;
60
+ /**
61
+ * Hook to access the ComponentsMap context.
62
+ *
63
+ * @throws Error if used outside of ComponentsMapProvider
64
+ */
65
+ export declare function useComponentsMapContext(): ComponentsMapContextValue;
66
+ /**
67
+ * Hook to get a component by type name.
68
+ * Returns custom component if available, otherwise default.
69
+ *
70
+ * @param type - The component type name
71
+ * @returns The component or undefined if not found
72
+ */
73
+ export declare function useComponentFromMap(type: string): A2UIComponent | undefined;
@@ -0,0 +1,21 @@
1
+ import { jsx as s } from "react/jsx-runtime";
2
+ import { createContext as u, useMemo as p } from "react";
3
+ const c = u(null);
4
+ function x({
5
+ components: n,
6
+ defaultComponents: e,
7
+ children: r
8
+ }) {
9
+ const m = p(() => {
10
+ const o = n ?? /* @__PURE__ */ new Map();
11
+ return {
12
+ customComponents: o,
13
+ getComponent: (t) => o.has(t) ? o.get(t) : e[t]
14
+ };
15
+ }, [n, e]);
16
+ return /* @__PURE__ */ s(c.Provider, { value: m, children: r });
17
+ }
18
+ export {
19
+ c as ComponentsMapContext,
20
+ x as ComponentsMapProvider
21
+ };
@@ -0,0 +1,53 @@
1
+ import { ReactNode } from 'react';
2
+ import { ScopeValue } from '@a2ui-sdk/types/0.9';
3
+ /**
4
+ * Context for tracking collection scopes.
5
+ *
6
+ * When rendering children from template binding (e.g., List with `{"componentId": "item", "path": "/items"}`),
7
+ * each item gets its own scope with a base path like "/items/0", "/items/1", etc.
8
+ *
9
+ * Components use this context to resolve relative paths within their scope.
10
+ */
11
+ export declare const ScopeContext: import('react').Context<ScopeValue>;
12
+ /**
13
+ * Props for ScopeProvider.
14
+ */
15
+ export interface ScopeProviderProps {
16
+ /** The base path for this scope (e.g., "/items/0") */
17
+ basePath: string;
18
+ children: ReactNode;
19
+ }
20
+ /**
21
+ * Provider for creating a new scope.
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * // In ListComponent when rendering template children:
26
+ * {items.map((_, index) => (
27
+ * <ScopeProvider key={index} basePath={`${dataPath}/${index}`}>
28
+ * <ComponentRenderer id={templateComponentId} />
29
+ * </ScopeProvider>
30
+ * ))}
31
+ * ```
32
+ */
33
+ export declare function ScopeProvider({ basePath, children }: ScopeProviderProps): import("react/jsx-runtime").JSX.Element;
34
+ /**
35
+ * Hook to access the current scope.
36
+ *
37
+ * @returns The current scope value
38
+ *
39
+ * @example
40
+ * ```tsx
41
+ * function MyComponent() {
42
+ * const { basePath } = useScope()
43
+ * // basePath is null for root scope, or something like "/items/0" for item scope
44
+ * }
45
+ * ```
46
+ */
47
+ export declare function useScope(): ScopeValue;
48
+ /**
49
+ * Hook to get the base path for the current scope.
50
+ *
51
+ * @returns The base path (null for root scope, string for nested scope)
52
+ */
53
+ export declare function useScopeBasePath(): string | null;
@@ -0,0 +1,22 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { createContext as c, useContext as u } from "react";
3
+ const s = {
4
+ basePath: null
5
+ }, t = c(s);
6
+ function f({ basePath: e, children: o }) {
7
+ const n = { basePath: e };
8
+ return /* @__PURE__ */ r(t.Provider, { value: n, children: o });
9
+ }
10
+ function a() {
11
+ return u(t);
12
+ }
13
+ function l() {
14
+ const { basePath: e } = a();
15
+ return e;
16
+ }
17
+ export {
18
+ t as ScopeContext,
19
+ f as ScopeProvider,
20
+ a as useScope,
21
+ l as useScopeBasePath
22
+ };
@@ -0,0 +1,50 @@
1
+ import { ReactNode } from 'react';
2
+ import { Component, DataModel, SurfaceState } from '@a2ui-sdk/types/0.9';
3
+ /**
4
+ * Surface context value interface.
5
+ */
6
+ export interface SurfaceContextValue {
7
+ /** Map of all surfaces by surfaceId */
8
+ surfaces: Map<string, SurfaceState>;
9
+ /**
10
+ * Creates a new surface.
11
+ * If the surface already exists, logs an error and ignores.
12
+ */
13
+ createSurface: (surfaceId: string, catalogId: string) => void;
14
+ /** Updates components in a surface (upsert semantics) */
15
+ updateComponents: (surfaceId: string, components: Component[]) => void;
16
+ /** Updates the data model at a path */
17
+ updateDataModel: (surfaceId: string, path?: string, value?: unknown) => void;
18
+ /** Deletes a surface */
19
+ deleteSurface: (surfaceId: string) => void;
20
+ /** Gets a surface by ID */
21
+ getSurface: (surfaceId: string) => SurfaceState | undefined;
22
+ /** Gets a component from a surface */
23
+ getComponent: (surfaceId: string, componentId: string) => Component | undefined;
24
+ /** Gets the data model for a surface */
25
+ getDataModel: (surfaceId: string) => DataModel;
26
+ /** Sets a value in the data model (for two-way binding) */
27
+ setDataValue: (surfaceId: string, path: string, value: unknown) => void;
28
+ /** Clears all surfaces */
29
+ clearSurfaces: () => void;
30
+ }
31
+ /**
32
+ * Surface context for A2UI 0.9 rendering.
33
+ */
34
+ export declare const SurfaceContext: import('react').Context<SurfaceContextValue | null>;
35
+ /**
36
+ * Props for SurfaceProvider.
37
+ */
38
+ export interface SurfaceProviderProps {
39
+ children: ReactNode;
40
+ }
41
+ /**
42
+ * Provider component for Surface state management.
43
+ */
44
+ export declare function SurfaceProvider({ children }: SurfaceProviderProps): import("react/jsx-runtime").JSX.Element;
45
+ /**
46
+ * Hook to access the Surface context.
47
+ *
48
+ * @throws Error if used outside of SurfaceProvider
49
+ */
50
+ export declare function useSurfaceContext(): SurfaceContextValue;