@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,63 @@
1
+ import { ReactNode, ComponentType } from 'react';
2
+ import { BaseComponentProps } from '@a2ui-sdk/types/0.8';
3
+ /**
4
+ * Type for a component in the components map.
5
+ */
6
+ export type A2UIComponent = ComponentType<BaseComponentProps & Record<string, unknown>>;
7
+ /**
8
+ * Map of component type names to React components.
9
+ */
10
+ export type ComponentsMap = Map<string, A2UIComponent>;
11
+ /**
12
+ * Context value for ComponentsMapContext.
13
+ */
14
+ export interface ComponentsMapContextValue {
15
+ /** Custom components provided by the user */
16
+ customComponents: ComponentsMap;
17
+ /** Get a component by type name (custom first, then default) */
18
+ getComponent: (type: string) => A2UIComponent | undefined;
19
+ }
20
+ /**
21
+ * Context for custom component overrides.
22
+ */
23
+ export declare const ComponentsMapContext: import('react').Context<ComponentsMapContextValue | null>;
24
+ /**
25
+ * Props for ComponentsMapProvider.
26
+ */
27
+ export interface ComponentsMapProviderProps {
28
+ /** Custom components to override or extend defaults */
29
+ components?: ComponentsMap;
30
+ /** Default component registry */
31
+ defaultComponents: Record<string, A2UIComponent>;
32
+ children: ReactNode;
33
+ }
34
+ /**
35
+ * Provider for custom component overrides.
36
+ *
37
+ * @example
38
+ * ```tsx
39
+ * const customComponents = new Map([
40
+ * ['Button', CustomButton],
41
+ * ['Switch', CustomSwitch],
42
+ * ])
43
+ *
44
+ * <ComponentsMapProvider components={customComponents} defaultComponents={defaultRegistry}>
45
+ * <App />
46
+ * </ComponentsMapProvider>
47
+ * ```
48
+ */
49
+ export declare function ComponentsMapProvider({ components, defaultComponents, children, }: ComponentsMapProviderProps): import("react/jsx-runtime").JSX.Element;
50
+ /**
51
+ * Hook to access the ComponentsMap context.
52
+ *
53
+ * @throws Error if used outside of ComponentsMapProvider
54
+ */
55
+ export declare function useComponentsMapContext(): ComponentsMapContextValue;
56
+ /**
57
+ * Hook to get a component by type name.
58
+ * Returns custom component if available, otherwise default.
59
+ *
60
+ * @param type - The component type name
61
+ * @returns The component or undefined if not found
62
+ */
63
+ 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,43 @@
1
+ import { ReactNode } from 'react';
2
+ import { DataModel, DataModelValue } from '@a2ui-sdk/types/0.8';
3
+ /**
4
+ * DataModel context value interface.
5
+ */
6
+ export interface DataModelContextValue {
7
+ /** Map of data models by surfaceId */
8
+ dataModels: Map<string, DataModel>;
9
+ /** Updates the data model at a path with merge behavior */
10
+ updateDataModel: (surfaceId: string, path: string, data: Record<string, unknown>) => void;
11
+ /** Gets a value from the data model */
12
+ getDataValue: (surfaceId: string, path: string) => DataModelValue | undefined;
13
+ /** Sets a value in the data model (used by form inputs) */
14
+ setDataValue: (surfaceId: string, path: string, value: unknown) => void;
15
+ /** Gets the entire data model for a surface */
16
+ getDataModel: (surfaceId: string) => DataModel;
17
+ /** Initializes the data model for a surface */
18
+ initDataModel: (surfaceId: string) => void;
19
+ /** Deletes the data model for a surface */
20
+ deleteDataModel: (surfaceId: string) => void;
21
+ /** Clears all data models */
22
+ clearDataModels: () => void;
23
+ }
24
+ /**
25
+ * DataModel context for A2UI rendering.
26
+ */
27
+ export declare const DataModelContext: import('react').Context<DataModelContextValue | null>;
28
+ /**
29
+ * Props for DataModelProvider.
30
+ */
31
+ export interface DataModelProviderProps {
32
+ children: ReactNode;
33
+ }
34
+ /**
35
+ * Provider component for DataModel state management.
36
+ */
37
+ export declare function DataModelProvider({ children }: DataModelProviderProps): import("react/jsx-runtime").JSX.Element;
38
+ /**
39
+ * Hook to access the DataModel context.
40
+ *
41
+ * @throws Error if used outside of DataModelProvider
42
+ */
43
+ export declare function useDataModelContext(): DataModelContextValue;
@@ -0,0 +1,86 @@
1
+ import { jsx as C } from "react/jsx-runtime";
2
+ import { createContext as P, useContext as f, useState as V, useCallback as a, useMemo as v } from "react";
3
+ import { mergeAtPath as b, getValueByPath as y, setValueByPath as B } from "../utils/pathUtils.js";
4
+ const g = P(
5
+ null
6
+ );
7
+ function E({ children: u }) {
8
+ const [r, s] = V(
9
+ /* @__PURE__ */ new Map()
10
+ ), M = a(
11
+ (t, n, e) => {
12
+ s((c) => {
13
+ const o = new Map(c), l = o.get(t) ?? {}, d = b(l, n, e);
14
+ return o.set(t, d), o;
15
+ });
16
+ },
17
+ []
18
+ ), i = a(
19
+ (t, n) => {
20
+ const e = r.get(t);
21
+ if (e)
22
+ return y(e, n);
23
+ },
24
+ [r]
25
+ ), D = a(
26
+ (t, n, e) => {
27
+ s((c) => {
28
+ const o = new Map(c), l = o.get(t) ?? {}, d = B(l, n, e);
29
+ return o.set(t, d), o;
30
+ });
31
+ },
32
+ []
33
+ ), x = a(
34
+ (t) => r.get(t) ?? {},
35
+ [r]
36
+ ), p = a((t) => {
37
+ s((n) => {
38
+ if (n.has(t))
39
+ return n;
40
+ const e = new Map(n);
41
+ return e.set(t, {}), e;
42
+ });
43
+ }, []), m = a((t) => {
44
+ s((n) => {
45
+ const e = new Map(n);
46
+ return e.delete(t), e;
47
+ });
48
+ }, []), w = a(() => {
49
+ s(/* @__PURE__ */ new Map());
50
+ }, []), h = v(
51
+ () => ({
52
+ dataModels: r,
53
+ updateDataModel: M,
54
+ getDataValue: i,
55
+ setDataValue: D,
56
+ getDataModel: x,
57
+ initDataModel: p,
58
+ deleteDataModel: m,
59
+ clearDataModels: w
60
+ }),
61
+ [
62
+ r,
63
+ M,
64
+ i,
65
+ D,
66
+ x,
67
+ p,
68
+ m,
69
+ w
70
+ ]
71
+ );
72
+ return /* @__PURE__ */ C(g.Provider, { value: h, children: u });
73
+ }
74
+ function S() {
75
+ const u = f(g);
76
+ if (!u)
77
+ throw new Error(
78
+ "useDataModelContext must be used within a DataModelProvider"
79
+ );
80
+ return u;
81
+ }
82
+ export {
83
+ g as DataModelContext,
84
+ E as DataModelProvider,
85
+ S as useDataModelContext
86
+ };
@@ -0,0 +1,45 @@
1
+ import { ReactNode } from 'react';
2
+ import { Surface, ComponentDefinition, SurfaceStyles } from '@a2ui-sdk/types/0.8';
3
+ /**
4
+ * Surface context value interface.
5
+ */
6
+ export interface SurfaceContextValue {
7
+ /** Map of all surfaces by surfaceId */
8
+ surfaces: Map<string, Surface>;
9
+ /**
10
+ * Initializes a surface with root and styles.
11
+ * If the surface already exists, preserves existing components.
12
+ * Called when beginRendering message is received.
13
+ */
14
+ initSurface: (surfaceId: string, root: string, styles?: SurfaceStyles) => void;
15
+ /** Updates components in a surface */
16
+ updateSurface: (surfaceId: string, components: ComponentDefinition[]) => void;
17
+ /** Deletes a surface */
18
+ deleteSurface: (surfaceId: string) => void;
19
+ /** Gets a surface by ID */
20
+ getSurface: (surfaceId: string) => Surface | undefined;
21
+ /** Gets a component from a surface */
22
+ getComponent: (surfaceId: string, componentId: string) => ComponentDefinition | undefined;
23
+ /** Clears all surfaces */
24
+ clearSurfaces: () => void;
25
+ }
26
+ /**
27
+ * Surface context for A2UI rendering.
28
+ */
29
+ export declare const SurfaceContext: import('react').Context<SurfaceContextValue | null>;
30
+ /**
31
+ * Props for SurfaceProvider.
32
+ */
33
+ export interface SurfaceProviderProps {
34
+ children: ReactNode;
35
+ }
36
+ /**
37
+ * Provider component for Surface state management.
38
+ */
39
+ export declare function SurfaceProvider({ children }: SurfaceProviderProps): import("react/jsx-runtime").JSX.Element;
40
+ /**
41
+ * Hook to access the Surface context.
42
+ *
43
+ * @throws Error if used outside of SurfaceProvider
44
+ */
45
+ export declare function useSurfaceContext(): SurfaceContextValue;
@@ -0,0 +1,88 @@
1
+ import { jsx as P } from "react/jsx-runtime";
2
+ import { createContext as b, useContext as h, useState as j, useCallback as s, useMemo as k } from "react";
3
+ const C = b(null);
4
+ function q({ children: a }) {
5
+ const [o, f] = j(/* @__PURE__ */ new Map()), i = s(
6
+ (e, n, t) => {
7
+ f((c) => {
8
+ const p = c.get(e), r = new Map(c);
9
+ return r.set(e, {
10
+ surfaceId: e,
11
+ root: n,
12
+ components: p?.components ?? /* @__PURE__ */ new Map(),
13
+ styles: t
14
+ }), r;
15
+ });
16
+ },
17
+ []
18
+ ), m = s(
19
+ (e, n) => {
20
+ f((t) => {
21
+ const c = t.get(e);
22
+ if (!c) {
23
+ const u = {
24
+ surfaceId: e,
25
+ root: "",
26
+ components: /* @__PURE__ */ new Map()
27
+ };
28
+ for (const l of n)
29
+ u.components.set(l.id, l);
30
+ const g = new Map(t);
31
+ return g.set(e, u), g;
32
+ }
33
+ const p = new Map(t), r = new Map(c.components);
34
+ for (const u of n)
35
+ r.set(u.id, u);
36
+ return p.set(e, {
37
+ ...c,
38
+ components: r
39
+ }), p;
40
+ });
41
+ },
42
+ []
43
+ ), w = s((e) => {
44
+ f((n) => {
45
+ const t = new Map(n);
46
+ return t.delete(e), t;
47
+ });
48
+ }, []), x = s(
49
+ (e) => o.get(e),
50
+ [o]
51
+ ), S = s(
52
+ (e, n) => o.get(e)?.components.get(n),
53
+ [o]
54
+ ), M = s(() => {
55
+ f(/* @__PURE__ */ new Map());
56
+ }, []), d = k(
57
+ () => ({
58
+ surfaces: o,
59
+ initSurface: i,
60
+ updateSurface: m,
61
+ deleteSurface: w,
62
+ getSurface: x,
63
+ getComponent: S,
64
+ clearSurfaces: M
65
+ }),
66
+ [
67
+ o,
68
+ i,
69
+ m,
70
+ w,
71
+ x,
72
+ S,
73
+ M
74
+ ]
75
+ );
76
+ return /* @__PURE__ */ P(C.Provider, { value: d, children: a });
77
+ }
78
+ function y() {
79
+ const a = h(C);
80
+ if (!a)
81
+ throw new Error("useSurfaceContext must be used within a SurfaceProvider");
82
+ return a;
83
+ }
84
+ export {
85
+ C as SurfaceContext,
86
+ q as SurfaceProvider,
87
+ y as useSurfaceContext
88
+ };
@@ -0,0 +1,41 @@
1
+ import { A2UIMessage } from '@a2ui-sdk/types/0.8';
2
+ /**
3
+ * Return type for the message handler hook.
4
+ */
5
+ export interface A2UIMessageHandler {
6
+ /** Processes a single A2UI message */
7
+ processMessage: (message: A2UIMessage) => void;
8
+ /** Processes multiple A2UI messages */
9
+ processMessages: (messages: A2UIMessage[]) => void;
10
+ /** Clears all surfaces and data models */
11
+ clear: () => void;
12
+ }
13
+ /**
14
+ * Hook that returns functions to process A2UI messages.
15
+ *
16
+ * @returns Object with processMessage, processMessages, and clear functions
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * function MyComponent() {
21
+ * const { processMessage, processMessages, clear } = useA2UIMessageHandler();
22
+ *
23
+ * useEffect(() => {
24
+ * // Process initial messages
25
+ * processMessages(initialMessages);
26
+ *
27
+ * // Listen for SSE updates
28
+ * const handler = (event) => {
29
+ * processMessage(event.detail.message);
30
+ * };
31
+ * window.addEventListener('a2ui-message', handler);
32
+ *
33
+ * return () => {
34
+ * window.removeEventListener('a2ui-message', handler);
35
+ * clear();
36
+ * };
37
+ * }, []);
38
+ * }
39
+ * ```
40
+ */
41
+ export declare function useA2UIMessageHandler(): A2UIMessageHandler;
@@ -0,0 +1,54 @@
1
+ import { useCallback as c } from "react";
2
+ import { useSurfaceContext as I } from "../contexts/SurfaceContext.js";
3
+ import { useDataModelContext as U } from "../contexts/DataModelContext.js";
4
+ import { contentsToObject as b } from "../utils/dataBinding.js";
5
+ function g() {
6
+ const { initSurface: n, updateSurface: d, deleteSurface: u, clearSurfaces: f } = I(), { updateDataModel: s, initDataModel: l, deleteDataModel: i, clearDataModels: p } = U(), o = c(
7
+ (t) => {
8
+ if (t.beginRendering) {
9
+ const { surfaceId: e, root: r, styles: a } = t.beginRendering;
10
+ n(e, r, a), l(e);
11
+ return;
12
+ }
13
+ if (t.surfaceUpdate) {
14
+ const { surfaceId: e, components: r } = t.surfaceUpdate;
15
+ d(e, r);
16
+ return;
17
+ }
18
+ if (t.dataModelUpdate) {
19
+ const { surfaceId: e, path: r = "/", contents: a } = t.dataModelUpdate, D = b(a);
20
+ s(e, r, D);
21
+ return;
22
+ }
23
+ if (t.deleteSurface) {
24
+ const { surfaceId: e } = t.deleteSurface;
25
+ u(e), i(e);
26
+ return;
27
+ }
28
+ },
29
+ [
30
+ n,
31
+ d,
32
+ u,
33
+ l,
34
+ s,
35
+ i
36
+ ]
37
+ ), M = c(
38
+ (t) => {
39
+ for (const e of t)
40
+ o(e);
41
+ },
42
+ [o]
43
+ ), S = c(() => {
44
+ f(), p();
45
+ }, [f, p]);
46
+ return {
47
+ processMessage: o,
48
+ processMessages: M,
49
+ clear: S
50
+ };
51
+ }
52
+ export {
53
+ g as useA2UIMessageHandler
54
+ };
@@ -0,0 +1,23 @@
1
+ import { ComponentDefinition } from '@a2ui-sdk/types/0.8';
2
+ /**
3
+ * Gets a component from a Surface by its ID.
4
+ *
5
+ * @param surfaceId - The surface ID
6
+ * @param componentId - The component ID to look up
7
+ * @returns The ComponentDefinition, or undefined if not found
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * function MyComponent({ surfaceId, componentId }) {
12
+ * const component = useComponent(surfaceId, componentId);
13
+ *
14
+ * if (!component) {
15
+ * return null;
16
+ * }
17
+ *
18
+ * const [type, props] = Object.entries(component.component)[0];
19
+ * // Render based on type...
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function useComponent(surfaceId: string, componentId: string): ComponentDefinition | undefined;
@@ -0,0 +1,9 @@
1
+ import { useMemo as r } from "react";
2
+ import { useSurfaceContext as n } from "../contexts/SurfaceContext.js";
3
+ function p(o, t) {
4
+ const { getComponent: e } = n();
5
+ return r(() => e(o, t), [e, o, t]);
6
+ }
7
+ export {
8
+ p as useComponent
9
+ };
@@ -0,0 +1,50 @@
1
+ import { ValueSource, DataModel } from '@a2ui-sdk/types/0.8';
2
+ /**
3
+ * Resolves a ValueSource to its actual value.
4
+ *
5
+ * @param surfaceId - The surface ID for data model lookup
6
+ * @param source - The value source (literal or path reference)
7
+ * @param defaultValue - Default value if source is undefined or path not found
8
+ * @returns The resolved value
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * function TextComponent({ surfaceId, text }) {
13
+ * const textValue = useDataBinding<string>(surfaceId, text, '');
14
+ * return <span>{textValue}</span>;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function useDataBinding<T = unknown>(surfaceId: string, source: ValueSource | undefined, defaultValue?: T): T;
19
+ /**
20
+ * Gets the full data model for a surface.
21
+ * Useful for components that need access to multiple values.
22
+ *
23
+ * @param surfaceId - The surface ID
24
+ * @returns The data model for this surface
25
+ */
26
+ export declare function useDataModel(surfaceId: string): DataModel;
27
+ /**
28
+ * Hook for two-way data binding in form components.
29
+ * Returns both the current value and a setter function.
30
+ *
31
+ * @param surfaceId - The surface ID
32
+ * @param source - The value source (must be a path reference for setting)
33
+ * @param defaultValue - Default value if not found
34
+ * @returns Tuple of [value, setValue]
35
+ *
36
+ * @example
37
+ * ```tsx
38
+ * function TextFieldComponent({ surfaceId, text }) {
39
+ * const [value, setValue] = useFormBinding<string>(surfaceId, text, '');
40
+ *
41
+ * return (
42
+ * <input
43
+ * value={value}
44
+ * onChange={(e) => setValue(e.target.value)}
45
+ * />
46
+ * );
47
+ * }
48
+ * ```
49
+ */
50
+ export declare function useFormBinding<T = unknown>(surfaceId: string, source: ValueSource | undefined, defaultValue?: T): [T, (value: T) => void];
@@ -0,0 +1,28 @@
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
+ function s(n, t, o) {
5
+ const { getDataModel: e } = l();
6
+ return i(() => {
7
+ const a = e(n);
8
+ return m(t, a, o);
9
+ }, [e, n, t, o]);
10
+ }
11
+ function u(n) {
12
+ const { getDataModel: t } = l();
13
+ return i(() => t(n), [t, n]);
14
+ }
15
+ function h(n, t, o) {
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);
21
+ }, [a, n, t]);
22
+ return [M, D];
23
+ }
24
+ export {
25
+ s as useDataBinding,
26
+ u as useDataModel,
27
+ h as useFormBinding
28
+ };
@@ -0,0 +1,22 @@
1
+ import { Action } from '@a2ui-sdk/types/0.8';
2
+ /**
3
+ * Returns a function to dispatch actions.
4
+ *
5
+ * @returns A function that dispatches actions
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * function ButtonComponent({ surfaceId, componentId, action }) {
10
+ * const dispatchAction = useDispatchAction();
11
+ *
12
+ * const handleClick = () => {
13
+ * if (action) {
14
+ * dispatchAction(surfaceId, componentId, action);
15
+ * }
16
+ * };
17
+ *
18
+ * return <button onClick={handleClick}>Click me</button>;
19
+ * }
20
+ * ```
21
+ */
22
+ export declare function useDispatchAction(): (surfaceId: string, componentId: string, action: Action) => void;
@@ -0,0 +1,8 @@
1
+ import { useActionContext as o } from "../contexts/ActionContext.js";
2
+ function c() {
3
+ const { dispatchAction: t } = o();
4
+ return t;
5
+ }
6
+ export {
7
+ c as useDispatchAction
8
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A2UI React Renderer - Public API
3
+ *
4
+ * This is the main entry point for the A2UI React renderer library.
5
+ * Import from '@a2ui-sdk/react/0.8'
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { A2UIProvider, A2UIRenderer, A2UIMessage, A2UIAction } from '@a2ui-sdk/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
+ * ```
34
+ */
35
+ export type { A2UIMessage, ActionPayload as A2UIAction, Action, ValueSource, } from '@a2ui-sdk/types/0.8';
36
+ export type { A2UIProviderProps, ComponentsMap } from './contexts/A2UIProvider';
37
+ export type { A2UIRendererProps } from './A2UIRenderer';
38
+ export { A2UIProvider } from './contexts/A2UIProvider';
39
+ export { A2UIRenderer } from './A2UIRenderer';
40
+ export { ComponentRenderer } from './components/ComponentRenderer';
41
+ export { useDispatchAction } from './hooks/useDispatchAction';
42
+ export { useDataBinding, useFormBinding } from './hooks/useDataBinding';
43
+ export { useSurfaceContext } from './contexts/SurfaceContext';
44
+ export { useDataModelContext } from './contexts/DataModelContext';
@@ -0,0 +1,17 @@
1
+ import { A2UIProvider as r } from "./contexts/A2UIProvider.js";
2
+ import { A2UIRenderer as n } from "./A2UIRenderer.js";
3
+ import { ComponentRenderer as p } from "./components/ComponentRenderer.js";
4
+ import { useDispatchAction as f } from "./hooks/useDispatchAction.js";
5
+ import { useDataBinding as a, useFormBinding as d } from "./hooks/useDataBinding.js";
6
+ import { useSurfaceContext as u } from "./contexts/SurfaceContext.js";
7
+ import { useDataModelContext as A } from "./contexts/DataModelContext.js";
8
+ export {
9
+ r as A2UIProvider,
10
+ n as A2UIRenderer,
11
+ p as ComponentRenderer,
12
+ a as useDataBinding,
13
+ A as useDataModelContext,
14
+ f as useDispatchAction,
15
+ d as useFormBinding,
16
+ u as useSurfaceContext
17
+ };