@ukiahinsure/a2ui-react-adapter 0.1.9 → 0.1.11

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
@@ -1137,9 +1137,6 @@ function isProviderSubmitField(key) {
1137
1137
  "provider_name",
1138
1138
  "displayName",
1139
1139
  "display_name",
1140
- "doctorName",
1141
- "doctorname",
1142
- "doctor_name",
1143
1140
  "name",
1144
1141
  "primary_care_provider_location",
1145
1142
  "primaryCareProviderLocation",
@@ -1254,9 +1251,6 @@ var PROVIDER_NAME_FIELDS = /* @__PURE__ */ new Set([
1254
1251
  "providername",
1255
1252
  "display_name",
1256
1253
  "displayname",
1257
- "doctor",
1258
- "doctor_name",
1259
- "doctorname",
1260
1254
  "name"
1261
1255
  ]);
1262
1256
  var PROVIDER_LOCATION_FIELDS = /* @__PURE__ */ new Set([
@@ -1274,8 +1268,6 @@ var PROVIDER_LOCATION_FIELDS = /* @__PURE__ */ new Set([
1274
1268
  "providerlocation",
1275
1269
  "provider_location_details",
1276
1270
  "providerlocationdetails",
1277
- "doctor_location",
1278
- "doctorlocation",
1279
1271
  "location",
1280
1272
  "location_details",
1281
1273
  "locationdetails",
@@ -1285,8 +1277,6 @@ var PROVIDER_LOCATION_FIELDS = /* @__PURE__ */ new Set([
1285
1277
  "practicelocation",
1286
1278
  "provider_address",
1287
1279
  "provideraddress",
1288
- "doctor_address",
1289
- "doctoraddress",
1290
1280
  "address",
1291
1281
  "city_state",
1292
1282
  "citystate"
@@ -1510,6 +1500,7 @@ function A2UISurfaceHost({
1510
1500
  validationSummaryId
1511
1501
  ),
1512
1502
  formatFieldLabels(root),
1503
+ annotateSavedLoopTables(root),
1513
1504
  bindFieldInteractionGroups(
1514
1505
  root,
1515
1506
  resolvedSurfaceMetadata?.fieldInteractions ?? [],
@@ -2175,12 +2166,434 @@ function formatFieldLabels(root) {
2175
2166
  originals.set(label, label.textContent ?? "");
2176
2167
  label.textContent = displayFieldLabel(field);
2177
2168
  }
2169
+ for (const element of root.querySelectorAll("*")) {
2170
+ if (!isGeneratedTextElement(element) || originals.has(element)) {
2171
+ continue;
2172
+ }
2173
+ const field = generatedFieldLabelName(element.textContent ?? "");
2174
+ if (field === void 0) {
2175
+ continue;
2176
+ }
2177
+ originals.set(element, element.textContent ?? "");
2178
+ element.textContent = displayFieldLabel(field);
2179
+ }
2178
2180
  return () => {
2179
2181
  for (const [label, text] of originals) {
2180
2182
  label.textContent = text;
2181
2183
  }
2182
2184
  };
2183
2185
  }
2186
+ function generatedFieldLabelName(text) {
2187
+ const trimmed = text.trim();
2188
+ const unwrapped = trimmed.startsWith("*") && trimmed.endsWith("*") ? trimmed.slice(1, -1).trim() : trimmed;
2189
+ return /^[A-Za-z][A-Za-z0-9_]*$/.test(unwrapped) && /[_A-Z]/.test(unwrapped) ? unwrapped : void 0;
2190
+ }
2191
+ function annotateSavedLoopTables(root) {
2192
+ const originals = /* @__PURE__ */ new Map();
2193
+ const textOriginals = /* @__PURE__ */ new Map();
2194
+ const remember = (element) => {
2195
+ if (originals.has(element)) {
2196
+ return;
2197
+ }
2198
+ originals.set(element, {
2199
+ loopTable: element.dataset.a2uiLoopTable,
2200
+ loopRow: element.dataset.a2uiLoopRow,
2201
+ loopHeader: element.dataset.a2uiLoopHeader,
2202
+ loopField: element.dataset.a2uiLoopField,
2203
+ loopCell: element.dataset.a2uiLoopCell,
2204
+ loopColumn: element.dataset.a2uiLoopColumn,
2205
+ loopColumnCount: element.dataset.a2uiLoopColumnCount,
2206
+ loopLabel: element.dataset.a2uiLoopLabel,
2207
+ generatedHeader: element.dataset.a2uiLoopGeneratedHeader,
2208
+ hidden: element.getAttribute("hidden"),
2209
+ ariaHidden: element.getAttribute("aria-hidden")
2210
+ });
2211
+ };
2212
+ const setText = (element, text) => {
2213
+ if (!textOriginals.has(element)) {
2214
+ textOriginals.set(element, element.textContent ?? "");
2215
+ }
2216
+ element.textContent = text;
2217
+ };
2218
+ const generatedElements = [];
2219
+ const rows = [...root.querySelectorAll("div, section, article, li")].filter(
2220
+ (row) => getSavedLoopRowFields(row).length > 0 && normalizedLoopSummaryFields(getSavedLoopSummaryFields(row)).length >= 2
2221
+ );
2222
+ for (const row of rows) {
2223
+ const parent = row.parentElement;
2224
+ if (parent !== null) {
2225
+ remember(parent);
2226
+ parent.dataset.a2uiLoopTable = "true";
2227
+ }
2228
+ }
2229
+ const rowsByParent = /* @__PURE__ */ new Map();
2230
+ for (const row of rows) {
2231
+ const parent = row.parentElement;
2232
+ if (parent === null) {
2233
+ continue;
2234
+ }
2235
+ const siblings = rowsByParent.get(parent) ?? [];
2236
+ siblings.push(row);
2237
+ rowsByParent.set(parent, siblings);
2238
+ }
2239
+ for (const siblings of rowsByParent.values()) {
2240
+ const firstRow = siblings[0];
2241
+ const parent = firstRow?.parentElement;
2242
+ if (parent !== null && parent !== void 0 && firstRow !== void 0) {
2243
+ const header = buildSavedLoopHeader(parent, firstRow);
2244
+ if (header !== void 0) {
2245
+ parent.dataset.a2uiLoopColumnCount = header.dataset.a2uiLoopColumnCount ?? void 0;
2246
+ parent.insertBefore(header, firstRow);
2247
+ generatedElements.push(header);
2248
+ }
2249
+ }
2250
+ siblings.forEach((row, rowIndex) => {
2251
+ remember(row);
2252
+ row.dataset.a2uiLoopRow = "true";
2253
+ row.dataset.a2uiLoopHeader = "false";
2254
+ let columnIndex = 0;
2255
+ for (const child of [...row.children]) {
2256
+ if (!(child instanceof HTMLElement)) {
2257
+ continue;
2258
+ }
2259
+ const button = child.matches("button") ? child : child.querySelector("button");
2260
+ if (button !== null) {
2261
+ const label = button.textContent?.trim().toLowerCase();
2262
+ remember(child);
2263
+ child.dataset.a2uiLoopCell = label === "save" ? "save" : "action";
2264
+ if (label === "save") {
2265
+ child.setAttribute("hidden", "");
2266
+ child.setAttribute("aria-hidden", "true");
2267
+ }
2268
+ continue;
2269
+ }
2270
+ const fieldParts = getSavedLoopFieldParts(child);
2271
+ if (fieldParts !== void 0) {
2272
+ remember(child);
2273
+ child.dataset.a2uiLoopField = "true";
2274
+ const column = String(columnIndex + 1);
2275
+ child.dataset.a2uiLoopColumn = column;
2276
+ remember(fieldParts.label);
2277
+ fieldParts.label.dataset.a2uiLoopCell = "label";
2278
+ fieldParts.label.dataset.a2uiLoopColumn = column;
2279
+ remember(fieldParts.value);
2280
+ fieldParts.value.dataset.a2uiLoopCell = "value";
2281
+ fieldParts.value.dataset.a2uiLoopColumn = column;
2282
+ columnIndex += 1;
2283
+ continue;
2284
+ }
2285
+ if (isSavedLoopSummary(child)) {
2286
+ remember(child);
2287
+ child.dataset.a2uiLoopCell = "summary";
2288
+ child.setAttribute("hidden", "");
2289
+ child.setAttribute("aria-hidden", "true");
2290
+ continue;
2291
+ }
2292
+ remember(child);
2293
+ child.dataset.a2uiLoopCell = columnIndex % 2 === 0 ? "label" : "value";
2294
+ child.dataset.a2uiLoopColumn = String(Math.floor(columnIndex / 2) + 1);
2295
+ columnIndex += 1;
2296
+ }
2297
+ normalizeSavedLoopRow(row, rowIndex, remember, setText, generatedElements);
2298
+ });
2299
+ }
2300
+ return () => {
2301
+ for (const [element, original] of originals) {
2302
+ restoreDataset(element, "a2uiLoopTable", original.loopTable);
2303
+ restoreDataset(element, "a2uiLoopRow", original.loopRow);
2304
+ restoreDataset(element, "a2uiLoopHeader", original.loopHeader);
2305
+ restoreDataset(element, "a2uiLoopField", original.loopField);
2306
+ restoreDataset(element, "a2uiLoopCell", original.loopCell);
2307
+ restoreDataset(element, "a2uiLoopColumn", original.loopColumn);
2308
+ restoreDataset(element, "a2uiLoopColumnCount", original.loopColumnCount);
2309
+ restoreDataset(element, "a2uiLoopLabel", original.loopLabel);
2310
+ restoreDataset(
2311
+ element,
2312
+ "a2uiLoopGeneratedHeader",
2313
+ original.generatedHeader
2314
+ );
2315
+ restoreAttribute(element, "hidden", original.hidden);
2316
+ restoreAttribute(element, "aria-hidden", original.ariaHidden);
2317
+ }
2318
+ for (const [element, text] of textOriginals) {
2319
+ element.textContent = text;
2320
+ }
2321
+ for (const element of generatedElements) {
2322
+ element.remove();
2323
+ }
2324
+ };
2325
+ }
2326
+ function buildSavedLoopHeader(parent, firstRow) {
2327
+ const fields = normalizedLoopSummaryFields(getSavedLoopSummaryFields(firstRow));
2328
+ if (fields.length < 2) {
2329
+ return void 0;
2330
+ }
2331
+ const header = parent.ownerDocument.createElement("div");
2332
+ header.dataset.a2uiLoopGeneratedHeader = "true";
2333
+ const columnCount = Math.min(fields.length, 3);
2334
+ header.dataset.a2uiLoopColumnCount = String(columnCount);
2335
+ fields.slice(0, columnCount).forEach((field, index) => {
2336
+ const cell = parent.ownerDocument.createElement("div");
2337
+ cell.dataset.a2uiLoopCell = "label";
2338
+ cell.dataset.a2uiLoopColumn = String(index + 1);
2339
+ cell.textContent = displayFieldLabel(field);
2340
+ header.appendChild(cell);
2341
+ });
2342
+ const action = parent.ownerDocument.createElement("div");
2343
+ action.dataset.a2uiLoopCell = "label";
2344
+ action.dataset.a2uiLoopColumn = String(columnCount + 1);
2345
+ action.textContent = "Action";
2346
+ header.appendChild(action);
2347
+ return header;
2348
+ }
2349
+ function normalizeSavedLoopRow(row, rowIndex, remember, setText, generatedElements) {
2350
+ const summaryFields = normalizedLoopSummaryFields(getSavedLoopSummaryFields(row));
2351
+ if (summaryFields.length < 2) {
2352
+ return;
2353
+ }
2354
+ const columnCount = Math.min(summaryFields.length, 3);
2355
+ row.dataset.a2uiLoopColumnCount = String(columnCount);
2356
+ const fields = [...row.querySelectorAll("[data-a2ui-loop-field='true']")];
2357
+ const summaryValues = getSavedLoopSummaryValues(row);
2358
+ const action = row.querySelector("[data-a2ui-loop-cell='action']");
2359
+ const orderedFields = summaryFields.slice(0, columnCount).map((fieldName) => {
2360
+ const field = findSavedLoopField(fields, fieldName);
2361
+ if (field !== void 0) {
2362
+ return field;
2363
+ }
2364
+ const value = summaryValues.get(fieldName);
2365
+ if (value === void 0) {
2366
+ return void 0;
2367
+ }
2368
+ const generated = createSavedLoopField(row.ownerDocument, fieldName, value);
2369
+ if (action !== null) {
2370
+ row.insertBefore(generated, action);
2371
+ } else {
2372
+ row.appendChild(generated);
2373
+ }
2374
+ generatedElements.push(generated);
2375
+ return generated;
2376
+ }).filter((field) => field !== void 0);
2377
+ orderedFields.forEach((field, index) => {
2378
+ const column = String(index + 1);
2379
+ remember(field);
2380
+ field.dataset.a2uiLoopColumn = column;
2381
+ const label = field.querySelector("[data-a2ui-loop-cell='label']");
2382
+ const value = field.querySelector("[data-a2ui-loop-cell='value']");
2383
+ if (label !== null) {
2384
+ remember(label);
2385
+ label.dataset.a2uiLoopColumn = column;
2386
+ label.dataset.a2uiLoopCell = "label";
2387
+ const displayLabel = displayFieldLabel(summaryFields[index] ?? "");
2388
+ label.dataset.a2uiLoopLabel = displayLabel;
2389
+ setText(label, displayLabel);
2390
+ }
2391
+ if (value !== null) {
2392
+ remember(value);
2393
+ value.dataset.a2uiLoopColumn = column;
2394
+ value.dataset.a2uiLoopCell = "value";
2395
+ }
2396
+ });
2397
+ if (action !== null) {
2398
+ remember(action);
2399
+ action.dataset.a2uiLoopColumn = String(columnCount + 1);
2400
+ }
2401
+ for (const field of fields) {
2402
+ if (orderedFields.includes(field)) {
2403
+ continue;
2404
+ }
2405
+ remember(field);
2406
+ field.dataset.a2uiLoopCell = "save";
2407
+ field.setAttribute("hidden", "");
2408
+ field.setAttribute("aria-hidden", "true");
2409
+ }
2410
+ }
2411
+ function findSavedLoopField(fields, summaryField) {
2412
+ const expectedName = canonicalLoopFieldName(summaryField).toLowerCase();
2413
+ const expectedLabel = displayFieldLabel(expectedName).toLowerCase();
2414
+ return fields.find((field) => {
2415
+ const parts = getSavedLoopFieldParts(field);
2416
+ if (parts?.fieldName === void 0) {
2417
+ return false;
2418
+ }
2419
+ const name = canonicalLoopFieldName(parts.fieldName).toLowerCase();
2420
+ return name === expectedName || name === expectedLabel;
2421
+ });
2422
+ }
2423
+ function createSavedLoopField(document, fieldName, value) {
2424
+ const field = document.createElement("div");
2425
+ field.dataset.a2uiLoopField = "true";
2426
+ const label = document.createElement("span");
2427
+ label.dataset.a2uiLoopCell = "label";
2428
+ label.textContent = displayFieldLabel(fieldName);
2429
+ const valueCell = document.createElement("div");
2430
+ valueCell.dataset.a2uiLoopCell = "value";
2431
+ valueCell.textContent = value;
2432
+ field.append(label, valueCell);
2433
+ return field;
2434
+ }
2435
+ function normalizedLoopSummaryFields(fields) {
2436
+ const withoutInternal = uniqueStrings(
2437
+ fields.map(canonicalLoopFieldName).filter(
2438
+ (field) => !["itemid", "__displaytext", "role", "save", "delete", "action"].includes(
2439
+ field.toLowerCase()
2440
+ )
2441
+ )
2442
+ );
2443
+ const providerFields = [
2444
+ "doctor_name",
2445
+ "doctor_location",
2446
+ "specialization_type"
2447
+ ];
2448
+ const hasProviderFields = providerFields.some(
2449
+ (field) => withoutInternal.includes(field)
2450
+ );
2451
+ if (hasProviderFields) {
2452
+ return providerFields.filter((field) => withoutInternal.includes(field));
2453
+ }
2454
+ const prescriptionFields = [
2455
+ "prescription_name",
2456
+ "prescription_dosage",
2457
+ "prescription_frequency",
2458
+ "prescriptions"
2459
+ ];
2460
+ const hasPrescriptionFields = prescriptionFields.some(
2461
+ (field) => withoutInternal.includes(field)
2462
+ );
2463
+ if (hasPrescriptionFields) {
2464
+ return prescriptionFields.filter((field) => withoutInternal.includes(field));
2465
+ }
2466
+ const pharmacyFields = ["pharmacy_name", "pharmacy_type", "pharmacy_address"];
2467
+ const hasPharmacyFields = pharmacyFields.some(
2468
+ (field) => withoutInternal.includes(field)
2469
+ );
2470
+ if (hasPharmacyFields) {
2471
+ return pharmacyFields.filter((field) => withoutInternal.includes(field));
2472
+ }
2473
+ const hospitalFields = ["hospital_name", "hospital_city_state"];
2474
+ const hasHospitalFields = hospitalFields.some(
2475
+ (field) => withoutInternal.includes(field)
2476
+ );
2477
+ if (hasHospitalFields) {
2478
+ return hospitalFields.filter((field) => withoutInternal.includes(field));
2479
+ }
2480
+ return withoutInternal;
2481
+ }
2482
+ function uniqueStrings(values) {
2483
+ const seen = /* @__PURE__ */ new Set();
2484
+ const output = [];
2485
+ for (const value of values) {
2486
+ const key = value.toLowerCase();
2487
+ if (seen.has(key)) {
2488
+ continue;
2489
+ }
2490
+ seen.add(key);
2491
+ output.push(value);
2492
+ }
2493
+ return output;
2494
+ }
2495
+ function getSavedLoopSummaryFields(row) {
2496
+ const summary = [...row.children].find(
2497
+ (child) => child instanceof HTMLElement && isSavedLoopSummary(child)
2498
+ );
2499
+ if (summary === void 0) {
2500
+ return [];
2501
+ }
2502
+ return (summary.textContent ?? "").split(/\s+\|\s+/).map((part) => part.trim().match(/^\*?([^:*]+?)\*?\s*:/)?.[1]).filter((field) => field !== void 0);
2503
+ }
2504
+ function getSavedLoopSummaryValues(row) {
2505
+ const summary = [...row.children].find(
2506
+ (child) => child instanceof HTMLElement && isSavedLoopSummary(child)
2507
+ );
2508
+ const values = /* @__PURE__ */ new Map();
2509
+ const text = summary?.textContent ?? "";
2510
+ for (const part of text.split(/\s+\|\s+/)) {
2511
+ const match = /^([^:]+):\s*(.*)$/.exec(part.trim());
2512
+ if (match === null) {
2513
+ continue;
2514
+ }
2515
+ const [, label, value] = match;
2516
+ const fieldName = canonicalLoopFieldName(label ?? "");
2517
+ if (fieldName && value !== void 0) {
2518
+ values.set(fieldName, value.trim());
2519
+ }
2520
+ }
2521
+ return values;
2522
+ }
2523
+ function getSavedLoopRowFields(row) {
2524
+ if (row.dataset.a2uiActionGroup === "true" || row.querySelector("input, textarea, select") !== null || row.querySelector("button") === null) {
2525
+ return [];
2526
+ }
2527
+ return [...row.children].filter(
2528
+ (child) => child instanceof HTMLElement && !child.matches("button") && child.querySelector("button") === null && getSavedLoopFieldParts(child) !== void 0
2529
+ );
2530
+ }
2531
+ function getSavedLoopFieldParts(element) {
2532
+ if (!(element instanceof HTMLElement)) {
2533
+ return void 0;
2534
+ }
2535
+ const children = [...element.children].filter(
2536
+ (child) => child instanceof HTMLElement && !child.matches("button") && child.querySelector("button") === null
2537
+ );
2538
+ if (children.length < 2) {
2539
+ return void 0;
2540
+ }
2541
+ const [label, value] = children;
2542
+ if (label === void 0 || value === void 0) {
2543
+ return void 0;
2544
+ }
2545
+ const labelText = label.textContent ?? "";
2546
+ const fieldName = savedLoopFieldLabelName(labelText);
2547
+ return fieldName !== void 0 || isLoopActionText(labelText) ? { fieldName, label, value } : void 0;
2548
+ }
2549
+ function savedLoopFieldLabelName(text) {
2550
+ const trimmed = text.trim();
2551
+ if (isLoopActionText(trimmed)) {
2552
+ return void 0;
2553
+ }
2554
+ const generated = generatedFieldLabelName(trimmed);
2555
+ if (generated !== void 0) {
2556
+ return generated;
2557
+ }
2558
+ return LOOP_FIELD_LABELS.get(trimmed.replace(/\s+/g, " ").toLowerCase());
2559
+ }
2560
+ function canonicalLoopFieldName(text) {
2561
+ const generated = generatedFieldLabelName(text);
2562
+ if (generated !== void 0) {
2563
+ return generated;
2564
+ }
2565
+ const normalized = text.trim().replace(/\s+/g, " ").toLowerCase();
2566
+ const mapped = LOOP_FIELD_LABELS.get(normalized);
2567
+ if (mapped !== void 0) {
2568
+ return mapped;
2569
+ }
2570
+ return text;
2571
+ }
2572
+ function isLoopActionText(text) {
2573
+ const normalized = text?.trim().toLowerCase();
2574
+ return normalized === "save" || normalized === "delete";
2575
+ }
2576
+ var LOOP_FIELD_LABELS = /* @__PURE__ */ new Map([
2577
+ ["role", "role"],
2578
+ ["doctor name", "doctor_name"],
2579
+ ["doctor location", "doctor_location"],
2580
+ ["specialization type", "specialization_type"],
2581
+ ["location", "location"],
2582
+ ["prescription name", "prescription_name"],
2583
+ ["prescription dosage", "prescription_dosage"],
2584
+ ["prescription frequency", "prescription_frequency"],
2585
+ ["pharmacy name", "pharmacy_name"],
2586
+ ["pharmacy type", "pharmacy_type"],
2587
+ ["pharmacy address", "pharmacy_address"],
2588
+ ["hospital name", "hospital_name"],
2589
+ ["hospital city state", "hospital_city_state"]
2590
+ ]);
2591
+ function isSavedLoopSummary(element) {
2592
+ if (element.children.length > 0) {
2593
+ return false;
2594
+ }
2595
+ return /\b[A-Za-z][A-Za-z0-9_]*:\s*/.test(element.textContent ?? "");
2596
+ }
2184
2597
  function labelElementForControl(root, control) {
2185
2598
  if (control.id.length > 0) {
2186
2599
  const label2 = root.querySelector(
@@ -2900,10 +3313,6 @@ function canonicalListFieldKey(listPath, key) {
2900
3313
  case "primary_care_location":
2901
3314
  case "provider_location":
2902
3315
  case "providerlocation":
2903
- case "doctor_location":
2904
- case "doctorlocation":
2905
- case "doctor_address":
2906
- case "doctoraddress":
2907
3316
  case "location_details":
2908
3317
  case "locationdetails":
2909
3318
  case "provider_address":