@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,118 @@
1
+ import { jsx as P } from "react/jsx-runtime";
2
+ import { createContext as b, useContext as A, useState as U, useCallback as a, useMemo as $ } from "react";
3
+ import { setValueByPath as y } from "../utils/pathUtils.js";
4
+ const C = b(null);
5
+ function z({ children: f }) {
6
+ const [r, s] = U(/* @__PURE__ */ new Map()), i = a((e, n) => {
7
+ s((t) => {
8
+ if (t.has(e))
9
+ return console.error(
10
+ `[A2UI 0.9] Surface "${e}" already exists. Ignoring createSurface.`
11
+ ), t;
12
+ const o = new Map(t);
13
+ return o.set(e, {
14
+ surfaceId: e,
15
+ catalogId: n,
16
+ components: /* @__PURE__ */ new Map(),
17
+ dataModel: {},
18
+ created: !0
19
+ }), o;
20
+ });
21
+ }, []), p = a(
22
+ (e, n) => {
23
+ s((t) => {
24
+ const o = t.get(e);
25
+ if (!o)
26
+ return console.warn(
27
+ `[A2UI 0.9] updateComponents called for non-existent surface "${e}". Components will be buffered until createSurface is received.`
28
+ ), t;
29
+ const c = new Map(t), u = new Map(o.components);
30
+ for (const d of n)
31
+ u.set(d.id, d);
32
+ return c.set(e, {
33
+ ...o,
34
+ components: u
35
+ }), c;
36
+ });
37
+ },
38
+ []
39
+ ), l = a(
40
+ (e, n, t) => {
41
+ s((o) => {
42
+ const c = o.get(e);
43
+ if (!c)
44
+ return console.warn(
45
+ `[A2UI 0.9] updateDataModel called for non-existent surface "${e}".`
46
+ ), o;
47
+ const u = new Map(o), d = n ?? "/", D = y(
48
+ c.dataModel,
49
+ d,
50
+ t
51
+ );
52
+ return u.set(e, {
53
+ ...c,
54
+ dataModel: D
55
+ }), u;
56
+ });
57
+ },
58
+ []
59
+ ), m = a((e) => {
60
+ s((n) => {
61
+ const t = new Map(n);
62
+ return t.delete(e), t;
63
+ });
64
+ }, []), M = a(
65
+ (e) => r.get(e),
66
+ [r]
67
+ ), x = a(
68
+ (e, n) => r.get(e)?.components.get(n),
69
+ [r]
70
+ ), w = a(
71
+ (e) => r.get(e)?.dataModel ?? {},
72
+ [r]
73
+ ), S = a(
74
+ (e, n, t) => {
75
+ l(e, n, t);
76
+ },
77
+ [l]
78
+ ), g = a(() => {
79
+ s(/* @__PURE__ */ new Map());
80
+ }, []), h = $(
81
+ () => ({
82
+ surfaces: r,
83
+ createSurface: i,
84
+ updateComponents: p,
85
+ updateDataModel: l,
86
+ deleteSurface: m,
87
+ getSurface: M,
88
+ getComponent: x,
89
+ getDataModel: w,
90
+ setDataValue: S,
91
+ clearSurfaces: g
92
+ }),
93
+ [
94
+ r,
95
+ i,
96
+ p,
97
+ l,
98
+ m,
99
+ M,
100
+ x,
101
+ w,
102
+ S,
103
+ g
104
+ ]
105
+ );
106
+ return /* @__PURE__ */ P(C.Provider, { value: h, children: f });
107
+ }
108
+ function B() {
109
+ const f = A(C);
110
+ if (!f)
111
+ throw new Error("useSurfaceContext must be used within a SurfaceProvider");
112
+ return f;
113
+ }
114
+ export {
115
+ C as SurfaceContext,
116
+ z as SurfaceProvider,
117
+ B as useSurfaceContext
118
+ };
@@ -0,0 +1,44 @@
1
+ import { A2UIMessage } from '@a2ui-sdk/types/0.9';
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 buffered messages */
11
+ clear: () => void;
12
+ }
13
+ /**
14
+ * Hook that returns functions to process A2UI 0.9 messages.
15
+ *
16
+ * Messages received before createSurface are buffered and applied
17
+ * when createSurface is received.
18
+ *
19
+ * @returns Object with processMessage, processMessages, and clear functions
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * function MyComponent() {
24
+ * const { processMessage, processMessages, clear } = useA2UIMessageHandler();
25
+ *
26
+ * useEffect(() => {
27
+ * // Process initial messages
28
+ * processMessages(initialMessages);
29
+ *
30
+ * // Listen for SSE updates
31
+ * const handler = (event) => {
32
+ * processMessage(JSON.parse(event.data));
33
+ * };
34
+ * eventSource.addEventListener('message', handler);
35
+ *
36
+ * return () => {
37
+ * eventSource.close();
38
+ * clear();
39
+ * };
40
+ * }, []);
41
+ * }
42
+ * ```
43
+ */
44
+ export declare function useA2UIMessageHandler(): A2UIMessageHandler;
@@ -0,0 +1,87 @@
1
+ import { useRef as S, useCallback as a } from "react";
2
+ import { useSurfaceContext as D } from "../contexts/SurfaceContext.js";
3
+ function x() {
4
+ const {
5
+ createSurface: p,
6
+ updateComponents: o,
7
+ updateDataModel: u,
8
+ deleteSurface: l,
9
+ clearSurfaces: i
10
+ } = D(), n = S(/* @__PURE__ */ new Map()), c = S(/* @__PURE__ */ new Set()), M = a(
11
+ (t) => {
12
+ const e = n.current.get(t);
13
+ if (!(!e || e.length === 0)) {
14
+ for (const r of e)
15
+ if ("updateComponents" in r)
16
+ o(t, r.updateComponents.components);
17
+ else if ("updateDataModel" in r) {
18
+ const { path: d, value: m } = r.updateDataModel;
19
+ u(t, d, m);
20
+ }
21
+ n.current.delete(t);
22
+ }
23
+ },
24
+ [o, u]
25
+ ), s = a(
26
+ (t, e) => {
27
+ const r = n.current.get(t) ?? [];
28
+ n.current.set(t, [...r, e]);
29
+ },
30
+ []
31
+ ), f = a(
32
+ (t) => {
33
+ if ("createSurface" in t) {
34
+ const { surfaceId: e, catalogId: r } = t.createSurface;
35
+ p(e, r), c.current.add(e), M(e);
36
+ return;
37
+ }
38
+ if ("updateComponents" in t) {
39
+ const { surfaceId: e, components: r } = t.updateComponents;
40
+ if (!c.current.has(e)) {
41
+ s(e, t);
42
+ return;
43
+ }
44
+ o(e, r);
45
+ return;
46
+ }
47
+ if ("updateDataModel" in t) {
48
+ const { surfaceId: e, path: r, value: d } = t.updateDataModel;
49
+ if (!c.current.has(e)) {
50
+ s(e, t);
51
+ return;
52
+ }
53
+ u(e, r, d);
54
+ return;
55
+ }
56
+ if ("deleteSurface" in t) {
57
+ const { surfaceId: e } = t.deleteSurface;
58
+ l(e), c.current.delete(e), n.current.delete(e);
59
+ return;
60
+ }
61
+ },
62
+ [
63
+ p,
64
+ o,
65
+ u,
66
+ l,
67
+ M,
68
+ s
69
+ ]
70
+ ), C = a(
71
+ (t) => {
72
+ for (const e of t)
73
+ f(e);
74
+ },
75
+ [f]
76
+ ), h = a(() => {
77
+ i(), n.current.clear(), c.current.clear();
78
+ }, [i]);
79
+ return {
80
+ processMessage: f,
81
+ processMessages: C,
82
+ clear: h
83
+ };
84
+ }
85
+ export {
86
+ x as useA2UIMessageHandler
87
+ };
@@ -0,0 +1,23 @@
1
+ import { Component } from '@a2ui-sdk/types/0.9';
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 Component, 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
+ * // Use component.component to get the type ("Text", "Button", etc.)
19
+ * // All other properties are available directly on the component
20
+ * }
21
+ * ```
22
+ */
23
+ export declare function useComponent(surfaceId: string, componentId: string): Component | 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,59 @@
1
+ import { DynamicValue, DynamicString, DataModel, FormBindableValue } from '@a2ui-sdk/types/0.9';
2
+ /**
3
+ * Resolves a DynamicValue to its actual value.
4
+ *
5
+ * @param surfaceId - The surface ID for data model lookup
6
+ * @param source - The dynamic value (literal or path binding)
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, component }) {
13
+ * const textValue = useDataBinding<string>(surfaceId, component.text, '');
14
+ * return <span>{textValue}</span>;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function useDataBinding<T = unknown>(surfaceId: string, source: DynamicValue | undefined, defaultValue?: T): T;
19
+ /**
20
+ * Resolves a DynamicString to a string value.
21
+ *
22
+ * @param surfaceId - The surface ID for data model lookup
23
+ * @param source - The dynamic string value
24
+ * @param defaultValue - Default value if source is undefined or path not found
25
+ * @returns The resolved string
26
+ */
27
+ export declare function useStringBinding(surfaceId: string, source: DynamicString | undefined, defaultValue?: string): string;
28
+ /**
29
+ * Gets the full data model for a surface.
30
+ * Useful for components that need access to multiple values.
31
+ *
32
+ * @param surfaceId - The surface ID
33
+ * @returns The data model for this surface
34
+ */
35
+ export declare function useDataModel(surfaceId: string): DataModel;
36
+ /**
37
+ * Hook for two-way data binding in form components.
38
+ * Returns both the current value and a setter function.
39
+ *
40
+ * @param surfaceId - The surface ID
41
+ * @param source - The dynamic value (must be a path binding for setting)
42
+ * @param defaultValue - Default value if not found
43
+ * @returns Tuple of [value, setValue]
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * function TextFieldComponent({ surfaceId, component }) {
48
+ * const [value, setValue] = useFormBinding<string>(surfaceId, component.value, '');
49
+ *
50
+ * return (
51
+ * <input
52
+ * value={value}
53
+ * onChange={(e) => setValue(e.target.value)}
54
+ * />
55
+ * );
56
+ * }
57
+ * ```
58
+ */
59
+ export declare function useFormBinding<T = unknown>(surfaceId: string, source: FormBindableValue | undefined, defaultValue?: T): [T, (value: T) => void];
@@ -0,0 +1,43 @@
1
+ import { useMemo as r, useCallback as D } from "react";
2
+ import { useSurfaceContext as s } from "../contexts/SurfaceContext.js";
3
+ import { useScope as g } from "../contexts/ScopeContext.js";
4
+ import { resolveString as d, resolveValue as h, isPathBinding as c } from "../utils/dataBinding.js";
5
+ function S(n, t, a) {
6
+ const { getDataModel: e } = s(), { basePath: i } = g();
7
+ return r(() => {
8
+ const o = e(n);
9
+ return h(t, o, i, a);
10
+ }, [e, n, t, i, a]);
11
+ }
12
+ function v(n, t, a = "") {
13
+ const { getDataModel: e } = s(), { basePath: i } = g();
14
+ return r(() => {
15
+ const o = e(n);
16
+ return d(t, o, i, a);
17
+ }, [e, n, t, i, a]);
18
+ }
19
+ function $(n) {
20
+ const { getDataModel: t } = s();
21
+ return r(() => t(n), [t, n]);
22
+ }
23
+ function x(n, t, a) {
24
+ const { getDataModel: e, setDataValue: i } = s(), { basePath: o } = g(), l = r(() => {
25
+ const p = e(n);
26
+ return h(t, p, o, a);
27
+ }, [e, n, t, o, a]), m = D(
28
+ (p) => {
29
+ if (c(t)) {
30
+ const M = t.path.startsWith("/") ? t.path : o ? `${o}/${t.path}` : `/${t.path}`;
31
+ i(n, M, p);
32
+ }
33
+ },
34
+ [i, n, t, o]
35
+ );
36
+ return [l, m];
37
+ }
38
+ export {
39
+ S as useDataBinding,
40
+ $ as useDataModel,
41
+ x as useFormBinding,
42
+ v as useStringBinding
43
+ };
@@ -0,0 +1,22 @@
1
+ import { Action } from '@a2ui-sdk/types/0.9';
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, component }) {
10
+ * const dispatchAction = useDispatchAction();
11
+ *
12
+ * const handleClick = () => {
13
+ * if (component.action) {
14
+ * dispatchAction(surfaceId, component.id, component.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,17 @@
1
+ import { useCallback as a } from "react";
2
+ import { useActionContext as i } from "../contexts/ActionContext.js";
3
+ import { useSurfaceContext as m } from "../contexts/SurfaceContext.js";
4
+ import { useScope as p } from "../contexts/ScopeContext.js";
5
+ function h() {
6
+ const { dispatchAction: t } = i(), { getDataModel: o } = m(), { basePath: e } = p();
7
+ return a(
8
+ (c, n, r) => {
9
+ const s = o(c);
10
+ t(c, n, r, s, e);
11
+ },
12
+ [t, o, e]
13
+ );
14
+ }
15
+ export {
16
+ h as useDispatchAction
17
+ };
@@ -0,0 +1,25 @@
1
+ import { CheckRule, ValidationResult } from '@a2ui-sdk/types/0.9';
2
+ import { ValidationFunction } from '../utils/validation';
3
+ /**
4
+ * Hook for evaluating validation checks on a component.
5
+ *
6
+ * @param surfaceId - The surface ID for data model lookup
7
+ * @param checks - Array of check rules to evaluate
8
+ * @param customFunctions - Optional custom validation functions
9
+ * @returns ValidationResult with valid flag and error messages
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * function TextFieldComponent({ surfaceId, component }) {
14
+ * const { valid, errors } = useValidation(surfaceId, component.checks);
15
+ *
16
+ * return (
17
+ * <div>
18
+ * <input className={!valid ? 'error' : ''} />
19
+ * {errors.map(err => <span key={err} className="error">{err}</span>)}
20
+ * </div>
21
+ * );
22
+ * }
23
+ * ```
24
+ */
25
+ export declare function useValidation(surfaceId: string, checks: CheckRule[] | undefined, customFunctions?: Record<string, ValidationFunction>): ValidationResult;
@@ -0,0 +1,14 @@
1
+ import { useMemo as n } from "react";
2
+ import { useSurfaceContext as i } from "../contexts/SurfaceContext.js";
3
+ import { useScope as p } from "../contexts/ScopeContext.js";
4
+ import { evaluateChecks as u } from "../utils/validation.js";
5
+ function M(o, t, e) {
6
+ const { getDataModel: r } = i(), { basePath: a } = p();
7
+ return n(() => {
8
+ const m = r(o);
9
+ return u(t, m, a, e);
10
+ }, [r, o, t, a, e]);
11
+ }
12
+ export {
13
+ M as useValidation
14
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A2UI 0.9 React Renderer - Public API
3
+ *
4
+ * This is the main entry point for the A2UI 0.9 React renderer library.
5
+ * Import from '@a2ui-sdk/react/0.9'
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * import { A2UIProvider, A2UIRenderer, A2UIMessage, A2UIAction } from '@a2ui-sdk/react/0.9'
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
+ */
24
+ export type { A2UIMessage, CreateSurfacePayload, UpdateComponentsPayload, UpdateDataModelPayload, DeleteSurfacePayload, Component, TextComponent, ImageComponent, IconComponent, VideoComponent, AudioPlayerComponent, DividerComponent, RowComponent, ColumnComponent, ListComponent, CardComponent, TabsComponent, ModalComponent, ButtonComponent, TextFieldComponent, CheckBoxComponent, ChoicePickerComponent, SliderComponent, DateTimeInputComponent, DynamicValue, DynamicString, DynamicNumber, DynamicBoolean, DynamicStringList, ChildList, TemplateBinding, Action, ActionPayload as A2UIAction, ActionHandler, CheckRule, Checkable, ValidationResult, ScopeValue, DataModel, } from '@a2ui-sdk/types/0.9';
25
+ export type { A2UIProviderProps, ComponentsMap } from './contexts/A2UIProvider';
26
+ export type { A2UIRendererProps } from './A2UIRenderer';
27
+ export { A2UIProvider } from './contexts/A2UIProvider';
28
+ export { A2UIRenderer } from './A2UIRenderer';
29
+ export { ComponentRenderer } from './components/ComponentRenderer';
30
+ export { useDispatchAction } from './hooks/useDispatchAction';
31
+ export { useDataBinding, useFormBinding, useStringBinding, useDataModel, } from './hooks/useDataBinding';
32
+ export { useValidation } from './hooks/useValidation';
33
+ export { useSurfaceContext } from './contexts/SurfaceContext';
34
+ export { useScope, useScopeBasePath } from './contexts/ScopeContext';
35
+ export { validationFunctions, evaluateChecks, evaluateCheckRule, type ValidationFunction, type EvaluationContext, } from './utils/validation';
@@ -0,0 +1,26 @@
1
+ import { A2UIProvider as r } from "./contexts/A2UIProvider.js";
2
+ import { A2UIRenderer as n } from "./A2UIRenderer.js";
3
+ import { ComponentRenderer as i } from "./components/ComponentRenderer.js";
4
+ import { useDispatchAction as p } from "./hooks/useDispatchAction.js";
5
+ import { useDataBinding as m, useDataModel as f, useFormBinding as x, useStringBinding as d } from "./hooks/useDataBinding.js";
6
+ import { useValidation as l } from "./hooks/useValidation.js";
7
+ import { useSurfaceContext as h } from "./contexts/SurfaceContext.js";
8
+ import { useScope as B, useScopeBasePath as C } from "./contexts/ScopeContext.js";
9
+ import { evaluateCheckRule as A, evaluateChecks as D, validationFunctions as R } from "./utils/validation.js";
10
+ export {
11
+ r as A2UIProvider,
12
+ n as A2UIRenderer,
13
+ i as ComponentRenderer,
14
+ A as evaluateCheckRule,
15
+ D as evaluateChecks,
16
+ m as useDataBinding,
17
+ f as useDataModel,
18
+ p as useDispatchAction,
19
+ x as useFormBinding,
20
+ B as useScope,
21
+ C as useScopeBasePath,
22
+ d as useStringBinding,
23
+ h as useSurfaceContext,
24
+ l as useValidation,
25
+ R as validationFunctions
26
+ };
@@ -0,0 +1,126 @@
1
+ import { DynamicValue, DynamicString, DataModel, FormBindableValue } from '@a2ui-sdk/types/0.9';
2
+ /**
3
+ * Type guard to check if a value is a path binding.
4
+ *
5
+ * @param value - The value to check
6
+ * @returns True if the value is a path binding object
7
+ *
8
+ * @example
9
+ * isPathBinding({ path: "/user/name" }); // true
10
+ * isPathBinding("literal"); // false
11
+ * isPathBinding({ call: "required" }); // false
12
+ */
13
+ export declare function isPathBinding(value: FormBindableValue | undefined | null): value is {
14
+ path: string;
15
+ };
16
+ /**
17
+ * Type guard to check if a value is a function call.
18
+ *
19
+ * @param value - The value to check
20
+ * @returns True if the value is a function call object
21
+ */
22
+ export declare function isFunctionCall(value: FormBindableValue | undefined | null): value is {
23
+ call: string;
24
+ args?: Record<string, DynamicValue>;
25
+ };
26
+ /**
27
+ * Gets the path from a dynamic value, or undefined if it's not a path binding.
28
+ *
29
+ * @param value - The dynamic value
30
+ * @returns The path string or undefined
31
+ */
32
+ export declare function getBindingPath(value: FormBindableValue | undefined | null): string | undefined;
33
+ /**
34
+ * Resolves a dynamic value to its actual value.
35
+ *
36
+ * Resolution order:
37
+ * 1. If value is a path binding object → resolve from data model
38
+ * 2. If value is a function call → return undefined (function calls not evaluated here)
39
+ * 3. Otherwise → return literal value
40
+ *
41
+ * @param value - The dynamic value (literal, path binding, or function call)
42
+ * @param dataModel - The data model for path lookups
43
+ * @param basePath - Optional base path for relative path resolution
44
+ * @param defaultValue - Default value if undefined or path not found
45
+ * @returns The resolved value
46
+ *
47
+ * @example
48
+ * // Literal values
49
+ * resolveValue("Hello", {}); // "Hello"
50
+ * resolveValue(42, {}); // 42
51
+ * resolveValue(true, {}); // true
52
+ *
53
+ * // Path bindings
54
+ * const model = { user: { name: "John" } };
55
+ * resolveValue({ path: "/user/name" }, model); // "John"
56
+ * resolveValue({ path: "name" }, model, "/user"); // "John" (relative)
57
+ * resolveValue({ path: "/nonexistent" }, model, null, "default"); // "default"
58
+ */
59
+ export declare function resolveValue<T = unknown>(value: FormBindableValue | undefined | null, dataModel: DataModel, basePath?: string | null, defaultValue?: T): T;
60
+ /**
61
+ * Resolves a DynamicString value to a string.
62
+ * This is a convenience wrapper for string values.
63
+ *
64
+ * Supports interpolation: if the string contains `${...}` expressions,
65
+ * they will be replaced with values from the data model.
66
+ *
67
+ * @param value - The dynamic string value
68
+ * @param dataModel - The data model for path lookups
69
+ * @param basePath - Optional base path for relative path resolution
70
+ * @param defaultValue - Default value if undefined or path not found
71
+ * @returns The resolved string
72
+ *
73
+ * @example
74
+ * // Simple string
75
+ * resolveString("Hello", {}); // "Hello"
76
+ *
77
+ * // Path binding
78
+ * resolveString({ path: "/user/name" }, { user: { name: "John" } }); // "John"
79
+ *
80
+ * // Interpolation
81
+ * resolveString("Hello, ${/user/name}!", { user: { name: "John" } }); // "Hello, John!"
82
+ */
83
+ export declare function resolveString(value: DynamicString | undefined | null, dataModel: DataModel, basePath?: string | null, defaultValue?: string): string;
84
+ /**
85
+ * Resolves a dynamic number value.
86
+ *
87
+ * @param value - The dynamic number value
88
+ * @param dataModel - The data model for path lookups
89
+ * @param basePath - Optional base path for relative path resolution
90
+ * @param defaultValue - Default value if undefined or path not found
91
+ * @returns The resolved number
92
+ */
93
+ export declare function resolveNumber(value: number | {
94
+ path: string;
95
+ } | undefined | null, dataModel: DataModel, basePath?: string | null, defaultValue?: number): number;
96
+ /**
97
+ * Resolves a dynamic boolean value.
98
+ *
99
+ * @param value - The dynamic boolean value
100
+ * @param dataModel - The data model for path lookups
101
+ * @param basePath - Optional base path for relative path resolution
102
+ * @param defaultValue - Default value if undefined or path not found
103
+ * @returns The resolved boolean
104
+ */
105
+ export declare function resolveBoolean(value: boolean | {
106
+ path: string;
107
+ } | undefined | null, dataModel: DataModel, basePath?: string | null, defaultValue?: boolean): boolean;
108
+ /**
109
+ * Resolves action context values to a plain object.
110
+ * All path bindings are resolved to their actual values.
111
+ *
112
+ * @param context - Object with dynamic values
113
+ * @param dataModel - The data model for path lookups
114
+ * @param basePath - Optional base path for relative path resolution
115
+ * @returns A plain object with resolved context values
116
+ *
117
+ * @example
118
+ * const context = {
119
+ * name: { path: "/user/name" },
120
+ * action: "submit",
121
+ * count: 42
122
+ * };
123
+ * resolveContext(context, { user: { name: "John" } });
124
+ * // Returns: { name: "John", action: "submit", count: 42 }
125
+ */
126
+ export declare function resolveContext(context: Record<string, DynamicValue> | undefined, dataModel: DataModel, basePath?: string | null): Record<string, unknown>;