@ukiahinsure/a2ui-react-adapter 0.1.22 → 0.1.23

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
@@ -55,6 +55,69 @@ var HospitalChoice = createComponentImplementation(ChoicePickerApi, ({ props, co
55
55
  import { useId as useId2, useLayoutEffect, useRef, useState } from "react";
56
56
  import { createComponentImplementation as createComponentImplementation2 } from "@a2ui/react/v0_9";
57
57
  import { DateTimeInputApi } from "@a2ui/web_core/v0_9/basic_catalog";
58
+
59
+ // src/fieldLabel.ts
60
+ var ACRONYMS = {
61
+ aep: "AEP",
62
+ champva: "CHAMPVA",
63
+ dob: "DOB",
64
+ hmo: "HMO",
65
+ id: "ID",
66
+ iep: "IEP",
67
+ lis: "LIS",
68
+ ma: "MA",
69
+ mapd: "MAPD",
70
+ mbi: "MBI",
71
+ npi: "NPI",
72
+ oep: "OEP",
73
+ pcp: "PCP",
74
+ pdp: "PDP",
75
+ ppo: "PPO",
76
+ sep: "SEP",
77
+ snp: "SNP",
78
+ ssn: "SSN",
79
+ tricare: "TRICARE",
80
+ url: "URL",
81
+ us: "US",
82
+ va: "VA",
83
+ zip: "ZIP"
84
+ };
85
+ var MINOR_WORDS = /* @__PURE__ */ new Set([
86
+ "a",
87
+ "an",
88
+ "and",
89
+ "for",
90
+ "in",
91
+ "of",
92
+ "on",
93
+ "or",
94
+ "the",
95
+ "to",
96
+ "with"
97
+ ]);
98
+ function displayFieldLabel(field) {
99
+ const words = field.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_-]+/).filter(Boolean);
100
+ return words.map((word, index) => displayFieldLabelWord(word, index, words[index - 1])).join(" ");
101
+ }
102
+ function readableLabel(label) {
103
+ return /^[a-z][a-z0-9]*(_[a-z0-9]+)+$/.test(label) ? displayFieldLabel(label) : label;
104
+ }
105
+ function displayFieldLabelWord(word, index, previous) {
106
+ const lower = word.toLowerCase();
107
+ if (previous?.toLowerCase() === "part" && /^[a-d]$/.test(lower)) {
108
+ return lower.toUpperCase();
109
+ }
110
+ const acronym = ACRONYMS[lower];
111
+ if (acronym !== void 0) {
112
+ return acronym;
113
+ }
114
+ if (index > 0 && MINOR_WORDS.has(lower)) {
115
+ return lower;
116
+ }
117
+ return lower.charAt(0).toUpperCase() + lower.slice(1);
118
+ }
119
+
120
+ // src/DateTimeInput.tsx
58
121
  import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
59
122
  var inputStyle = {
60
123
  backgroundColor: "var(--a2ui-datetimeinput-background, var(--a2ui-color-input, #fff))",
@@ -167,7 +230,7 @@ function DateOnlyInput(props) {
167
230
  "button",
168
231
  {
169
232
  type: "button",
170
- "aria-label": `Choose ${props.label || "date"} from calendar`,
233
+ "aria-label": `Choose ${props.label ? readableLabel(props.label) : "date"} from calendar`,
171
234
  style: inputStyle,
172
235
  onClick: () => openPicker(pickerRef.current, () => setPickerOpen(true)),
173
236
  children: "\u25A6"
@@ -178,7 +241,7 @@ function DateOnlyInput(props) {
178
241
  {
179
242
  ref: pickerRef,
180
243
  type: "date",
181
- "aria-label": `${props.label || "Date"} calendar`,
244
+ "aria-label": `${props.label ? readableLabel(props.label) : "Date"} calendar`,
182
245
  tabIndex: pickerOpen ? 0 : -1,
183
246
  "aria-hidden": !pickerOpen,
184
247
  "data-a2ui-calendar-input": "true",
@@ -2665,6 +2728,21 @@ function formatFieldLabels(root) {
2665
2728
  originals.set(element, element.textContent ?? "");
2666
2729
  element.textContent = displayFieldLabel(field);
2667
2730
  }
2731
+ const fields = new Set(
2732
+ [...root.querySelectorAll("[data-a2ui-field]")].map((control) => control.dataset.a2uiField).filter((field) => field !== void 0)
2733
+ );
2734
+ for (const element of root.querySelectorAll("*")) {
2735
+ if (element.childElementCount !== 0 || originals.has(element)) {
2736
+ continue;
2737
+ }
2738
+ const text = element.textContent ?? "";
2739
+ const match = /^(\s*)([A-Za-z][A-Za-z0-9_]*)(\s+\S[\s\S]*)$/.exec(text);
2740
+ if (match === null || !fields.has(match[2]) || !match[2].includes("_")) {
2741
+ continue;
2742
+ }
2743
+ originals.set(element, text);
2744
+ element.textContent = `${match[1]}${displayFieldLabel(match[2])}${match[3]}`;
2745
+ }
2668
2746
  return () => {
2669
2747
  for (const [label, text] of originals) {
2670
2748
  label.textContent = text;
@@ -3355,28 +3433,6 @@ function labelElementForControl(root, control) {
3355
3433
  const label = root.ownerDocument.getElementById(labelledBy);
3356
3434
  return label instanceof HTMLElement && root.contains(label) ? label : void 0;
3357
3435
  }
3358
- function displayFieldLabel(field) {
3359
- const words = field.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_-]+/).filter(Boolean);
3360
- return words.map((word, index) => displayFieldLabelWord(word, index)).join(" ");
3361
- }
3362
- function displayFieldLabelWord(word, index) {
3363
- const lower = word.toLowerCase();
3364
- const acronyms = {
3365
- dob: "DOB",
3366
- id: "ID",
3367
- ssn: "SSN",
3368
- url: "URL",
3369
- us: "US",
3370
- zip: "ZIP"
3371
- };
3372
- if (lower in acronyms) {
3373
- return acronyms[lower];
3374
- }
3375
- if (index > 0 && ["a", "an", "and", "for", "in", "of", "on", "or", "the", "to", "with"].includes(lower)) {
3376
- return lower;
3377
- }
3378
- return lower.charAt(0).toUpperCase() + lower.slice(1);
3379
- }
3380
3436
  function cssString(value) {
3381
3437
  return globalThis.CSS?.escape?.(value) ?? value.replace(/["\\]/g, "\\$&");
3382
3438
  }