@ukiahinsure/a2ui-react-adapter 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import {
10
10
  } from "./chunk-AOBRTDAU.js";
11
11
 
12
12
  // src/adapter.ts
13
- import { basicCatalog } from "@a2ui/react/v0_9";
13
+ import { basicCatalog as basicCatalog2 } from "@a2ui/react/v0_9";
14
14
  import {
15
15
  A2uiError,
16
16
  Catalog,
@@ -18,11 +18,44 @@ import {
18
18
  MessageProcessor
19
19
  } from "@a2ui/web_core/v0_9";
20
20
 
21
+ // src/HospitalChoice.tsx
22
+ import { useId } from "react";
23
+ import { basicCatalog, createComponentImplementation } from "@a2ui/react/v0_9";
24
+ import { ChoicePickerApi } from "@a2ui/web_core/v0_9/basic_catalog";
25
+ import { jsx, jsxs } from "react/jsx-runtime";
26
+ var OriginalChoice = basicCatalog.components.get("ChoicePicker").render;
27
+ var HospitalChoice = createComponentImplementation(ChoicePickerApi, ({ props, context, buildChild }) => {
28
+ const id = useId();
29
+ if (props.label !== "hospital_preference") {
30
+ return /* @__PURE__ */ jsx(OriginalChoice, { context, buildChild });
31
+ }
32
+ const selected = Array.isArray(props.value) ? props.value[0] ?? "" : "";
33
+ return /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: "0.25rem" }, children: [
34
+ /* @__PURE__ */ jsx("label", { htmlFor: id, children: "Hospital preference" }),
35
+ /* @__PURE__ */ jsxs(
36
+ "select",
37
+ {
38
+ id,
39
+ "data-a2ui-field": "hospital_preference",
40
+ value: selected,
41
+ required: true,
42
+ style: { padding: "0.5rem", border: "var(--a2ui-border)", borderRadius: "var(--a2ui-border-radius)" },
43
+ onChange: (event) => props.setValue(event.currentTarget.value ? [event.currentTarget.value] : []),
44
+ children: [
45
+ /* @__PURE__ */ jsx("option", { value: "", children: "Choose Prefer or Avoid" }),
46
+ /* @__PURE__ */ jsx("option", { value: "Prefer", children: "Prefer" }),
47
+ /* @__PURE__ */ jsx("option", { value: "Avoid", children: "Avoid" })
48
+ ]
49
+ }
50
+ )
51
+ ] });
52
+ });
53
+
21
54
  // src/DateTimeInput.tsx
22
- import { useId, useLayoutEffect, useRef, useState } from "react";
23
- import { createComponentImplementation } from "@a2ui/react/v0_9";
55
+ import { useId as useId2, useLayoutEffect, useRef, useState } from "react";
56
+ import { createComponentImplementation as createComponentImplementation2 } from "@a2ui/react/v0_9";
24
57
  import { DateTimeInputApi } from "@a2ui/web_core/v0_9/basic_catalog";
25
- import { jsx, jsxs } from "react/jsx-runtime";
58
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
26
59
  var inputStyle = {
27
60
  backgroundColor: "var(--a2ui-datetimeinput-background, var(--a2ui-color-input, #fff))",
28
61
  color: "var(--a2ui-datetimeinput-color, var(--a2ui-color-on-input, #333))",
@@ -50,7 +83,7 @@ function displayDate(value) {
50
83
  return iso ? `${iso.slice(5, 7)}/${iso.slice(8, 10)}/${iso.slice(0, 4)}` : value;
51
84
  }
52
85
  function DateOnlyInput(props) {
53
- const id = useId();
86
+ const id = useId2();
54
87
  const [draft, setDraft] = useState(() => displayDate(props.value || ""));
55
88
  const [pickerOpen, setPickerOpen] = useState(false);
56
89
  const published = useRef(props.value || "");
@@ -76,10 +109,10 @@ function DateOnlyInput(props) {
76
109
  published.current = value;
77
110
  props.setValue(value);
78
111
  };
79
- return /* @__PURE__ */ jsxs("div", { "data-a2ui-date-editor": "true", style: { display: "flex", flexDirection: "column", gap: "var(--a2ui-spacing-xs, 0.25rem)" }, children: [
80
- props.label && /* @__PURE__ */ jsx("label", { htmlFor: id, style: labelStyle, children: props.label }),
81
- /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.25rem", position: "relative" }, children: [
82
- /* @__PURE__ */ jsx(
112
+ return /* @__PURE__ */ jsxs2("div", { "data-a2ui-date-editor": "true", style: { display: "flex", flexDirection: "column", gap: "var(--a2ui-spacing-xs, 0.25rem)" }, children: [
113
+ props.label && /* @__PURE__ */ jsx2("label", { htmlFor: id, style: labelStyle, children: props.label }),
114
+ /* @__PURE__ */ jsxs2("div", { style: { display: "flex", gap: "0.25rem", position: "relative" }, children: [
115
+ /* @__PURE__ */ jsx2(
83
116
  "input",
84
117
  {
85
118
  ref: inputRef,
@@ -97,7 +130,7 @@ function DateOnlyInput(props) {
97
130
  style: { ...inputStyle, minWidth: 0, flex: 1 }
98
131
  }
99
132
  ),
100
- /* @__PURE__ */ jsx(
133
+ /* @__PURE__ */ jsx2(
101
134
  "button",
102
135
  {
103
136
  type: "button",
@@ -117,7 +150,7 @@ function DateOnlyInput(props) {
117
150
  children: "\u25A6"
118
151
  }
119
152
  ),
120
- /* @__PURE__ */ jsx(
153
+ /* @__PURE__ */ jsx2(
121
154
  "input",
122
155
  {
123
156
  ref: pickerRef,
@@ -140,15 +173,15 @@ function DateOnlyInput(props) {
140
173
  ] });
141
174
  }
142
175
  function NativeTimeInput(props) {
143
- const id = useId();
176
+ const id = useId2();
144
177
  const inputRef = useRef(null);
145
178
  const initialValue = useRef(props.value || "");
146
179
  useLayoutEffect(() => {
147
180
  if (inputRef.current && inputRef.current.value !== (props.value || "")) inputRef.current.value = props.value || "";
148
181
  }, [props.value]);
149
- return /* @__PURE__ */ jsxs("div", { children: [
150
- props.label && /* @__PURE__ */ jsx("label", { htmlFor: id, style: labelStyle, children: props.label }),
151
- /* @__PURE__ */ jsx(
182
+ return /* @__PURE__ */ jsxs2("div", { children: [
183
+ props.label && /* @__PURE__ */ jsx2("label", { htmlFor: id, style: labelStyle, children: props.label }),
184
+ /* @__PURE__ */ jsx2(
152
185
  "input",
153
186
  {
154
187
  ref: inputRef,
@@ -163,19 +196,19 @@ function NativeTimeInput(props) {
163
196
  )
164
197
  ] });
165
198
  }
166
- var DateTimeInput = createComponentImplementation(
199
+ var DateTimeInput = createComponentImplementation2(
167
200
  DateTimeInputApi,
168
- ({ props }) => props.enableDate && !props.enableTime ? /* @__PURE__ */ jsx(DateOnlyInput, { ...props }) : /* @__PURE__ */ jsx(NativeTimeInput, { ...props })
201
+ ({ props }) => props.enableDate && !props.enableTime ? /* @__PURE__ */ jsx2(DateOnlyInput, { ...props }) : /* @__PURE__ */ jsx2(NativeTimeInput, { ...props })
169
202
  );
170
203
 
171
204
  // src/adapter.ts
172
205
  var editableDateCatalog = new Catalog(
173
- basicCatalog.id,
174
- [...basicCatalog.components.values()].map(
175
- (component) => component.name === DateTimeInput.name ? DateTimeInput : component
206
+ basicCatalog2.id,
207
+ [...basicCatalog2.components.values()].map(
208
+ (component) => component.name === DateTimeInput.name ? DateTimeInput : component.name === HospitalChoice.name ? HospitalChoice : component
176
209
  ),
177
- [...basicCatalog.functions.values()],
178
- basicCatalog.themeSchema
210
+ [...basicCatalog2.functions.values()],
211
+ basicCatalog2.themeSchema
179
212
  );
180
213
  var RENDERER_NAME = "a2ui_react_adapter";
181
214
  var RENDERER_VERSION = "0.1.0";
@@ -203,7 +236,7 @@ var A2UIClientAdapter = class {
203
236
  }
204
237
  /** Catalog ids this adapter will announce in capability envelopes. */
205
238
  get supportedCatalogIds() {
206
- return [basicCatalog.id];
239
+ return [basicCatalog2.id];
207
240
  }
208
241
  get lastSeq() {
209
242
  return this.#lastSeq;
@@ -1714,13 +1747,13 @@ function classifyProcessingError(error) {
1714
1747
  // src/SurfaceHost.tsx
1715
1748
  import {
1716
1749
  Component,
1717
- useId as useId2,
1750
+ useId as useId3,
1718
1751
  useLayoutEffect as useLayoutEffect2,
1719
1752
  useRef as useRef2,
1720
1753
  useSyncExternalStore
1721
1754
  } from "react";
1722
1755
  import { A2uiSurface } from "@a2ui/react/v0_9";
1723
- import { jsx as jsx2 } from "react/jsx-runtime";
1756
+ import { jsx as jsx3 } from "react/jsx-runtime";
1724
1757
  function A2UISurfaceHost({
1725
1758
  adapter,
1726
1759
  surfaceId,
@@ -1747,7 +1780,7 @@ function A2UISurfaceHost({
1747
1780
  readSessionSnapshot,
1748
1781
  readSessionSnapshot
1749
1782
  );
1750
- const generatedId = useId2().replaceAll(":", "");
1783
+ const generatedId = useId3().replaceAll(":", "");
1751
1784
  const rootRef = useRef2(null);
1752
1785
  const lastFocusedState = useRef2(void 0);
1753
1786
  const lastViewedSection = useRef2(void 0);
@@ -1860,9 +1893,9 @@ function A2UISurfaceHost({
1860
1893
  version
1861
1894
  ]);
1862
1895
  if (surface === void 0) {
1863
- return noSurfaceFallback ?? /* @__PURE__ */ jsx2("div", { "data-a2ui-host": "no-surface", role: "status", "aria-live": "polite", children: "Your conversation continues by voice." });
1896
+ return noSurfaceFallback ?? /* @__PURE__ */ jsx3("div", { "data-a2ui-host": "no-surface", role: "status", "aria-live": "polite", children: "Your conversation continues by voice." });
1864
1897
  }
1865
- return /* @__PURE__ */ jsx2(
1898
+ return /* @__PURE__ */ jsx3(
1866
1899
  "div",
1867
1900
  {
1868
1901
  ref: rootRef,
@@ -1875,13 +1908,13 @@ function A2UISurfaceHost({
1875
1908
  "aria-busy": busy || void 0,
1876
1909
  "aria-disabled": disabled || busy || void 0,
1877
1910
  tabIndex: -1,
1878
- children: /* @__PURE__ */ jsx2(
1911
+ children: /* @__PURE__ */ jsx3(
1879
1912
  SurfaceErrorBoundary,
1880
1913
  {
1881
1914
  adapter,
1882
1915
  surface,
1883
- fallback: errorFallback ?? /* @__PURE__ */ jsx2("div", { "data-a2ui-host": "render-error", role: "alert", children: "This step can't be shown right now. Please continue by voice." }),
1884
- children: /* @__PURE__ */ jsx2(A2uiSurface, { surface })
1916
+ fallback: errorFallback ?? /* @__PURE__ */ jsx3("div", { "data-a2ui-host": "render-error", role: "alert", children: "This step can't be shown right now. Please continue by voice." }),
1917
+ children: /* @__PURE__ */ jsx3(A2uiSurface, { surface })
1885
1918
  },
1886
1919
  surface.id
1887
1920
  )
@@ -2175,7 +2208,7 @@ var SurfaceErrorBoundary = class extends Component {
2175
2208
  }
2176
2209
  render() {
2177
2210
  if (this.state.failedSurfaceId !== void 0) {
2178
- return /* @__PURE__ */ jsx2(
2211
+ return /* @__PURE__ */ jsx3(
2179
2212
  "div",
2180
2213
  {
2181
2214
  "data-a2ui-error-boundary": "true",
@@ -2393,7 +2426,7 @@ function blockInvalidActionControls(root) {
2393
2426
  };
2394
2427
  }
2395
2428
  function firstInvalidInput(root) {
2396
- return [...root.querySelectorAll("input[data-a2ui-field]")].filter((input) => input.type !== "radio" && !isControlDisabled(input)).find((input) => !input.checkValidity());
2429
+ return [...root.querySelectorAll("input[data-a2ui-field], select[data-a2ui-field]")].filter((input) => input.type !== "radio" && !isControlDisabled(input)).find((input) => !input.checkValidity());
2397
2430
  }
2398
2431
  function findFieldControls(root, field) {
2399
2432
  const labels = [...root.querySelectorAll("label")];
@@ -2867,11 +2900,23 @@ function renderSavedLoopEditInputs(editButton, row, orderedFields, summaryFields
2867
2900
  continue;
2868
2901
  }
2869
2902
  let input = value.querySelector(
2870
- "input[data-a2ui-loop-edit-input='true']"
2903
+ "[data-a2ui-loop-edit-input='true']"
2871
2904
  );
2872
2905
  if (input === null) {
2873
- input = row.ownerDocument.createElement("input");
2874
- input.type = "text";
2906
+ if (fieldName === "hospital_preference") {
2907
+ const select = row.ownerDocument.createElement("select");
2908
+ for (const choice of ["", "Prefer", "Avoid"]) {
2909
+ const option = row.ownerDocument.createElement("option");
2910
+ option.value = choice;
2911
+ option.textContent = choice || "Choose Prefer or Avoid";
2912
+ select.appendChild(option);
2913
+ }
2914
+ select.required = true;
2915
+ input = select;
2916
+ } else {
2917
+ input = row.ownerDocument.createElement("input");
2918
+ input.type = "text";
2919
+ }
2875
2920
  input.name = fieldName;
2876
2921
  input.setAttribute("aria-label", displayFieldLabel(fieldName));
2877
2922
  input.dataset.a2uiLoopEditInput = "true";
@@ -2897,7 +2942,7 @@ function renderSavedLoopEditInputs(editButton, row, orderedFields, summaryFields
2897
2942
  setText(editButton, "Save");
2898
2943
  if (focusFirstInput) {
2899
2944
  row.querySelector(
2900
- "input[data-a2ui-loop-edit-input='true']"
2945
+ "[data-a2ui-loop-edit-input='true']"
2901
2946
  )?.focus();
2902
2947
  }
2903
2948
  }
@@ -2919,7 +2964,7 @@ function savedLoopRowInputValues(orderedFields, summaryFields) {
2919
2964
  orderedFields.forEach((field, index) => {
2920
2965
  const fieldName = summaryFields[index];
2921
2966
  const input = field.querySelector(
2922
- "input[data-a2ui-loop-edit-input='true']"
2967
+ "[data-a2ui-loop-edit-input='true']"
2923
2968
  );
2924
2969
  const value = field.querySelector(
2925
2970
  "[data-a2ui-loop-cell='value']"
@@ -3001,7 +3046,7 @@ function normalizedLoopSummaryFields(fields) {
3001
3046
  if (hasPharmacyFields) {
3002
3047
  return pharmacyFields.filter((field) => withoutInternal.includes(field));
3003
3048
  }
3004
- const hospitalFields = ["hospital_name", "hospital_city_state"];
3049
+ const hospitalFields = ["hospital_name", "hospital_city_state", "hospital_preference"];
3005
3050
  const hasHospitalFields = hospitalFields.some(
3006
3051
  (field) => withoutInternal.includes(field)
3007
3052
  );
@@ -3117,7 +3162,8 @@ var LOOP_FIELD_LABELS = /* @__PURE__ */ new Map([
3117
3162
  ["pharmacy type", "pharmacy_type"],
3118
3163
  ["pharmacy address", "pharmacy_address"],
3119
3164
  ["hospital name", "hospital_name"],
3120
- ["hospital city state", "hospital_city_state"]
3165
+ ["hospital city state", "hospital_city_state"],
3166
+ ["hospital preference", "hospital_preference"]
3121
3167
  ]);
3122
3168
  function isSavedLoopSummary(element) {
3123
3169
  if (element.children.length > 0) {