@alfadocs/ui-kit-debug 1.77.1 → 1.79.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 (205) hide show
  1. package/dist/_chunks/{address-fields-BUPRs3n-.js → address-fields-GnoSkvh6.js} +2 -2
  2. package/dist/_chunks/{address-fields-BUPRs3n-.js.map → address-fields-GnoSkvh6.js.map} +1 -1
  3. package/dist/_chunks/{anamnesis-summary-rows-vNDyE5HW.js → anamnesis-summary-rows-lONg-zja.js} +2 -2
  4. package/dist/_chunks/{anamnesis-summary-rows-vNDyE5HW.js.map → anamnesis-summary-rows-lONg-zja.js.map} +1 -1
  5. package/dist/_chunks/{bishop-score-CdbU9Nl4.js → bishop-score-C5di6oAV.js} +2 -2
  6. package/dist/_chunks/{bishop-score-CdbU9Nl4.js.map → bishop-score-C5di6oAV.js.map} +1 -1
  7. package/dist/_chunks/{bmi-calculator-DnfiDh4Q.js → bmi-calculator-BIExHBZV.js} +2 -2
  8. package/dist/_chunks/{bmi-calculator-DnfiDh4Q.js.map → bmi-calculator-BIExHBZV.js.map} +1 -1
  9. package/dist/_chunks/{booking-Cz_QjIJe.js → booking-BV2s2J3C.js} +3 -3
  10. package/dist/_chunks/{booking-Cz_QjIJe.js.map → booking-BV2s2J3C.js.map} +1 -1
  11. package/dist/_chunks/{calendar-appointment-editor-dialog-cvUpUjj-.js → calendar-appointment-editor-dialog-DhTTWgXw.js} +3 -3
  12. package/dist/_chunks/{calendar-appointment-editor-dialog-cvUpUjj-.js.map → calendar-appointment-editor-dialog-DhTTWgXw.js.map} +1 -1
  13. package/dist/_chunks/{cycle-calculator-HO3s5InI.js → cycle-calculator-CQkjVSD2.js} +2 -2
  14. package/dist/_chunks/{cycle-calculator-HO3s5InI.js.map → cycle-calculator-CQkjVSD2.js.map} +1 -1
  15. package/dist/_chunks/{due-date-calculator-CDWTSblh.js → due-date-calculator-NjTlmoFK.js} +2 -2
  16. package/dist/_chunks/{due-date-calculator-CDWTSblh.js.map → due-date-calculator-NjTlmoFK.js.map} +1 -1
  17. package/dist/_chunks/{fetal-weight-CrtBFJl-.js → fetal-weight-Brl3n4LN.js} +2 -2
  18. package/dist/_chunks/{fetal-weight-CrtBFJl-.js.map → fetal-weight-Brl3n4LN.js.map} +1 -1
  19. package/dist/_chunks/{forgot-password-form-BSOZVrZG.js → forgot-password-form-BQPvDS7i.js} +2 -2
  20. package/dist/_chunks/{forgot-password-form-BSOZVrZG.js.map → forgot-password-form-BQPvDS7i.js.map} +1 -1
  21. package/dist/_chunks/form-field-CyHfOVKF.js +185 -0
  22. package/dist/_chunks/form-field-CyHfOVKF.js.map +1 -0
  23. package/dist/_chunks/{gestational-age-calculator-CTHeJJdb.js → gestational-age-calculator-Dr9hdDta.js} +2 -2
  24. package/dist/_chunks/{gestational-age-calculator-CTHeJJdb.js.map → gestational-age-calculator-Dr9hdDta.js.map} +1 -1
  25. package/dist/_chunks/{hcg-doubling-BBk-a33g.js → hcg-doubling-K41Wy7LB.js} +2 -2
  26. package/dist/_chunks/{hcg-doubling-BBk-a33g.js.map → hcg-doubling-K41Wy7LB.js.map} +1 -1
  27. package/dist/_chunks/{help-me-write-templates-Ds1FY-WY.js → help-me-write-templates-BJSf24xS.js} +2 -2
  28. package/dist/_chunks/{help-me-write-templates-Ds1FY-WY.js.map → help-me-write-templates-BJSf24xS.js.map} +1 -1
  29. package/dist/_chunks/key-round-DIgsnJSg.js +21 -0
  30. package/dist/_chunks/key-round-DIgsnJSg.js.map +1 -0
  31. package/dist/_chunks/{kit-extensions-sNTZWkoo.js → kit-extensions-a0G4COFH.js} +6 -6
  32. package/dist/_chunks/{kit-extensions-sNTZWkoo.js.map → kit-extensions-a0G4COFH.js.map} +1 -1
  33. package/dist/_chunks/login-dev-card-CvLHj-_N.js +353 -0
  34. package/dist/_chunks/login-dev-card-CvLHj-_N.js.map +1 -0
  35. package/dist/_chunks/{patient-search-DuBdxv1w.js → patient-search-CxqNcth4.js} +454 -438
  36. package/dist/_chunks/patient-search-CxqNcth4.js.map +1 -0
  37. package/dist/_chunks/{pregnancy-dating-JBAUbM40.js → pregnancy-dating-BHvfDxz4.js} +2 -2
  38. package/dist/_chunks/{pregnancy-dating-JBAUbM40.js.map → pregnancy-dating-BHvfDxz4.js.map} +1 -1
  39. package/dist/_chunks/{pregnancy-weight-gain--Bqv6AWu.js → pregnancy-weight-gain-BeQRxwdP.js} +2 -2
  40. package/dist/_chunks/{pregnancy-weight-gain--Bqv6AWu.js.map → pregnancy-weight-gain-BeQRxwdP.js.map} +1 -1
  41. package/dist/_chunks/{radiograph-panel.agent-DQh2SX8G.js → radiograph-panel.agent-BQ95uFCd.js} +2 -2
  42. package/dist/_chunks/{radiograph-panel.agent-DQh2SX8G.js.map → radiograph-panel.agent-BQ95uFCd.js.map} +1 -1
  43. package/dist/_chunks/registration-form-CNBfUduG.js +1337 -0
  44. package/dist/_chunks/registration-form-CNBfUduG.js.map +1 -0
  45. package/dist/_chunks/reset-password-form-Cf9QPEJu.js +367 -0
  46. package/dist/_chunks/reset-password-form-Cf9QPEJu.js.map +1 -0
  47. package/dist/_chunks/{send-registration-link-form-__DWY62q.js → send-registration-link-form-vTn1HxjA.js} +2 -2
  48. package/dist/_chunks/{send-registration-link-form-__DWY62q.js.map → send-registration-link-form-vTn1HxjA.js.map} +1 -1
  49. package/dist/_chunks/{task-editor-CRhfwP9T.js → task-editor-Cpw-NmND.js} +2 -2
  50. package/dist/_chunks/{task-editor-CRhfwP9T.js.map → task-editor-Cpw-NmND.js.map} +1 -1
  51. package/dist/_chunks/{unit-converter-D59L-gkf.js → unit-converter-BH5ueIhT.js} +2 -2
  52. package/dist/_chunks/{unit-converter-D59L-gkf.js.map → unit-converter-BH5ueIhT.js.map} +1 -1
  53. package/dist/_chunks/{voice-control-panel-DQJwe6_Q.js → voice-control-panel-BziKE-KK.js} +2 -2
  54. package/dist/_chunks/{voice-control-panel-DQJwe6_Q.js.map → voice-control-panel-BziKE-KK.js.map} +1 -1
  55. package/dist/_chunks/{workflow-webhook-action-BvVPZVpG.js → workflow-webhook-action-DulCpCRz.js} +96 -111
  56. package/dist/_chunks/workflow-webhook-action-DulCpCRz.js.map +1 -0
  57. package/dist/agent-catalog.json +89 -3
  58. package/dist/agent-i18n/en.json +11 -2
  59. package/dist/components/address-fields/index.js +1 -1
  60. package/dist/components/bishop-score/index.js +1 -1
  61. package/dist/components/bmi-calculator/index.js +1 -1
  62. package/dist/components/booking/index.js +1 -1
  63. package/dist/components/cycle-calculator/index.js +1 -1
  64. package/dist/components/due-date-calculator/index.js +1 -1
  65. package/dist/components/fetal-weight/index.js +1 -1
  66. package/dist/components/form-field/form-field.d.ts +6 -0
  67. package/dist/components/form-field/form-field.d.ts.map +1 -1
  68. package/dist/components/form-field/index.js +1 -1
  69. package/dist/components/gestational-age-calculator/index.js +1 -1
  70. package/dist/components/hcg-doubling/index.js +1 -1
  71. package/dist/components/index.d.ts +1 -0
  72. package/dist/components/index.d.ts.map +1 -1
  73. package/dist/components/patient-search/index.js +1 -1
  74. package/dist/components/patient-search/patient-search.d.ts +9 -2
  75. package/dist/components/patient-search/patient-search.d.ts.map +1 -1
  76. package/dist/components/pregnancy-dating/index.js +1 -1
  77. package/dist/components/pregnancy-weight-gain/index.js +1 -1
  78. package/dist/components/radiograph-panel/index.js +1 -1
  79. package/dist/components/rich-text-editor/index.js +1 -1
  80. package/dist/components/task-editor/index.js +1 -1
  81. package/dist/components/unit-converter/index.js +1 -1
  82. package/dist/components/voice-control-panel/index.js +1 -1
  83. package/dist/i18n/locales/ar.d.ts +26 -0
  84. package/dist/i18n/locales/ar.d.ts.map +1 -1
  85. package/dist/i18n/locales/ar.js +27 -1
  86. package/dist/i18n/locales/ar.js.map +1 -1
  87. package/dist/i18n/locales/de.d.ts +26 -0
  88. package/dist/i18n/locales/de.d.ts.map +1 -1
  89. package/dist/i18n/locales/de.js +27 -1
  90. package/dist/i18n/locales/de.js.map +1 -1
  91. package/dist/i18n/locales/el.d.ts +26 -0
  92. package/dist/i18n/locales/el.d.ts.map +1 -1
  93. package/dist/i18n/locales/el.js +27 -1
  94. package/dist/i18n/locales/el.js.map +1 -1
  95. package/dist/i18n/locales/en.d.ts +26 -0
  96. package/dist/i18n/locales/en.d.ts.map +1 -1
  97. package/dist/i18n/locales/en.js +26 -0
  98. package/dist/i18n/locales/en.js.map +1 -1
  99. package/dist/i18n/locales/es.d.ts +26 -0
  100. package/dist/i18n/locales/es.d.ts.map +1 -1
  101. package/dist/i18n/locales/es.js +27 -1
  102. package/dist/i18n/locales/es.js.map +1 -1
  103. package/dist/i18n/locales/fr.d.ts +26 -0
  104. package/dist/i18n/locales/fr.d.ts.map +1 -1
  105. package/dist/i18n/locales/fr.js +27 -1
  106. package/dist/i18n/locales/fr.js.map +1 -1
  107. package/dist/i18n/locales/hi.d.ts +26 -0
  108. package/dist/i18n/locales/hi.d.ts.map +1 -1
  109. package/dist/i18n/locales/hi.js +27 -1
  110. package/dist/i18n/locales/hi.js.map +1 -1
  111. package/dist/i18n/locales/it.d.ts +26 -0
  112. package/dist/i18n/locales/it.d.ts.map +1 -1
  113. package/dist/i18n/locales/it.js +27 -1
  114. package/dist/i18n/locales/it.js.map +1 -1
  115. package/dist/i18n/locales/ja.d.ts +26 -0
  116. package/dist/i18n/locales/ja.d.ts.map +1 -1
  117. package/dist/i18n/locales/ja.js +27 -1
  118. package/dist/i18n/locales/ja.js.map +1 -1
  119. package/dist/i18n/locales/nl.d.ts +26 -0
  120. package/dist/i18n/locales/nl.d.ts.map +1 -1
  121. package/dist/i18n/locales/nl.js +27 -1
  122. package/dist/i18n/locales/nl.js.map +1 -1
  123. package/dist/i18n/locales/pl.d.ts +26 -0
  124. package/dist/i18n/locales/pl.d.ts.map +1 -1
  125. package/dist/i18n/locales/pl.js +27 -1
  126. package/dist/i18n/locales/pl.js.map +1 -1
  127. package/dist/i18n/locales/pt.d.ts +26 -0
  128. package/dist/i18n/locales/pt.d.ts.map +1 -1
  129. package/dist/i18n/locales/pt.js +27 -1
  130. package/dist/i18n/locales/pt.js.map +1 -1
  131. package/dist/i18n/locales/ro.d.ts +26 -0
  132. package/dist/i18n/locales/ro.d.ts.map +1 -1
  133. package/dist/i18n/locales/ro.js +27 -1
  134. package/dist/i18n/locales/ro.js.map +1 -1
  135. package/dist/i18n/locales/ru.d.ts +26 -0
  136. package/dist/i18n/locales/ru.d.ts.map +1 -1
  137. package/dist/i18n/locales/ru.js +27 -1
  138. package/dist/i18n/locales/ru.js.map +1 -1
  139. package/dist/i18n/locales/sq.d.ts +26 -0
  140. package/dist/i18n/locales/sq.d.ts.map +1 -1
  141. package/dist/i18n/locales/sq.js +27 -1
  142. package/dist/i18n/locales/sq.js.map +1 -1
  143. package/dist/i18n/locales/sv.d.ts +26 -0
  144. package/dist/i18n/locales/sv.d.ts.map +1 -1
  145. package/dist/i18n/locales/sv.js +27 -1
  146. package/dist/i18n/locales/sv.js.map +1 -1
  147. package/dist/i18n/locales/tr.d.ts +26 -0
  148. package/dist/i18n/locales/tr.d.ts.map +1 -1
  149. package/dist/i18n/locales/tr.js +27 -1
  150. package/dist/i18n/locales/tr.js.map +1 -1
  151. package/dist/i18n/locales/zh.d.ts +26 -0
  152. package/dist/i18n/locales/zh.d.ts.map +1 -1
  153. package/dist/i18n/locales/zh.js +27 -1
  154. package/dist/i18n/locales/zh.js.map +1 -1
  155. package/dist/index.js +90 -87
  156. package/dist/index.js.map +1 -1
  157. package/dist/locales/ar.json +27 -1
  158. package/dist/locales/de.json +27 -1
  159. package/dist/locales/el.json +27 -1
  160. package/dist/locales/en.json +26 -0
  161. package/dist/locales/es.json +27 -1
  162. package/dist/locales/fr.json +27 -1
  163. package/dist/locales/hi.json +27 -1
  164. package/dist/locales/it.json +27 -1
  165. package/dist/locales/ja.json +27 -1
  166. package/dist/locales/nl.json +27 -1
  167. package/dist/locales/pl.json +27 -1
  168. package/dist/locales/pt.json +27 -1
  169. package/dist/locales/ro.json +27 -1
  170. package/dist/locales/ru.json +27 -1
  171. package/dist/locales/sq.json +27 -1
  172. package/dist/locales/sv.json +27 -1
  173. package/dist/locales/tr.json +27 -1
  174. package/dist/locales/zh.json +27 -1
  175. package/dist/patterns/_shared/password-policy.d.ts +3 -0
  176. package/dist/patterns/_shared/password-policy.d.ts.map +1 -0
  177. package/dist/patterns/anamnesis/index.js +1 -1
  178. package/dist/patterns/calendar/index.js +1 -1
  179. package/dist/patterns/forgot-password-form/index.js +1 -1
  180. package/dist/patterns/help-me-write-templates/index.js +1 -1
  181. package/dist/patterns/login-form/index.js +1 -1
  182. package/dist/patterns/login-form/login-form.d.ts +24 -7
  183. package/dist/patterns/login-form/login-form.d.ts.map +1 -1
  184. package/dist/patterns/registration-form/index.d.ts +1 -1
  185. package/dist/patterns/registration-form/index.d.ts.map +1 -1
  186. package/dist/patterns/registration-form/index.js +1 -1
  187. package/dist/patterns/registration-form/registration-form.d.ts +27 -0
  188. package/dist/patterns/registration-form/registration-form.d.ts.map +1 -1
  189. package/dist/patterns/reset-password-form/index.d.ts +3 -0
  190. package/dist/patterns/reset-password-form/index.d.ts.map +1 -0
  191. package/dist/patterns/reset-password-form/index.js +6 -0
  192. package/dist/patterns/reset-password-form/index.js.map +1 -0
  193. package/dist/patterns/reset-password-form/reset-password-form.d.ts +108 -0
  194. package/dist/patterns/reset-password-form/reset-password-form.d.ts.map +1 -0
  195. package/dist/patterns/send-registration-link-form/index.js +1 -1
  196. package/dist/patterns/workflow-webhook-action/index.js +1 -1
  197. package/package.json +5 -1
  198. package/dist/_chunks/form-field-Ani72sVY.js +0 -176
  199. package/dist/_chunks/form-field-Ani72sVY.js.map +0 -1
  200. package/dist/_chunks/login-dev-card-DRxTPkE9.js +0 -332
  201. package/dist/_chunks/login-dev-card-DRxTPkE9.js.map +0 -1
  202. package/dist/_chunks/patient-search-DuBdxv1w.js.map +0 -1
  203. package/dist/_chunks/registration-form-xORq2s4p.js +0 -1310
  204. package/dist/_chunks/registration-form-xORq2s4p.js.map +0 -1
  205. package/dist/_chunks/workflow-webhook-action-BvVPZVpG.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"fetal-weight-CrtBFJl-.js","sources":["../../src/components/fetal-weight/fetal-weight.agent.ts","../../src/components/fetal-weight/efw.ts","../../src/components/fetal-weight/fetal-weight.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* Agent adapter — FetalWeight. */\n/* */\n/* Clinical calculator: ultrasound biometry (BPD / HC / AC / FL, mm) → */\n/* estimated fetal weight in grams via Hadlock. The agent surface is the */\n/* four biometry inputs plus the computed EFW; the handle is the curated */\n/* `FetalWeightHandle` (the public `ref` stays the root <div>, exactly as */\n/* `slider.tsx` and `bmi-calculator.tsx` keep theirs). */\n/* */\n/* PHI (§7): never exposes patient identity — the slots return the */\n/* operator's own structural measurements in millimetres and the weight */\n/* derived from them. See `src/docs/26-agent-readiness.mdx`. */\n/* -------------------------------------------------------------------- */\n\nimport type { AgentAdapter } from '../../agent/types';\nimport type { FetalWeightHandle } from './fetal-weight';\n\n/** JSON Schema fragment for one optional biometry measurement, millimetres. */\nconst measurement = (label: string) => ({\n oneOf: [{ type: 'number', exclusiveMinimum: 0 }, { type: 'null' }],\n description: `${label} in millimetres, or null to clear it.`,\n});\n\nexport const fetalWeightAgent: AgentAdapter<FetalWeightHandle> = {\n id: 'fetal-weight',\n // set_value → the `set_biometry` action + the `biometry` state slot.\n capabilities: ['set_value'],\n state: {\n biometry: {\n type: '{ bpdMm: number | null, hcMm: number | null, acMm: number | null, flMm: number | null }',\n descriptionKey: 'ui.agent.fetalWeight.state.biometry',\n description:\n 'The four ultrasound measurements as entered, in millimetres — biparietal diameter, head circumference, abdominal circumference and femur length. Null where unset. Read this to see why a result is still null.',\n read: (handle) => handle.getBiometry(),\n },\n result: {\n type: \"{ grams: number, method: 'hadlock4' | 'hadlock1' } | null\",\n descriptionKey: 'ui.agent.fetalWeight.state.result',\n description:\n 'Estimated fetal weight in grams and which Hadlock regression produced it — `hadlock4` when all four measurements are present, `hadlock1` from AC + FL alone. Null until AC and FL are both set.',\n read: (handle) => handle.getResult(),\n },\n },\n actions: {\n set_biometry: {\n // Drives the same local input state a user types into; nothing is\n // persisted to a record, and every value is reversible in the same UI.\n safety: 'write',\n argsType:\n '{ bpdMm?: number | null, hcMm?: number | null, acMm?: number | null, flMm?: number | null }',\n argsSchema: {\n type: 'object',\n properties: {\n bpdMm: measurement('Biparietal diameter'),\n hcMm: measurement('Head circumference'),\n acMm: measurement('Abdominal circumference'),\n flMm: measurement('Femur length'),\n },\n additionalProperties: false,\n },\n idempotent: true,\n returns: 'boolean',\n returnsSchema: {\n type: 'boolean',\n description: 'True when the measurements were applied.',\n },\n errors: [\n 'Returns false and writes nothing when any supplied measurement is not a positive number — the payload applies all-or-nothing.',\n ],\n examples: [\n {\n args: { bpdMm: 85, hcMm: 310, acMm: 300, flMm: 62 },\n note: 'Full biometry around 32 weeks → the Hadlock 4-parameter estimate.',\n },\n {\n args: { acMm: 300, flMm: 62 },\n note: 'AC + FL only — the minimum for an estimate, via Hadlock 1.',\n },\n ],\n descriptionKey: 'ui.agent.fetalWeight.actions.setBiometry',\n description:\n 'Set any subset of the ultrasound biometry in millimetres. Omitted measurements are left unchanged; an explicit null clears one. AC and FL are the minimum for an estimate.',\n invoke: (\n handle,\n args: {\n bpdMm?: number | null;\n hcMm?: number | null;\n acMm?: number | null;\n flMm?: number | null;\n },\n ) => handle.setBiometry(args),\n },\n },\n domHooks: {\n root: {\n attr: 'data-component',\n value: 'fetal-weight',\n description:\n 'Marks the FetalWeight calculator (estimated fetal weight from ultrasound biometry).',\n },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description:\n 'Sourced from the id prop. Also the registry key — without an `id` the instance does not register and the handle-driven action/state are unreachable.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* Estimated fetal weight (EFW) from ultrasound biometry — Hadlock. */\n/* */\n/* Pure, framework-free, unit-testable. Hadlock (1985) regressions on */\n/* log10(weight in grams) from biometry in CENTIMETRES (inputs are taken */\n/* in mm and converted). The 4-parameter formula (BPD+HC+AC+FL) is the */\n/* default; the AC+FL formula is the fallback for partial biometry. */\n/* */\n/* Hadlock FP, Harrist RB, Sharman RS, Deter RL, Park SK. \"Estimation of */\n/* fetal weight with the use of head, body, and femur measurements.\" */\n/* Am J Obstet Gynecol 1985;151:333-7. */\n/* ------------------------------------------------------------------ */\n\nexport interface FetalBiometryInput {\n /** Biparietal diameter, mm. */\n bpdMm?: number | null;\n /** Head circumference, mm. */\n hcMm?: number | null;\n /** Abdominal circumference, mm. */\n acMm?: number | null;\n /** Femur length, mm. */\n flMm?: number | null;\n}\n\n/** Which Hadlock regression produced the estimate. */\nexport type EfwMethod = 'hadlock4' | 'hadlock1';\n\nexport interface EfwResult {\n /** Estimated fetal weight, grams (rounded to the nearest gram). */\n grams: number;\n /** The Hadlock regression used, given the available measurements. */\n method: EfwMethod;\n}\n\n/** A measurement is usable when it is a positive, finite number. */\nfunction cm(mm: number | null | undefined): number | null {\n return typeof mm === 'number' && Number.isFinite(mm) && mm > 0\n ? mm / 10\n : null;\n}\n\n/**\n * Estimate fetal weight from biometry. Uses the Hadlock 4-parameter formula\n * when BPD, HC, AC and FL are all present, else the AC+FL formula. Returns\n * `null` when AC and FL (the minimum) aren't both available.\n */\nexport function estimateFetalWeight(\n input: FetalBiometryInput,\n): EfwResult | null {\n const bpd = cm(input.bpdMm);\n const hc = cm(input.hcMm);\n const ac = cm(input.acMm);\n const fl = cm(input.flMm);\n\n // AC + FL are the minimum for any Hadlock estimate.\n if (ac === null || fl === null) return null;\n\n let log10: number;\n let method: EfwMethod;\n\n if (bpd !== null && hc !== null) {\n // Hadlock 4 (BPD, HC, AC, FL).\n log10 =\n 1.3596 -\n 0.00386 * ac * fl +\n 0.0064 * hc +\n 0.00061 * bpd * ac +\n 0.0424 * ac +\n 0.174 * fl;\n method = 'hadlock4';\n } else {\n // Hadlock 1 (AC, FL).\n log10 = 1.304 + 0.05281 * ac + 0.1938 * fl - 0.004 * ac * fl;\n method = 'hadlock1';\n }\n\n return { grams: Math.round(10 ** log10), method };\n}\n","/* ------------------------------------------------------------------ */\n/* FetalWeight — estimated fetal weight from ultrasound biometry. */\n/* */\n/* Inputs BPD / HC / AC / FL (mm); outputs EFW in grams via Hadlock */\n/* (maths in `./fetal-weight`, pure + tested). */\n/* ------------------------------------------------------------------ */\n\nimport { forwardRef, useEffect, useMemo, useRef, useState } from 'react';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { useAgentRegistration } from '../../agent/registry';\nimport { fetalWeightAgent } from './fetal-weight.agent';\nimport { FormField } from '../form-field';\nimport { NumberInput } from '../number-input';\nimport { Card } from '../card';\nimport { Badge } from '../badge';\nimport {\n InsertButton,\n type InsertPayload,\n type InsertVariant,\n type InsertMode,\n} from '../_shared/insert-result';\nimport { type EfwResult, estimateFetalWeight } from './efw';\n\nconst rootVariants = cva('ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]', {\n variants: {\n width: { full: 'ds:w-full', auto: 'ds:inline-flex' },\n },\n defaultVariants: { width: 'full' },\n});\n\n/** A biometry figure is usable when it is a positive finite number, or cleared. */\nconst isMeasurement = (n: number | null | undefined): boolean =>\n n === null || n === undefined || (Number.isFinite(n) && n > 0);\n\n/** Canonical biometry snapshot — millimetres, or null where unset. */\nexport interface FetalBiometrySnapshot {\n bpdMm: number | null;\n hcMm: number | null;\n acMm: number | null;\n flMm: number | null;\n}\n\n/**\n * Curated imperative handle for agent / external automation. Reads the four\n * biometry measurements and the Hadlock estimate, and writes the measurements\n * the way a user would type them. Never exposes patient identity — only\n * structural millimetres and the derived weight. Consumed by\n * `fetal-weight.agent.ts`; the public `ref` stays the root DOM element.\n */\nexport interface FetalWeightHandle {\n /** Current biometry in millimetres, or null where unset. */\n getBiometry: () => FetalBiometrySnapshot;\n /** Estimated fetal weight + the regression used, or null below the minimum biometry. */\n getResult: () => EfwResult | null;\n /**\n * Set any subset of the biometry in millimetres. Omitted keys are left\n * unchanged; an explicit `null` clears that measurement. Applies all-or-\n * nothing — returns false and writes nothing if any value is not positive.\n */\n setBiometry: (next: Partial<FetalBiometrySnapshot>) => boolean;\n}\n\nexport interface FetalWeightProps extends VariantProps<typeof rootVariants> {\n /** Fires whenever an estimate can be computed (and `null` when it can't). */\n onResultChange?: (result: EfwResult | null) => void;\n /** When provided, shows the result-action buttons that emit / copy the result. */\n onInsert?: (payload: InsertPayload) => void;\n /** Which verb the result button performs. Defaults to `'insert'`. */\n insertVariant?: InsertVariant;\n /** `copy` variant only — fired after a successful clipboard write. */\n onCopy?: (mode: InsertMode) => void;\n /** `copy` variant only — fired if the clipboard write can't proceed. */\n onError?: (error: unknown) => void;\n /** Brand wordmark printed in the inserted/copied result-card footer. */\n insertBrand?: string | false;\n /** Opaque instance id, emitted as `data-component-id`. */\n id?: string;\n /** Extra class names on the wrapper. */\n className?: string;\n}\n\nexport const FetalWeight = forwardRef<HTMLDivElement, FetalWeightProps>(\n (\n {\n onResultChange,\n onInsert,\n insertVariant = 'insert',\n onCopy,\n onError,\n insertBrand,\n id,\n width,\n className,\n },\n ref,\n ) => {\n const { t, i18n } = useTranslation('ui');\n\n const [bpdMm, setBpdMm] = useState<number | null>(null);\n const [hcMm, setHcMm] = useState<number | null>(null);\n const [acMm, setAcMm] = useState<number | null>(null);\n const [flMm, setFlMm] = useState<number | null>(null);\n\n const result = useMemo(\n () => estimateFetalWeight({ bpdMm, hcMm, acMm, flMm }),\n [bpdMm, hcMm, acMm, flMm],\n );\n\n useEffect(() => {\n onResultChange?.(result);\n }, [result, onResultChange]);\n\n /* ── Agent handle ────────────────────────────────────────────────── */\n const liveRef = useRef({ bpdMm, hcMm, acMm, flMm, result });\n liveRef.current = { bpdMm, hcMm, acMm, flMm, result };\n\n const agentHandle = useMemo<FetalWeightHandle>(\n () => ({\n getBiometry: () => {\n const { bpdMm: bpd, hcMm: hc, acMm: ac, flMm: fl } = liveRef.current;\n return { bpdMm: bpd, hcMm: hc, acMm: ac, flMm: fl };\n },\n getResult: () => liveRef.current.result,\n setBiometry: (next) => {\n const entries = [\n ['bpdMm', setBpdMm],\n ['hcMm', setHcMm],\n ['acMm', setAcMm],\n ['flMm', setFlMm],\n ] as const;\n // Validate the whole payload before writing any of it, so a bad\n // value can't leave the form half-updated.\n for (const [key] of entries) {\n if (key in next && !isMeasurement(next[key])) return false;\n }\n for (const [key, set] of entries) {\n if (key in next) set(next[key] ?? null);\n }\n return true;\n },\n }),\n [],\n );\n useAgentRegistration(fetalWeightAgent, agentHandle, id);\n\n const grams = useMemo(\n () => new Intl.NumberFormat(i18n.language, { maximumFractionDigits: 0 }),\n [i18n.language],\n );\n\n const unit = t('fetalWeight.units.mm');\n const efwText = (r: EfwResult): string =>\n t('fetalWeight.efwValue', { grams: grams.format(r.grams) });\n\n const fields: {\n label: string;\n value: number | null;\n onChange: (v: number | null) => void;\n }[] = [\n { label: t('fetalWeight.bpd'), value: bpdMm, onChange: setBpdMm },\n { label: t('fetalWeight.hc'), value: hcMm, onChange: setHcMm },\n { label: t('fetalWeight.ac'), value: acMm, onChange: setAcMm },\n { label: t('fetalWeight.fl'), value: flMm, onChange: setFlMm },\n ];\n\n return (\n <div\n ref={ref}\n data-component=\"fetal-weight\"\n data-component-id={id}\n className={rootVariants({ width, className })}\n >\n <div className=\"ds:grid ds:grid-cols-1 ds:gap-[var(--spacing-md)] ds:sm:grid-cols-2\">\n {fields.map((f) => (\n <FormField key={f.label} label={`${f.label} (${unit})`}>\n <NumberInput\n mode=\"decimal\"\n min={0}\n step={0.1}\n value={f.value}\n onChange={f.onChange}\n />\n </FormField>\n ))}\n </div>\n\n <p className=\"ds:sr-only\" role=\"status\" aria-live=\"polite\">\n {result ? `${t('fetalWeight.efwLabel')}: ${efwText(result)}.` : ''}\n </p>\n\n {result ? (\n <Card variant=\"elevated\">\n <Card.Body className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\">\n <dl className=\"ds:grid ds:grid-cols-1 ds:gap-[var(--spacing-md)] ds:sm:grid-cols-2\">\n <div className=\"ds:flex ds:flex-col ds:items-start ds:gap-[var(--spacing-xs)]\">\n <dt className=\"type-label ds:text-muted-foreground\">\n {t('fetalWeight.efwLabel')}\n </dt>\n <dd className=\"type-metric ds:text-foreground\">\n {efwText(result)}\n </dd>\n </div>\n <div className=\"ds:flex ds:flex-col ds:items-end ds:gap-[var(--spacing-xs)] ds:text-end\">\n <dt className=\"type-label ds:text-muted-foreground\">\n {t('fetalWeight.methodLabel')}\n </dt>\n <dd>\n <Badge variant=\"info\">\n {t(`fetalWeight.method.${result.method}`)}\n </Badge>\n </dd>\n </div>\n </dl>\n <p className=\"type-body-sm ds:text-muted-foreground\">\n {t('fetalWeight.disclaimer')}\n </p>\n {insertVariant === 'copy' || onInsert ? (\n <InsertButton\n onInsert={onInsert}\n variant={insertVariant}\n onCopy={onCopy}\n onError={onError}\n card={{\n title: t('insert.title.fetalWeight'),\n icon: 'scale',\n highlight: efwText(result),\n highlightToken: '--info',\n brand: insertBrand,\n fields: [\n {\n icon: 'scale',\n label: t('fetalWeight.efwLabel'),\n value: efwText(result),\n },\n {\n icon: 'activity',\n label: t('fetalWeight.methodLabel'),\n value: t(`fetalWeight.method.${result.method}`),\n },\n ],\n }}\n />\n ) : null}\n </Card.Body>\n </Card>\n ) : (\n <p className=\"type-body ds:text-muted-foreground\">\n {t('fetalWeight.empty')}\n </p>\n )}\n </div>\n );\n },\n);\n\nFetalWeight.displayName = 'FetalWeight';\n"],"names":["measurement","label","fetalWeightAgent","handle","args","cm","mm","estimateFetalWeight","input","bpd","hc","ac","fl","log10","method","rootVariants","cva","isMeasurement","n","FetalWeight","forwardRef","onResultChange","onInsert","insertVariant","onCopy","onError","insertBrand","id","width","className","ref","i18n","useTranslation","bpdMm","setBpdMm","useState","hcMm","setHcMm","acMm","setAcMm","flMm","setFlMm","result","useMemo","useEffect","liveRef","useRef","agentHandle","next","entries","key","set","useAgentRegistration","grams","unit","efwText","r","fields","jsxs","js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CnB,MAAkB,UAAUD,IAC3B,gBAAAqC;AAAA,cAACM;AAAA,cAAA;AAAA,gBACC,UAAA3C;AAAA,gBACA,SAASC;AAAA,gBACT,QAAAC;AAAA,gBACA,SAAAC;AAAA,gBACA,MAAM;AAAA,kBACJ,OAAO,EAAE,0BAA0B;AAAA,kBACnC,MAAM;AAAA,kBACN,WAAW8B,EAAQb,CAAM;AAAA,kBACzB,gBAAgB;AAAA,kBAChB,OAAOhB;AAAA,kBACP,QAAQ;AAAA,oBACN;AAAA,sBACE,MAAM;AAAA,sBACN,OAAO,EAAE,sBAAsB;AAAA,sBAC/B,OAAO6B,EAAQb,CAAM;AAAA,oBAAA;AAAA,oBAEvB;AAAA,sBACE,MAAM;AAAA,sBACN,OAAO,EAAE,yBAAyB;AAAA,sBAClC,OAAO,EAAE,sBAAsBA,EAAO,MAAM,EAAE;AAAA,oBAAA;AAAA,kBAChD;AAAA,gBACF;AAAA,cACF;AAAA,YAAA,IAEA;AAAA,UAAA,EAAA,CACN,EAAA,CACF,IAEA,gBAAAiB,EAAC,KAAA,EAAE,WAAU,sCACV,UAAA,EAAE,mBAAmB,EAAA,CACxB;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEAxC,EAAY,cAAc;"}
1
+ {"version":3,"file":"fetal-weight-Brl3n4LN.js","sources":["../../src/components/fetal-weight/fetal-weight.agent.ts","../../src/components/fetal-weight/efw.ts","../../src/components/fetal-weight/fetal-weight.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* Agent adapter — FetalWeight. */\n/* */\n/* Clinical calculator: ultrasound biometry (BPD / HC / AC / FL, mm) → */\n/* estimated fetal weight in grams via Hadlock. The agent surface is the */\n/* four biometry inputs plus the computed EFW; the handle is the curated */\n/* `FetalWeightHandle` (the public `ref` stays the root <div>, exactly as */\n/* `slider.tsx` and `bmi-calculator.tsx` keep theirs). */\n/* */\n/* PHI (§7): never exposes patient identity — the slots return the */\n/* operator's own structural measurements in millimetres and the weight */\n/* derived from them. See `src/docs/26-agent-readiness.mdx`. */\n/* -------------------------------------------------------------------- */\n\nimport type { AgentAdapter } from '../../agent/types';\nimport type { FetalWeightHandle } from './fetal-weight';\n\n/** JSON Schema fragment for one optional biometry measurement, millimetres. */\nconst measurement = (label: string) => ({\n oneOf: [{ type: 'number', exclusiveMinimum: 0 }, { type: 'null' }],\n description: `${label} in millimetres, or null to clear it.`,\n});\n\nexport const fetalWeightAgent: AgentAdapter<FetalWeightHandle> = {\n id: 'fetal-weight',\n // set_value → the `set_biometry` action + the `biometry` state slot.\n capabilities: ['set_value'],\n state: {\n biometry: {\n type: '{ bpdMm: number | null, hcMm: number | null, acMm: number | null, flMm: number | null }',\n descriptionKey: 'ui.agent.fetalWeight.state.biometry',\n description:\n 'The four ultrasound measurements as entered, in millimetres — biparietal diameter, head circumference, abdominal circumference and femur length. Null where unset. Read this to see why a result is still null.',\n read: (handle) => handle.getBiometry(),\n },\n result: {\n type: \"{ grams: number, method: 'hadlock4' | 'hadlock1' } | null\",\n descriptionKey: 'ui.agent.fetalWeight.state.result',\n description:\n 'Estimated fetal weight in grams and which Hadlock regression produced it — `hadlock4` when all four measurements are present, `hadlock1` from AC + FL alone. Null until AC and FL are both set.',\n read: (handle) => handle.getResult(),\n },\n },\n actions: {\n set_biometry: {\n // Drives the same local input state a user types into; nothing is\n // persisted to a record, and every value is reversible in the same UI.\n safety: 'write',\n argsType:\n '{ bpdMm?: number | null, hcMm?: number | null, acMm?: number | null, flMm?: number | null }',\n argsSchema: {\n type: 'object',\n properties: {\n bpdMm: measurement('Biparietal diameter'),\n hcMm: measurement('Head circumference'),\n acMm: measurement('Abdominal circumference'),\n flMm: measurement('Femur length'),\n },\n additionalProperties: false,\n },\n idempotent: true,\n returns: 'boolean',\n returnsSchema: {\n type: 'boolean',\n description: 'True when the measurements were applied.',\n },\n errors: [\n 'Returns false and writes nothing when any supplied measurement is not a positive number — the payload applies all-or-nothing.',\n ],\n examples: [\n {\n args: { bpdMm: 85, hcMm: 310, acMm: 300, flMm: 62 },\n note: 'Full biometry around 32 weeks → the Hadlock 4-parameter estimate.',\n },\n {\n args: { acMm: 300, flMm: 62 },\n note: 'AC + FL only — the minimum for an estimate, via Hadlock 1.',\n },\n ],\n descriptionKey: 'ui.agent.fetalWeight.actions.setBiometry',\n description:\n 'Set any subset of the ultrasound biometry in millimetres. Omitted measurements are left unchanged; an explicit null clears one. AC and FL are the minimum for an estimate.',\n invoke: (\n handle,\n args: {\n bpdMm?: number | null;\n hcMm?: number | null;\n acMm?: number | null;\n flMm?: number | null;\n },\n ) => handle.setBiometry(args),\n },\n },\n domHooks: {\n root: {\n attr: 'data-component',\n value: 'fetal-weight',\n description:\n 'Marks the FetalWeight calculator (estimated fetal weight from ultrasound biometry).',\n },\n instanceId: {\n attr: 'data-component-id',\n sourceProp: 'id',\n description:\n 'Sourced from the id prop. Also the registry key — without an `id` the instance does not register and the handle-driven action/state are unreachable.',\n },\n },\n};\n","/* ------------------------------------------------------------------ */\n/* Estimated fetal weight (EFW) from ultrasound biometry — Hadlock. */\n/* */\n/* Pure, framework-free, unit-testable. Hadlock (1985) regressions on */\n/* log10(weight in grams) from biometry in CENTIMETRES (inputs are taken */\n/* in mm and converted). The 4-parameter formula (BPD+HC+AC+FL) is the */\n/* default; the AC+FL formula is the fallback for partial biometry. */\n/* */\n/* Hadlock FP, Harrist RB, Sharman RS, Deter RL, Park SK. \"Estimation of */\n/* fetal weight with the use of head, body, and femur measurements.\" */\n/* Am J Obstet Gynecol 1985;151:333-7. */\n/* ------------------------------------------------------------------ */\n\nexport interface FetalBiometryInput {\n /** Biparietal diameter, mm. */\n bpdMm?: number | null;\n /** Head circumference, mm. */\n hcMm?: number | null;\n /** Abdominal circumference, mm. */\n acMm?: number | null;\n /** Femur length, mm. */\n flMm?: number | null;\n}\n\n/** Which Hadlock regression produced the estimate. */\nexport type EfwMethod = 'hadlock4' | 'hadlock1';\n\nexport interface EfwResult {\n /** Estimated fetal weight, grams (rounded to the nearest gram). */\n grams: number;\n /** The Hadlock regression used, given the available measurements. */\n method: EfwMethod;\n}\n\n/** A measurement is usable when it is a positive, finite number. */\nfunction cm(mm: number | null | undefined): number | null {\n return typeof mm === 'number' && Number.isFinite(mm) && mm > 0\n ? mm / 10\n : null;\n}\n\n/**\n * Estimate fetal weight from biometry. Uses the Hadlock 4-parameter formula\n * when BPD, HC, AC and FL are all present, else the AC+FL formula. Returns\n * `null` when AC and FL (the minimum) aren't both available.\n */\nexport function estimateFetalWeight(\n input: FetalBiometryInput,\n): EfwResult | null {\n const bpd = cm(input.bpdMm);\n const hc = cm(input.hcMm);\n const ac = cm(input.acMm);\n const fl = cm(input.flMm);\n\n // AC + FL are the minimum for any Hadlock estimate.\n if (ac === null || fl === null) return null;\n\n let log10: number;\n let method: EfwMethod;\n\n if (bpd !== null && hc !== null) {\n // Hadlock 4 (BPD, HC, AC, FL).\n log10 =\n 1.3596 -\n 0.00386 * ac * fl +\n 0.0064 * hc +\n 0.00061 * bpd * ac +\n 0.0424 * ac +\n 0.174 * fl;\n method = 'hadlock4';\n } else {\n // Hadlock 1 (AC, FL).\n log10 = 1.304 + 0.05281 * ac + 0.1938 * fl - 0.004 * ac * fl;\n method = 'hadlock1';\n }\n\n return { grams: Math.round(10 ** log10), method };\n}\n","/* ------------------------------------------------------------------ */\n/* FetalWeight — estimated fetal weight from ultrasound biometry. */\n/* */\n/* Inputs BPD / HC / AC / FL (mm); outputs EFW in grams via Hadlock */\n/* (maths in `./fetal-weight`, pure + tested). */\n/* ------------------------------------------------------------------ */\n\nimport { forwardRef, useEffect, useMemo, useRef, useState } from 'react';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { useAgentRegistration } from '../../agent/registry';\nimport { fetalWeightAgent } from './fetal-weight.agent';\nimport { FormField } from '../form-field';\nimport { NumberInput } from '../number-input';\nimport { Card } from '../card';\nimport { Badge } from '../badge';\nimport {\n InsertButton,\n type InsertPayload,\n type InsertVariant,\n type InsertMode,\n} from '../_shared/insert-result';\nimport { type EfwResult, estimateFetalWeight } from './efw';\n\nconst rootVariants = cva('ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]', {\n variants: {\n width: { full: 'ds:w-full', auto: 'ds:inline-flex' },\n },\n defaultVariants: { width: 'full' },\n});\n\n/** A biometry figure is usable when it is a positive finite number, or cleared. */\nconst isMeasurement = (n: number | null | undefined): boolean =>\n n === null || n === undefined || (Number.isFinite(n) && n > 0);\n\n/** Canonical biometry snapshot — millimetres, or null where unset. */\nexport interface FetalBiometrySnapshot {\n bpdMm: number | null;\n hcMm: number | null;\n acMm: number | null;\n flMm: number | null;\n}\n\n/**\n * Curated imperative handle for agent / external automation. Reads the four\n * biometry measurements and the Hadlock estimate, and writes the measurements\n * the way a user would type them. Never exposes patient identity — only\n * structural millimetres and the derived weight. Consumed by\n * `fetal-weight.agent.ts`; the public `ref` stays the root DOM element.\n */\nexport interface FetalWeightHandle {\n /** Current biometry in millimetres, or null where unset. */\n getBiometry: () => FetalBiometrySnapshot;\n /** Estimated fetal weight + the regression used, or null below the minimum biometry. */\n getResult: () => EfwResult | null;\n /**\n * Set any subset of the biometry in millimetres. Omitted keys are left\n * unchanged; an explicit `null` clears that measurement. Applies all-or-\n * nothing — returns false and writes nothing if any value is not positive.\n */\n setBiometry: (next: Partial<FetalBiometrySnapshot>) => boolean;\n}\n\nexport interface FetalWeightProps extends VariantProps<typeof rootVariants> {\n /** Fires whenever an estimate can be computed (and `null` when it can't). */\n onResultChange?: (result: EfwResult | null) => void;\n /** When provided, shows the result-action buttons that emit / copy the result. */\n onInsert?: (payload: InsertPayload) => void;\n /** Which verb the result button performs. Defaults to `'insert'`. */\n insertVariant?: InsertVariant;\n /** `copy` variant only — fired after a successful clipboard write. */\n onCopy?: (mode: InsertMode) => void;\n /** `copy` variant only — fired if the clipboard write can't proceed. */\n onError?: (error: unknown) => void;\n /** Brand wordmark printed in the inserted/copied result-card footer. */\n insertBrand?: string | false;\n /** Opaque instance id, emitted as `data-component-id`. */\n id?: string;\n /** Extra class names on the wrapper. */\n className?: string;\n}\n\nexport const FetalWeight = forwardRef<HTMLDivElement, FetalWeightProps>(\n (\n {\n onResultChange,\n onInsert,\n insertVariant = 'insert',\n onCopy,\n onError,\n insertBrand,\n id,\n width,\n className,\n },\n ref,\n ) => {\n const { t, i18n } = useTranslation('ui');\n\n const [bpdMm, setBpdMm] = useState<number | null>(null);\n const [hcMm, setHcMm] = useState<number | null>(null);\n const [acMm, setAcMm] = useState<number | null>(null);\n const [flMm, setFlMm] = useState<number | null>(null);\n\n const result = useMemo(\n () => estimateFetalWeight({ bpdMm, hcMm, acMm, flMm }),\n [bpdMm, hcMm, acMm, flMm],\n );\n\n useEffect(() => {\n onResultChange?.(result);\n }, [result, onResultChange]);\n\n /* ── Agent handle ────────────────────────────────────────────────── */\n const liveRef = useRef({ bpdMm, hcMm, acMm, flMm, result });\n liveRef.current = { bpdMm, hcMm, acMm, flMm, result };\n\n const agentHandle = useMemo<FetalWeightHandle>(\n () => ({\n getBiometry: () => {\n const { bpdMm: bpd, hcMm: hc, acMm: ac, flMm: fl } = liveRef.current;\n return { bpdMm: bpd, hcMm: hc, acMm: ac, flMm: fl };\n },\n getResult: () => liveRef.current.result,\n setBiometry: (next) => {\n const entries = [\n ['bpdMm', setBpdMm],\n ['hcMm', setHcMm],\n ['acMm', setAcMm],\n ['flMm', setFlMm],\n ] as const;\n // Validate the whole payload before writing any of it, so a bad\n // value can't leave the form half-updated.\n for (const [key] of entries) {\n if (key in next && !isMeasurement(next[key])) return false;\n }\n for (const [key, set] of entries) {\n if (key in next) set(next[key] ?? null);\n }\n return true;\n },\n }),\n [],\n );\n useAgentRegistration(fetalWeightAgent, agentHandle, id);\n\n const grams = useMemo(\n () => new Intl.NumberFormat(i18n.language, { maximumFractionDigits: 0 }),\n [i18n.language],\n );\n\n const unit = t('fetalWeight.units.mm');\n const efwText = (r: EfwResult): string =>\n t('fetalWeight.efwValue', { grams: grams.format(r.grams) });\n\n const fields: {\n label: string;\n value: number | null;\n onChange: (v: number | null) => void;\n }[] = [\n { label: t('fetalWeight.bpd'), value: bpdMm, onChange: setBpdMm },\n { label: t('fetalWeight.hc'), value: hcMm, onChange: setHcMm },\n { label: t('fetalWeight.ac'), value: acMm, onChange: setAcMm },\n { label: t('fetalWeight.fl'), value: flMm, onChange: setFlMm },\n ];\n\n return (\n <div\n ref={ref}\n data-component=\"fetal-weight\"\n data-component-id={id}\n className={rootVariants({ width, className })}\n >\n <div className=\"ds:grid ds:grid-cols-1 ds:gap-[var(--spacing-md)] ds:sm:grid-cols-2\">\n {fields.map((f) => (\n <FormField key={f.label} label={`${f.label} (${unit})`}>\n <NumberInput\n mode=\"decimal\"\n min={0}\n step={0.1}\n value={f.value}\n onChange={f.onChange}\n />\n </FormField>\n ))}\n </div>\n\n <p className=\"ds:sr-only\" role=\"status\" aria-live=\"polite\">\n {result ? `${t('fetalWeight.efwLabel')}: ${efwText(result)}.` : ''}\n </p>\n\n {result ? (\n <Card variant=\"elevated\">\n <Card.Body className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\">\n <dl className=\"ds:grid ds:grid-cols-1 ds:gap-[var(--spacing-md)] ds:sm:grid-cols-2\">\n <div className=\"ds:flex ds:flex-col ds:items-start ds:gap-[var(--spacing-xs)]\">\n <dt className=\"type-label ds:text-muted-foreground\">\n {t('fetalWeight.efwLabel')}\n </dt>\n <dd className=\"type-metric ds:text-foreground\">\n {efwText(result)}\n </dd>\n </div>\n <div className=\"ds:flex ds:flex-col ds:items-end ds:gap-[var(--spacing-xs)] ds:text-end\">\n <dt className=\"type-label ds:text-muted-foreground\">\n {t('fetalWeight.methodLabel')}\n </dt>\n <dd>\n <Badge variant=\"info\">\n {t(`fetalWeight.method.${result.method}`)}\n </Badge>\n </dd>\n </div>\n </dl>\n <p className=\"type-body-sm ds:text-muted-foreground\">\n {t('fetalWeight.disclaimer')}\n </p>\n {insertVariant === 'copy' || onInsert ? (\n <InsertButton\n onInsert={onInsert}\n variant={insertVariant}\n onCopy={onCopy}\n onError={onError}\n card={{\n title: t('insert.title.fetalWeight'),\n icon: 'scale',\n highlight: efwText(result),\n highlightToken: '--info',\n brand: insertBrand,\n fields: [\n {\n icon: 'scale',\n label: t('fetalWeight.efwLabel'),\n value: efwText(result),\n },\n {\n icon: 'activity',\n label: t('fetalWeight.methodLabel'),\n value: t(`fetalWeight.method.${result.method}`),\n },\n ],\n }}\n />\n ) : null}\n </Card.Body>\n </Card>\n ) : (\n <p className=\"type-body ds:text-muted-foreground\">\n {t('fetalWeight.empty')}\n </p>\n )}\n </div>\n );\n },\n);\n\nFetalWeight.displayName = 'FetalWeight';\n"],"names":["measurement","label","fetalWeightAgent","handle","args","cm","mm","estimateFetalWeight","input","bpd","hc","ac","fl","log10","method","rootVariants","cva","isMeasurement","n","FetalWeight","forwardRef","onResultChange","onInsert","insertVariant","onCopy","onError","insertBrand","id","width","className","ref","i18n","useTranslation","bpdMm","setBpdMm","useState","hcMm","setHcMm","acMm","setAcMm","flMm","setFlMm","result","useMemo","useEffect","liveRef","useRef","agentHandle","next","entries","key","set","useAgentRegistration","grams","unit","efwText","r","fields","jsxs","jsx","f","FormField","NumberInput","Card","Badge","InsertButton"],"mappings":";;;;;;;;;;AAkBA,MAAMA,IAAc,CAACC,OAAmB;AAAA,EACtC,OAAO,CAAC,EAAE,MAAM,UAAU,kBAAkB,KAAK,EAAE,MAAM,QAAQ;AAAA,EACjE,aAAa,GAAGA,CAAK;AACvB,IAEaC,IAAoD;AAAA,EAC/D,IAAI;AAAA;AAAA,EAEJ,cAAc,CAAC,WAAW;AAAA,EAC1B,OAAO;AAAA,IACL,UAAU;AAAA,MACR,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,aACE;AAAA,MACF,MAAM,CAACC,MAAWA,EAAO,YAAA;AAAA,IAAY;AAAA,IAEvC,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,aACE;AAAA,M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,OAAO,EAAE,sBAAsBA,EAAO,MAAM,EAAE;AAAA,oBAAA;AAAA,kBAChD;AAAA,gBACF;AAAA,cACF;AAAA,YAAA,IAEA;AAAA,UAAA,EAAA,CACN,EAAA,CACF,IAEA,gBAAAiB,EAAC,KAAA,EAAE,WAAU,sCACV,UAAA,EAAE,mBAAmB,EAAA,CACxB;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEAxC,EAAY,cAAc;"}
@@ -7,7 +7,7 @@ import { A as P } from "./alert-9kEwDza3.js";
7
7
  import { B as ho } from "./button-DohK_Ak_.js";
8
8
  import { C as K } from "./card-BA4Ig_kn.js";
9
9
  import { E as bo } from "./error-summary-mGxIyDAY.js";
10
- import { F as wo } from "./form-field-Ani72sVY.js";
10
+ import { F as wo } from "./form-field-CyHfOVKF.js";
11
11
  import { i as xo } from "./safe-href-5dbsfbQn.js";
12
12
  import { u as Eo } from "./use-state-backed-input-DhRQo6gM.js";
13
13
  import { u as Io, a as Ao, A as Po, b as yo, E as So, c as Ro, d as To } from "./auth-form-parts-B3GWChvG.js";
@@ -231,4 +231,4 @@ export {
231
231
  Vo as F,
232
232
  _o as a
233
233
  };
234
- //# sourceMappingURL=forgot-password-form-BSOZVrZG.js.map
234
+ //# sourceMappingURL=forgot-password-form-BQPvDS7i.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"forgot-password-form-BSOZVrZG.js","sources":["../../src/patterns/forgot-password-form/forgot-password-form.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* ForgotPasswordForm — the card that asks for a password reset link. */\n/* */\n/* One email field and a button, then a confirmation. The confirmation */\n/* is vague on purpose: it never says whether an account exists for the */\n/* address, and never repeats the address. The host sends the email and */\n/* owns every server rule; the card checks what a browser can check, */\n/* then hands the email to `onSubmit` or posts a real form. */\n/* -------------------------------------------------------------------- */\n\nimport {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n} from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { cva } from 'class-variance-authority';\n// The validator EmailInput itself uses, so the two never disagree.\nimport isEmail from 'validator/lib/isEmail';\nimport { Alert } from '../../components/alert';\nimport { Button } from '../../components/button';\nimport { Card } from '../../components/card';\nimport { EmailInput } from '../../components/email-input';\nimport { ErrorSummary } from '../../components/error-summary';\nimport { FormField } from '../../components/form-field';\nimport { isSafeHref } from '../../components/_shared/safe-href';\nimport { useStateBackedInput } from '../../components/_shared/use-state-backed-input';\nimport {\n AuthCardHeading,\n AuthFormMessage,\n AuthFormStatus,\n AuthTextLink,\n ExtraFields,\n useExtraFields,\n useFormAction,\n} from '../_shared/auth-form-parts';\nimport type { BrandMarkMotion } from '../_shared/brand-mark';\nimport {\n useErrorSummary,\n useFormMessageAnnounce,\n} from '../_shared/use-error-summary';\nimport { useRegistrationSubmit } from '../registration-form/use-registration-submit';\n\n/* -------------------------------------------------------------------- */\n/* Types */\n/* -------------------------------------------------------------------- */\n\n/** The form's one field. */\nexport const FORGOT_PASSWORD_FORM_FIELDS = ['email'] as const;\n\nexport type ForgotPasswordFormField =\n (typeof FORGOT_PASSWORD_FORM_FIELDS)[number];\n\n/** What `onSubmit` receives once the email has passed its check. */\nexport interface ForgotPasswordFormValues {\n email: string;\n}\n\n/** The email to show when the form opens. */\nexport type ForgotPasswordFormInitialValues = Partial<ForgotPasswordFormValues>;\n\n/** Messages from the server, already translated: one for the email,\n * plus `form` for a message about the whole form, such as \"too many\n * requests, try again later\". */\nexport type ForgotPasswordFormErrors = Partial<\n Record<ForgotPasswordFormField | 'form', string>\n>;\n\n/** The host's own form field name, for a native form post. It is needed:\n * a field without a name is not posted. */\nexport type ForgotPasswordFormFieldNames = Record<\n ForgotPasswordFormField,\n string\n>;\n\nexport interface ForgotPasswordFormProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'title' | 'onSubmit'\n> {\n /** Replaces the heading \"Reset your password\". Pass it translated. */\n title?: string;\n /**\n * Replaces the line under the heading (\"Enter the email linked to your\n * account and we will send a reset link.\"). Pass it translated.\n */\n description?: string;\n /**\n * The heading's level. Default 1: this page usually has no other\n * heading. Pass 2 on a page that has its own `h1`.\n */\n headingLevel?: 1 | 2 | 3;\n /**\n * Shows the Alfadocs mark above the heading, with the heading and its\n * line centred under it. Default true.\n */\n showLogo?: boolean;\n /** How the mark arrives when the card opens. Default `assemble`. It\n * plays once and rests. */\n logoMotion?: BrandMarkMotion;\n /**\n * Host content between the heading and the field, such as a notice. It\n * sits outside the form, so nothing in it is posted.\n */\n children?: ReactNode;\n /** The email to show when the form opens. Read once. */\n initialValues?: ForgotPasswordFormInitialValues;\n /**\n * Messages from the server, already translated. The email's message\n * shows on the field until the user changes it; `form` shows above the\n * field. When messages arrive, focus moves to the error summary at the\n * top of the form when the email has a message, or to the message\n * above the field when only that says something.\n *\n * Do not use a message to say that no account has the address: that\n * tells a stranger who has an account. Show `sent` for every address.\n */\n errors?: ForgotPasswordFormErrors;\n /**\n * Shows the confirmation in place of the form: \"Check your inbox\". Set\n * it once the request has been accepted, whether or not an account\n * exists for the address. The confirmation says \"if an account exists\"\n * and never shows the address.\n */\n sent?: boolean;\n /**\n * Adds \"Back to sign in\" under the card's content. A path on the same\n * site, or an address written in full. Anything else shows no link.\n */\n loginHref?: string;\n /** Replaces the button's \"Send reset link\". Pass it translated. */\n submitLabel?: string;\n /**\n * True while the host sends the email: the button shows a spinner and\n * a second submit is ignored. Set it inside `onSubmit`, before anything\n * is awaited: until it is true, a second press sends a second request.\n */\n submitting?: boolean;\n /** For React hosts: called with the email once it has passed its\n * check. Not called when `fieldNames` is set. */\n onSubmit?: (values: ForgotPasswordFormValues) => void;\n /**\n * For a native form post: the host's own field name, e.g.\n * `{ email: 'email' }`. When set, the input carries that name and the\n * browser posts the form.\n */\n fieldNames?: ForgotPasswordFormFieldNames;\n /**\n * Where a native form post goes. Default: the current address. Only a\n * path, or an address on the page's own origin, is accepted: another\n * origin is never sent what the user typed, and the post then goes to\n * the current address. Does nothing without `fieldNames`.\n */\n action?: string;\n /**\n * Extra hidden inputs posted with a native form, by name: a CSRF\n * token. Not used with `onSubmit`. A name that is also the one in\n * `fieldNames` is left out: the form's own field wins.\n */\n hiddenFields?: Readonly<Record<string, string>>;\n}\n\n/* -------------------------------------------------------------------- */\n/* Styles */\n/* -------------------------------------------------------------------- */\n\n// 400px at most, in px: a host whose root font size is not 16px would\n// stretch or squeeze a width in rem.\nconst forgotPasswordFormVariants = cva(\n 'ds:mx-auto ds:w-full ds:max-w-[400px] ds:text-start ds:text-[var(--foreground)]',\n);\n\n// The confirmation takes focus when it appears, so it shows a ring.\nconst confirmationVariants = cva(\n 'ds:focus-visible:outline-solid ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-[var(--ring)] ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)] ds:forced-colors:focus-visible:outline-[CanvasText]',\n);\n\n/* -------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------- */\n\ntype FocusTarget = 'email' | 'form';\n\n/** The form's one field, as the error summary lists it. */\nconst FIELDS = ['email'] as const;\n\n/** The confirmation's heading, by the level of the card's own. */\nconst CONFIRMATION_HEADING = { 1: 'h2', 2: 'h3', 3: 'h4' } as const;\n\nconst hasMessage = (errors: ForgotPasswordFormErrors): boolean =>\n Object.values(errors).some(Boolean);\n\nconst focusTargetFor = (\n messages: ForgotPasswordFormErrors,\n): FocusTarget | undefined =>\n messages.email ? 'email' : messages.form ? 'form' : undefined;\n\n/* -------------------------------------------------------------------- */\n/* Component */\n/* -------------------------------------------------------------------- */\n\n/**\n * The card that asks for a password reset link. Mount it on the\n * forgot-password page, inside `SignedOutFrame` or the host's own chrome.\n */\nexport const ForgotPasswordForm = forwardRef<\n HTMLDivElement,\n ForgotPasswordFormProps\n>(\n (\n {\n title,\n description,\n headingLevel = 1,\n showLogo = true,\n logoMotion = 'assemble',\n children,\n initialValues,\n errors,\n sent = false,\n loginHref,\n submitLabel,\n submitting = false,\n onSubmit,\n fieldNames,\n action,\n hiddenFields,\n className,\n ...rest\n },\n ref,\n ) => {\n const { t } = useTranslation('ui');\n const titleId = useId();\n const sentTitleId = useId();\n const sentDescriptionId = useId();\n const emailFieldId = useId();\n const formMessageId = useId();\n const native = fieldNames !== undefined;\n\n /* ------------------------------ State ----------------------------- */\n\n const [email, setEmail] = useState(() => initialValues?.email ?? '');\n // True once the user has filled in the field and left it. An email\n // that arrives filled in counts: a bad one is then flagged at once,\n // with its message. An empty field is not flagged for being passed\n // through; its message waits for a submit.\n const [touched, setTouched] = useState(() => Boolean(initialValues?.email));\n const [submitted, setSubmitted] = useState(false);\n const [serverErrors, setServerErrors] = useState<ForgotPasswordFormErrors>(\n () => errors ?? {},\n );\n\n const emailInput = useRef<HTMLInputElement>(null);\n // The address stays out of the input's `value` attribute, where a\n // copied outerHTML or a session replay could read it.\n const emailField = useStateBackedInput(email, emailInput);\n /**\n * What the input holds now. Read from the input, not from state: a\n * browser can fill the field without telling React, and the form must\n * not refuse a field that is visibly filled.\n */\n const held = (): string => {\n const value = emailInput.current?.value ?? email;\n if (value !== email) setEmail(value);\n return value;\n };\n\n /* ---------------------------- Validation -------------------------- */\n\n const invalid = !isEmail(email);\n // The message shows once the user has left the field or tried to\n // submit.\n const ownError =\n (submitted || touched) && invalid\n ? email === ''\n ? t('forgotPasswordForm.emailRequired')\n : t('inputs.email.invalid')\n : undefined;\n const emailError = serverErrors.email ?? ownError;\n\n /* ------------------------------ Focus ----------------------------- */\n\n const formMessage = useRef<HTMLDivElement>(null);\n const confirmation = useRef<HTMLDivElement>(null);\n\n // The email's message after a refused submit, or after a server\n // answer, is listed at the top of the form, and focus goes there. A\n // page the server rendered after a failed post opens that way too: it\n // announces nothing itself.\n const [openedWithEmailMessage] = useState(() => Boolean(errors?.email));\n const summary = useErrorSummary(\n FIELDS,\n () => emailError,\n openedWithEmailMessage,\n );\n // The message about the whole form: quiet while the summary lists the\n // email, because the summary reads it then.\n const formMessageAnnounce = useFormMessageAnnounce(\n serverErrors.form,\n summary.listed.length > 0,\n );\n\n // Any other place focus goes: the message above the field, when only\n // it says something. A new object for each request, so asking twice\n // for the same place moves focus twice.\n const [focusRequest, setFocusRequest] = useState<{\n target: FocusTarget;\n } | null>(() => {\n const target = openedWithEmailMessage\n ? undefined\n : focusTargetFor(errors ?? {});\n return target ? { target } : null;\n });\n useEffect(() => {\n if (!focusRequest) return;\n (focusRequest.target === 'email'\n ? emailInput\n : formMessage\n ).current?.focus();\n }, [focusRequest]);\n\n // The form, and the button that had focus, are gone once the\n // confirmation shows. Move focus to it, so a keyboard or screen\n // reader user lands on what happened. Not on a page that opens\n // already sent: that one is read from the top like any other.\n const wasSent = useRef(sent);\n useEffect(() => {\n if (sent && !wasSent.current) confirmation.current?.focus();\n wasSent.current = sent;\n }, [sent]);\n\n /* ------------------------------ Submit ---------------------------- */\n\n const submit = useRegistrationSubmit<'email'>({\n errors,\n submitting,\n native,\n captcha: false,\n firstProblem: () => (isEmail(held()) ? undefined : 'email'),\n onRefused: () => {\n setSubmitted(true);\n summary.open(() => setFocusRequest({ target: 'email' }));\n },\n // Only a React host gets here: a native post is the browser's own.\n deliver: () => onSubmit?.({ email: held() }),\n onAnswer: (answer) => {\n const next: ForgotPasswordFormErrors = answer;\n setServerErrors(next);\n if (!hasMessage(next)) return;\n setSubmitted(false);\n // The summary when the email has a message, else the message above.\n summary.open(() => {\n const target = focusTargetFor(next);\n if (target) setFocusRequest({ target });\n });\n },\n });\n const { busy } = submit;\n\n /* ------------------------------ Render ---------------------------- */\n\n const formAction = useFormAction('ForgotPasswordForm', native, action);\n const loginLink =\n loginHref && isSafeHref(loginHref) ? loginHref : undefined;\n const extraFields = useExtraFields(\n 'ForgotPasswordForm',\n native,\n fieldNames,\n hiddenFields,\n );\n\n return (\n <div\n ref={ref}\n {...rest}\n data-component=\"forgot-password-form\"\n data-state={sent ? 'sent' : 'asking'}\n className={forgotPasswordFormVariants({ className })}\n >\n <Card variant=\"elevated\">\n <Card.Body className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]\">\n <AuthCardHeading\n id={titleId}\n title={title ?? t('forgotPasswordForm.title')}\n // The instruction belongs to the form: once it is sent there\n // is nothing left to enter.\n description={\n sent\n ? undefined\n : (description ?? t('forgotPasswordForm.description'))\n }\n level={headingLevel}\n showLogo={showLogo}\n logoMotion={logoMotion}\n />\n\n {children ? (\n <div\n data-slot=\"host-content\"\n className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\"\n >\n {children}\n </div>\n ) : null}\n\n {sent ? (\n // Named and described, so a screen reader that lands here\n // reads the whole confirmation, not only \"status\".\n <Alert\n ref={confirmation}\n variant=\"success\"\n tabIndex={-1}\n aria-labelledby={sentTitleId}\n aria-describedby={sentDescriptionId}\n data-slot=\"confirmation\"\n className={confirmationVariants()}\n >\n {/* One level under the card's own heading. */}\n <Alert.Title\n id={sentTitleId}\n as={CONFIRMATION_HEADING[headingLevel]}\n >\n {t('forgotPasswordForm.sentTitle')}\n </Alert.Title>\n <Alert.Description id={sentDescriptionId}>\n {t('forgotPasswordForm.sentDescription')}\n </Alert.Description>\n </Alert>\n ) : (\n <>\n <form\n noValidate\n method=\"post\"\n action={formAction}\n aria-labelledby={titleId}\n aria-busy={busy || undefined}\n onSubmit={submit.handleSubmit}\n className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\"\n >\n <ErrorSummary\n ref={summary.ref}\n headingLevel={(headingLevel + 1) as 2 | 3 | 4}\n // The message about the whole form is read with it.\n aria-describedby={\n serverErrors.form ? formMessageId : undefined\n }\n errors={summary.listed.map((field) => ({\n field,\n message: emailError ?? '',\n targetId: emailFieldId,\n }))}\n />\n\n {serverErrors.form && (\n <AuthFormMessage\n ref={formMessage}\n id={formMessageId}\n announce={formMessageAnnounce}\n >\n {serverErrors.form}\n </AuthFormMessage>\n )}\n\n <FormField\n id={emailFieldId}\n label={t('forgotPasswordForm.email')}\n required\n error={emailError}\n // Quiet while the summary lists it: the summary reads it.\n announceError={!summary.lists('email')}\n data-field=\"email\"\n >\n {/* One check, above, drives the message, the red mark and\n aria-invalid through FormField. EmailInput's own check\n is off so the two cannot disagree. */}\n <EmailInput\n ref={emailField.ref}\n name={native ? fieldNames.email : 'email'}\n disableBuiltInValidation\n onChange={emailField.quiet((event) => {\n setEmail(event.target.value);\n // The server's message was about the old value.\n setServerErrors((previous) =>\n previous.email\n ? { ...previous, email: undefined }\n : previous,\n );\n })}\n onBlur={(event) => {\n // Whatever a browser filled in without saying so.\n setEmail(event.target.value);\n if (event.target.value !== '') setTouched(true);\n }}\n />\n </FormField>\n\n <ExtraFields fields={extraFields} />\n\n <Button\n type=\"submit\"\n intent=\"primary\"\n size=\"lg\"\n loading={busy}\n className=\"ds:w-full\"\n data-action=\"submit\"\n >\n {submitLabel ?? t('forgotPasswordForm.submit')}\n </Button>\n </form>\n {/* Outside the form: a screen reader may hold back what\n changes inside a busy region. */}\n <AuthFormStatus busy={busy} />\n </>\n )}\n\n {loginLink && (\n <AuthTextLink href={loginLink} action=\"login\">\n {t('forgotPasswordForm.back')}\n </AuthTextLink>\n )}\n </Card.Body>\n </Card>\n </div>\n );\n },\n);\nForgotPasswordForm.displayName = 'ForgotPasswordForm';\n"],"names":["FORGOT_PASSWORD_FORM_FIELDS","forgotPasswordFormVariants","cva","confirmationVariants","FIELDS","CONFIRMATION_HEADING","hasMessage","errors","focusTargetFor","messages","ForgotPasswordForm","forwardRef","title","description","headingLevel","showLogo","logoMotion","children","initialValues","sent","loginHref","submitLabel","submitting","onSubmit","fieldNames","action","hiddenFields","className","rest","ref","useTranslation","titleId","useId","sentTitleId","sentDescriptionId","emailFieldId","formMessageId","native","email","setEmail","useState","touched","setTouched","submitted","setSubmitted","serverErrors","setServerErrors","emailInput","useRef","emailField","useStateBackedInput","held","value","_a","invalid","isEmail","ownError","emailError","formMessage","confirmation","openedWithEmailMessage","summary","useErrorSummary","formMessageAnnounce","useFormMessageAnnounce","focusRequest","setFocusRequest","target","useEffect","wasSent","submit","useRegistrationSubmit","answer","next","busy","formAction","useFormAction","loginLink","isSafeHref","extraFields","useExtraFields","jsx","Card","AuthCardHeading","jsxs","Alert","Fragment","ErrorSummary","field","AuthFormMessage","FormField","EmailInput","event","previous","ExtraFields","Button","AuthFormStatus","AuthTextLink"],"mappings":";;;;;;;;;;;;;;AAoDO,MAAMA,KAA8B,CAAC,OAAO,GAuH7CC,KAA6BC;AAAA,EACjC;AACF,GAGMC,KAAuBD;AAAA,EAC3B;AACF,GASME,KAAS,CAAC,OAAO,GAGjBC,KAAuB,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAA,GAE9CC,KAAa,CAACC,MAClB,OAAO,OAAOA,CAAM,EAAE,KAAK,OAAO,GAE9BC,IAAiB,CACrBC,MAEAA,EAAS,QAAQ,UAAUA,EAAS,OAAO,SAAS,QAUzCC,KAAqBC;AAAA,EAIhC,CACE;AAAA,IACE,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,cAAAC,IAAe;AAAA,IACf,UAAAC,IAAW;AAAA,IACX,YAAAC,IAAa;AAAA,IACb,UAAAC;AAAA,IACA,eAAAC;AAAA,IACA,QAAAX;AAAA,IACA,MAAAY,IAAO;AAAA,IACP,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,YAAAC,IAAa;AAAA,IACb,UAAAC;AAAA,IACA,YAAAC;AAAA,IACA,QAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,GAELC,OACG;AACH,UAAM,EAAE,EAAA,IAAMC,GAAe,IAAI,GAC3BC,IAAUC,EAAA,GACVC,IAAcD,EAAA,GACdE,IAAoBF,EAAA,GACpBG,IAAeH,EAAA,GACfI,IAAgBJ,EAAA,GAChBK,IAASb,MAAe,QAIxB,CAACc,GAAOC,CAAQ,IAAIC,EAAS,OAAMtB,KAAA,gBAAAA,EAAe,UAAS,EAAE,GAK7D,CAACuB,IAASC,EAAU,IAAIF,EAAS,MAAM,GAAQtB,KA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AA,sBACL,QAAO;AAAA,sBACP,MAAK;AAAA,sBACL,SAASrB;AAAA,sBACT,WAAU;AAAA,sBACV,eAAY;AAAA,sBAEX,UAAArD,KAAe,EAAE,2BAA2B;AAAA,oBAAA;AAAA,kBAAA;AAAA,gBAC/C;AAAA,cAAA;AAAA,YAAA;AAAA,YAIF,gBAAA4D,EAACe,MAAe,MAAAtB,EAAA,CAAY;AAAA,UAAA,GAC9B;AAAA,UAGDG,uBACEoB,IAAA,EAAa,MAAMpB,GAAW,QAAO,SACnC,UAAA,EAAE,yBAAyB,EAAA,CAC9B;AAAA,QAAA,EAAA,CAEJ,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AACAnE,GAAmB,cAAc;"}
1
+ {"version":3,"file":"forgot-password-form-BQPvDS7i.js","sources":["../../src/patterns/forgot-password-form/forgot-password-form.tsx"],"sourcesContent":["/* -------------------------------------------------------------------- */\n/* ForgotPasswordForm — the card that asks for a password reset link. */\n/* */\n/* One email field and a button, then a confirmation. The confirmation */\n/* is vague on purpose: it never says whether an account exists for the */\n/* address, and never repeats the address. The host sends the email and */\n/* owns every server rule; the card checks what a browser can check, */\n/* then hands the email to `onSubmit` or posts a real form. */\n/* -------------------------------------------------------------------- */\n\nimport {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n} from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { cva } from 'class-variance-authority';\n// The validator EmailInput itself uses, so the two never disagree.\nimport isEmail from 'validator/lib/isEmail';\nimport { Alert } from '../../components/alert';\nimport { Button } from '../../components/button';\nimport { Card } from '../../components/card';\nimport { EmailInput } from '../../components/email-input';\nimport { ErrorSummary } from '../../components/error-summary';\nimport { FormField } from '../../components/form-field';\nimport { isSafeHref } from '../../components/_shared/safe-href';\nimport { useStateBackedInput } from '../../components/_shared/use-state-backed-input';\nimport {\n AuthCardHeading,\n AuthFormMessage,\n AuthFormStatus,\n AuthTextLink,\n ExtraFields,\n useExtraFields,\n useFormAction,\n} from '../_shared/auth-form-parts';\nimport type { BrandMarkMotion } from '../_shared/brand-mark';\nimport {\n useErrorSummary,\n useFormMessageAnnounce,\n} from '../_shared/use-error-summary';\nimport { useRegistrationSubmit } from '../registration-form/use-registration-submit';\n\n/* -------------------------------------------------------------------- */\n/* Types */\n/* -------------------------------------------------------------------- */\n\n/** The form's one field. */\nexport const FORGOT_PASSWORD_FORM_FIELDS = ['email'] as const;\n\nexport type ForgotPasswordFormField =\n (typeof FORGOT_PASSWORD_FORM_FIELDS)[number];\n\n/** What `onSubmit` receives once the email has passed its check. */\nexport interface ForgotPasswordFormValues {\n email: string;\n}\n\n/** The email to show when the form opens. */\nexport type ForgotPasswordFormInitialValues = Partial<ForgotPasswordFormValues>;\n\n/** Messages from the server, already translated: one for the email,\n * plus `form` for a message about the whole form, such as \"too many\n * requests, try again later\". */\nexport type ForgotPasswordFormErrors = Partial<\n Record<ForgotPasswordFormField | 'form', string>\n>;\n\n/** The host's own form field name, for a native form post. It is needed:\n * a field without a name is not posted. */\nexport type ForgotPasswordFormFieldNames = Record<\n ForgotPasswordFormField,\n string\n>;\n\nexport interface ForgotPasswordFormProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'title' | 'onSubmit'\n> {\n /** Replaces the heading \"Reset your password\". Pass it translated. */\n title?: string;\n /**\n * Replaces the line under the heading (\"Enter the email linked to your\n * account and we will send a reset link.\"). Pass it translated.\n */\n description?: string;\n /**\n * The heading's level. Default 1: this page usually has no other\n * heading. Pass 2 on a page that has its own `h1`.\n */\n headingLevel?: 1 | 2 | 3;\n /**\n * Shows the Alfadocs mark above the heading, with the heading and its\n * line centred under it. Default true.\n */\n showLogo?: boolean;\n /** How the mark arrives when the card opens. Default `assemble`. It\n * plays once and rests. */\n logoMotion?: BrandMarkMotion;\n /**\n * Host content between the heading and the field, such as a notice. It\n * sits outside the form, so nothing in it is posted.\n */\n children?: ReactNode;\n /** The email to show when the form opens. Read once. */\n initialValues?: ForgotPasswordFormInitialValues;\n /**\n * Messages from the server, already translated. The email's message\n * shows on the field until the user changes it; `form` shows above the\n * field. When messages arrive, focus moves to the error summary at the\n * top of the form when the email has a message, or to the message\n * above the field when only that says something.\n *\n * Do not use a message to say that no account has the address: that\n * tells a stranger who has an account. Show `sent` for every address.\n */\n errors?: ForgotPasswordFormErrors;\n /**\n * Shows the confirmation in place of the form: \"Check your inbox\". Set\n * it once the request has been accepted, whether or not an account\n * exists for the address. The confirmation says \"if an account exists\"\n * and never shows the address.\n */\n sent?: boolean;\n /**\n * Adds \"Back to sign in\" under the card's content. A path on the same\n * site, or an address written in full. Anything else shows no link.\n */\n loginHref?: string;\n /** Replaces the button's \"Send reset link\". Pass it translated. */\n submitLabel?: string;\n /**\n * True while the host sends the email: the button shows a spinner and\n * a second submit is ignored. Set it inside `onSubmit`, before anything\n * is awaited: until it is true, a second press sends a second request.\n */\n submitting?: boolean;\n /** For React hosts: called with the email once it has passed its\n * check. Not called when `fieldNames` is set. */\n onSubmit?: (values: ForgotPasswordFormValues) => void;\n /**\n * For a native form post: the host's own field name, e.g.\n * `{ email: 'email' }`. When set, the input carries that name and the\n * browser posts the form.\n */\n fieldNames?: ForgotPasswordFormFieldNames;\n /**\n * Where a native form post goes. Default: the current address. Only a\n * path, or an address on the page's own origin, is accepted: another\n * origin is never sent what the user typed, and the post then goes to\n * the current address. Does nothing without `fieldNames`.\n */\n action?: string;\n /**\n * Extra hidden inputs posted with a native form, by name: a CSRF\n * token. Not used with `onSubmit`. A name that is also the one in\n * `fieldNames` is left out: the form's own field wins.\n */\n hiddenFields?: Readonly<Record<string, string>>;\n}\n\n/* -------------------------------------------------------------------- */\n/* Styles */\n/* -------------------------------------------------------------------- */\n\n// 400px at most, in px: a host whose root font size is not 16px would\n// stretch or squeeze a width in rem.\nconst forgotPasswordFormVariants = cva(\n 'ds:mx-auto ds:w-full ds:max-w-[400px] ds:text-start ds:text-[var(--foreground)]',\n);\n\n// The confirmation takes focus when it appears, so it shows a ring.\nconst confirmationVariants = cva(\n 'ds:focus-visible:outline-solid ds:focus-visible:outline-[length:var(--focus-ring-width)] ds:focus-visible:outline-[var(--ring)] ds:focus-visible:outline-offset-[length:var(--focus-ring-offset)] ds:forced-colors:focus-visible:outline-[CanvasText]',\n);\n\n/* -------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------- */\n\ntype FocusTarget = 'email' | 'form';\n\n/** The form's one field, as the error summary lists it. */\nconst FIELDS = ['email'] as const;\n\n/** The confirmation's heading, by the level of the card's own. */\nconst CONFIRMATION_HEADING = { 1: 'h2', 2: 'h3', 3: 'h4' } as const;\n\nconst hasMessage = (errors: ForgotPasswordFormErrors): boolean =>\n Object.values(errors).some(Boolean);\n\nconst focusTargetFor = (\n messages: ForgotPasswordFormErrors,\n): FocusTarget | undefined =>\n messages.email ? 'email' : messages.form ? 'form' : undefined;\n\n/* -------------------------------------------------------------------- */\n/* Component */\n/* -------------------------------------------------------------------- */\n\n/**\n * The card that asks for a password reset link. Mount it on the\n * forgot-password page, inside `SignedOutFrame` or the host's own chrome.\n */\nexport const ForgotPasswordForm = forwardRef<\n HTMLDivElement,\n ForgotPasswordFormProps\n>(\n (\n {\n title,\n description,\n headingLevel = 1,\n showLogo = true,\n logoMotion = 'assemble',\n children,\n initialValues,\n errors,\n sent = false,\n loginHref,\n submitLabel,\n submitting = false,\n onSubmit,\n fieldNames,\n action,\n hiddenFields,\n className,\n ...rest\n },\n ref,\n ) => {\n const { t } = useTranslation('ui');\n const titleId = useId();\n const sentTitleId = useId();\n const sentDescriptionId = useId();\n const emailFieldId = useId();\n const formMessageId = useId();\n const native = fieldNames !== undefined;\n\n /* ------------------------------ State ----------------------------- */\n\n const [email, setEmail] = useState(() => initialValues?.email ?? '');\n // True once the user has filled in the field and left it. An email\n // that arrives filled in counts: a bad one is then flagged at once,\n // with its message. An empty field is not flagged for being passed\n // through; its message waits for a submit.\n const [touched, setTouched] = useState(() => Boolean(initialValues?.email));\n const [submitted, setSubmitted] = useState(false);\n const [serverErrors, setServerErrors] = useState<ForgotPasswordFormErrors>(\n () => errors ?? {},\n );\n\n const emailInput = useRef<HTMLInputElement>(null);\n // The address stays out of the input's `value` attribute, where a\n // copied outerHTML or a session replay could read it.\n const emailField = useStateBackedInput(email, emailInput);\n /**\n * What the input holds now. Read from the input, not from state: a\n * browser can fill the field without telling React, and the form must\n * not refuse a field that is visibly filled.\n */\n const held = (): string => {\n const value = emailInput.current?.value ?? email;\n if (value !== email) setEmail(value);\n return value;\n };\n\n /* ---------------------------- Validation -------------------------- */\n\n const invalid = !isEmail(email);\n // The message shows once the user has left the field or tried to\n // submit.\n const ownError =\n (submitted || touched) && invalid\n ? email === ''\n ? t('forgotPasswordForm.emailRequired')\n : t('inputs.email.invalid')\n : undefined;\n const emailError = serverErrors.email ?? ownError;\n\n /* ------------------------------ Focus ----------------------------- */\n\n const formMessage = useRef<HTMLDivElement>(null);\n const confirmation = useRef<HTMLDivElement>(null);\n\n // The email's message after a refused submit, or after a server\n // answer, is listed at the top of the form, and focus goes there. A\n // page the server rendered after a failed post opens that way too: it\n // announces nothing itself.\n const [openedWithEmailMessage] = useState(() => Boolean(errors?.email));\n const summary = useErrorSummary(\n FIELDS,\n () => emailError,\n openedWithEmailMessage,\n );\n // The message about the whole form: quiet while the summary lists the\n // email, because the summary reads it then.\n const formMessageAnnounce = useFormMessageAnnounce(\n serverErrors.form,\n summary.listed.length > 0,\n );\n\n // Any other place focus goes: the message above the field, when only\n // it says something. A new object for each request, so asking twice\n // for the same place moves focus twice.\n const [focusRequest, setFocusRequest] = useState<{\n target: FocusTarget;\n } | null>(() => {\n const target = openedWithEmailMessage\n ? undefined\n : focusTargetFor(errors ?? {});\n return target ? { target } : null;\n });\n useEffect(() => {\n if (!focusRequest) return;\n (focusRequest.target === 'email'\n ? emailInput\n : formMessage\n ).current?.focus();\n }, [focusRequest]);\n\n // The form, and the button that had focus, are gone once the\n // confirmation shows. Move focus to it, so a keyboard or screen\n // reader user lands on what happened. Not on a page that opens\n // already sent: that one is read from the top like any other.\n const wasSent = useRef(sent);\n useEffect(() => {\n if (sent && !wasSent.current) confirmation.current?.focus();\n wasSent.current = sent;\n }, [sent]);\n\n /* ------------------------------ Submit ---------------------------- */\n\n const submit = useRegistrationSubmit<'email'>({\n errors,\n submitting,\n native,\n captcha: false,\n firstProblem: () => (isEmail(held()) ? undefined : 'email'),\n onRefused: () => {\n setSubmitted(true);\n summary.open(() => setFocusRequest({ target: 'email' }));\n },\n // Only a React host gets here: a native post is the browser's own.\n deliver: () => onSubmit?.({ email: held() }),\n onAnswer: (answer) => {\n const next: ForgotPasswordFormErrors = answer;\n setServerErrors(next);\n if (!hasMessage(next)) return;\n setSubmitted(false);\n // The summary when the email has a message, else the message above.\n summary.open(() => {\n const target = focusTargetFor(next);\n if (target) setFocusRequest({ target });\n });\n },\n });\n const { busy } = submit;\n\n /* ------------------------------ Render ---------------------------- */\n\n const formAction = useFormAction('ForgotPasswordForm', native, action);\n const loginLink =\n loginHref && isSafeHref(loginHref) ? loginHref : undefined;\n const extraFields = useExtraFields(\n 'ForgotPasswordForm',\n native,\n fieldNames,\n hiddenFields,\n );\n\n return (\n <div\n ref={ref}\n {...rest}\n data-component=\"forgot-password-form\"\n data-state={sent ? 'sent' : 'asking'}\n className={forgotPasswordFormVariants({ className })}\n >\n <Card variant=\"elevated\">\n <Card.Body className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-lg)]\">\n <AuthCardHeading\n id={titleId}\n title={title ?? t('forgotPasswordForm.title')}\n // The instruction belongs to the form: once it is sent there\n // is nothing left to enter.\n description={\n sent\n ? undefined\n : (description ?? t('forgotPasswordForm.description'))\n }\n level={headingLevel}\n showLogo={showLogo}\n logoMotion={logoMotion}\n />\n\n {children ? (\n <div\n data-slot=\"host-content\"\n className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\"\n >\n {children}\n </div>\n ) : null}\n\n {sent ? (\n // Named and described, so a screen reader that lands here\n // reads the whole confirmation, not only \"status\".\n <Alert\n ref={confirmation}\n variant=\"success\"\n tabIndex={-1}\n aria-labelledby={sentTitleId}\n aria-describedby={sentDescriptionId}\n data-slot=\"confirmation\"\n className={confirmationVariants()}\n >\n {/* One level under the card's own heading. */}\n <Alert.Title\n id={sentTitleId}\n as={CONFIRMATION_HEADING[headingLevel]}\n >\n {t('forgotPasswordForm.sentTitle')}\n </Alert.Title>\n <Alert.Description id={sentDescriptionId}>\n {t('forgotPasswordForm.sentDescription')}\n </Alert.Description>\n </Alert>\n ) : (\n <>\n <form\n noValidate\n method=\"post\"\n action={formAction}\n aria-labelledby={titleId}\n aria-busy={busy || undefined}\n onSubmit={submit.handleSubmit}\n className=\"ds:flex ds:flex-col ds:gap-[var(--spacing-md)]\"\n >\n <ErrorSummary\n ref={summary.ref}\n headingLevel={(headingLevel + 1) as 2 | 3 | 4}\n // The message about the whole form is read with it.\n aria-describedby={\n serverErrors.form ? formMessageId : undefined\n }\n errors={summary.listed.map((field) => ({\n field,\n message: emailError ?? '',\n targetId: emailFieldId,\n }))}\n />\n\n {serverErrors.form && (\n <AuthFormMessage\n ref={formMessage}\n id={formMessageId}\n announce={formMessageAnnounce}\n >\n {serverErrors.form}\n </AuthFormMessage>\n )}\n\n <FormField\n id={emailFieldId}\n label={t('forgotPasswordForm.email')}\n required\n error={emailError}\n // Quiet while the summary lists it: the summary reads it.\n announceError={!summary.lists('email')}\n data-field=\"email\"\n >\n {/* One check, above, drives the message, the red mark and\n aria-invalid through FormField. EmailInput's own check\n is off so the two cannot disagree. */}\n <EmailInput\n ref={emailField.ref}\n name={native ? fieldNames.email : 'email'}\n disableBuiltInValidation\n onChange={emailField.quiet((event) => {\n setEmail(event.target.value);\n // The server's message was about the old value.\n setServerErrors((previous) =>\n previous.email\n ? { ...previous, email: undefined }\n : previous,\n );\n })}\n onBlur={(event) => {\n // Whatever a browser filled in without saying so.\n setEmail(event.target.value);\n if (event.target.value !== '') setTouched(true);\n }}\n />\n </FormField>\n\n <ExtraFields fields={extraFields} />\n\n <Button\n type=\"submit\"\n intent=\"primary\"\n size=\"lg\"\n loading={busy}\n className=\"ds:w-full\"\n data-action=\"submit\"\n >\n {submitLabel ?? t('forgotPasswordForm.submit')}\n </Button>\n </form>\n {/* Outside the form: a screen reader may hold back what\n changes inside a busy region. */}\n <AuthFormStatus busy={busy} />\n </>\n )}\n\n {loginLink && (\n <AuthTextLink href={loginLink} action=\"login\">\n {t('forgotPasswordForm.back')}\n </AuthTextLink>\n )}\n </Card.Body>\n </Card>\n </div>\n );\n },\n);\nForgotPasswordForm.displayName = 'ForgotPasswordForm';\n"],"names":["FORGOT_PASSWORD_FORM_FIELDS","forgotPasswordFormVariants","cva","confirmationVariants","FIELDS","CONFIRMATION_HEADING","hasMessage","errors","focusTargetFor","messages","ForgotPasswordForm","forwardRef","title","description","headingLevel","showLogo","logoMotion","children","initialValues","sent","loginHref","submitLabel","submitting","onSubmit","fieldNames","action","hiddenFields","className","rest","ref","useTranslation","titleId","useId","sentTitleId","sentDescriptionId","emailFieldId","formMessageId","native","email","setEmail","useState","touched","setTouched","submitted","setSubmitted","serverErrors","setServerErrors","emailInput","useRef","emailField","useStateBackedInput","held","value","_a","invalid","isEmail","ownError","emailError","formMessage","confirmation","openedWithEmailMessage","summary","useErrorSummary","formMessageAnnounce","useFormMessageAnnounce","focusRequest","setFocusRequest","target","useEffect","wasSent","submit","useRegistrationSubmit","answer","next","busy","formAction","useFormAction","loginLink","isSafeHref","extraFields","useExtraFields","jsx","Card","AuthCardHeading","jsxs","Alert","Fragment","ErrorSummary","field","AuthFormMessage","FormField","EmailInput","event","previous","ExtraFields","Button","AuthFormStatus","AuthTextLink"],"mappings":";;;;;;;;;;;;;;AAoDO,MAAMA,KAA8B,CAAC,OAAO,GAuH7CC,KAA6BC;AAAA,EACjC;AACF,GAGMC,KAAuBD;AAAA,EAC3B;AACF,GASME,KAAS,CAAC,OAAO,GAGjBC,KAAuB,EAAE,GAAG,MAAM,GAAG,MAAM,GAA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AAA,CAEJ,EAAA,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AACAnE,GAAmB,cAAc;"}
@@ -0,0 +1,185 @@
1
+ import { jsxs as r, Fragment as X, jsx as s } from "react/jsx-runtime";
2
+ import { forwardRef as Y, useId as Z, useState as D, useMemo as E, useRef as T, useCallback as ee } from "react";
3
+ import { c as V } from "./index-D2ZczOXr.js";
4
+ import { useTranslation as se } from "react-i18next";
5
+ import { F as te } from "./form-field-context-DtiROUJV.js";
6
+ import { C as ne } from "./circle-alert-rGDZ73Wh.js";
7
+ const re = V("ds:text-start", {
8
+ variants: {
9
+ orientation: {
10
+ vertical: "ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]",
11
+ horizontal: "ds:grid ds:grid-cols-[minmax(0,var(--form-label-inline-size))_minmax(0,1fr)] ds:items-start ds:gap-x-[var(--spacing-md)] ds:gap-y-[var(--spacing-xs)]"
12
+ },
13
+ disabled: {
14
+ true: "ds:opacity-50 ds:cursor-not-allowed",
15
+ false: ""
16
+ }
17
+ },
18
+ defaultVariants: {
19
+ orientation: "vertical",
20
+ disabled: !1
21
+ }
22
+ }), ae = V("ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]", {
23
+ variants: {
24
+ orientation: {
25
+ vertical: "",
26
+ horizontal: "ds:min-w-0"
27
+ }
28
+ },
29
+ defaultVariants: {
30
+ orientation: "vertical"
31
+ }
32
+ }), oe = Y(
33
+ ($, j) => {
34
+ const {
35
+ label: m,
36
+ labelStart: i,
37
+ labelEnd: d,
38
+ description: c,
39
+ error: t,
40
+ announceError: L = !0,
41
+ errorAction: h,
42
+ required: p = !1,
43
+ optional: P = !1,
44
+ orientation: b = "vertical",
45
+ disabled: u = !1,
46
+ className: _,
47
+ children: A,
48
+ ...M
49
+ } = $, { t: q } = se("ui"), e = Z(), a = `${e}-help`, o = `${e}-error`, G = `${e}-notice`, N = !!t, [y, U] = D(void 0), F = E(
50
+ () => [c ? a : null, t ? o : null].filter(Boolean).join(" "),
51
+ [c, t, a, o]
52
+ ), I = T(null), W = T([]), [H, C] = D(null), O = ee(
53
+ (B) => {
54
+ const l = W.current, k = () => {
55
+ var z;
56
+ const n = (z = I.current) == null ? void 0 : z.getRootNode(), f = (x) => n instanceof Document || n instanceof ShadowRoot ? n.getElementById(x) : null;
57
+ if (l.includes(e) || f(e)) {
58
+ C(null);
59
+ return;
60
+ }
61
+ const K = [...l].sort((x, Q) => {
62
+ const g = f(x), v = f(Q);
63
+ return !g || !v || g === v ? 0 : g.compareDocumentPosition(v) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
64
+ });
65
+ C(K[0] ?? null);
66
+ };
67
+ return l.push(B), k(), () => {
68
+ const n = l.indexOf(B);
69
+ n !== -1 && l.splice(n, 1), k();
70
+ };
71
+ },
72
+ [e]
73
+ ), R = typeof m == "string" ? m : void 0, J = E(
74
+ () => ({
75
+ id: e,
76
+ helpId: a,
77
+ errorId: o,
78
+ describedBy: F,
79
+ invalid: N,
80
+ required: p,
81
+ disabled: u,
82
+ label: R,
83
+ registerControlId: O,
84
+ setNotice: U
85
+ }),
86
+ [
87
+ e,
88
+ a,
89
+ o,
90
+ F,
91
+ N,
92
+ p,
93
+ u,
94
+ R,
95
+ O
96
+ ]
97
+ ), S = /* @__PURE__ */ r(X, { children: [
98
+ m,
99
+ p && /* @__PURE__ */ s(
100
+ "span",
101
+ {
102
+ "aria-hidden": "true",
103
+ className: "ds:text-destructive ds:ms-[var(--spacing-xs)]",
104
+ children: "*"
105
+ }
106
+ ),
107
+ P && /* @__PURE__ */ r("span", { className: "ds:text-muted-foreground ds:ms-[var(--spacing-xs)] ds:font-normal", children: [
108
+ "(",
109
+ q("common.optional", "optional"),
110
+ ")"
111
+ ] })
112
+ ] }), w = !!(i || d);
113
+ return /* @__PURE__ */ s(te.Provider, { value: J, children: /* @__PURE__ */ r(
114
+ "div",
115
+ {
116
+ ref: j,
117
+ className: re({ orientation: b, disabled: u, className: _ }),
118
+ "data-component": "form-field",
119
+ ...M,
120
+ children: [
121
+ /* @__PURE__ */ r(
122
+ "label",
123
+ {
124
+ ref: I,
125
+ id: `${e}-label`,
126
+ htmlFor: H ?? e,
127
+ className: w ? "type-label ds:text-foreground ds:flex ds:items-start ds:gap-[var(--spacing-xs)]" : "type-label ds:text-foreground",
128
+ children: [
129
+ i ? /* @__PURE__ */ s("span", { className: "ds:inline-flex ds:shrink-0 ds:items-center", children: i }) : null,
130
+ i ? " " : null,
131
+ w ? /* @__PURE__ */ s("span", { children: S }) : S,
132
+ d ? " " : null,
133
+ d ? /* @__PURE__ */ s("span", { className: "ds:ms-auto ds:inline-flex ds:shrink-0 ds:items-center", children: d }) : null
134
+ ]
135
+ }
136
+ ),
137
+ /* @__PURE__ */ r("div", { className: ae({ orientation: b }), children: [
138
+ A,
139
+ c && /* @__PURE__ */ s("p", { id: a, className: "type-body-sm ds:text-muted-foreground", children: c }),
140
+ y && /* @__PURE__ */ s(
141
+ "p",
142
+ {
143
+ id: G,
144
+ className: "type-body-sm ds:text-muted-foreground",
145
+ children: y
146
+ }
147
+ ),
148
+ t && /* @__PURE__ */ r(
149
+ "p",
150
+ {
151
+ id: o,
152
+ role: L ? "alert" : void 0,
153
+ "data-slot": "error",
154
+ className: "ds:inline-flex ds:items-center ds:gap-[var(--spacing-xs)] type-body-sm ds:text-destructive",
155
+ children: [
156
+ /* @__PURE__ */ s(
157
+ ne,
158
+ {
159
+ "aria-hidden": "true",
160
+ className: "ds:size-4 ds:shrink-0"
161
+ }
162
+ ),
163
+ /* @__PURE__ */ s("span", { children: t })
164
+ ]
165
+ }
166
+ ),
167
+ t && h ? /* @__PURE__ */ s(
168
+ "div",
169
+ {
170
+ "data-slot": "error-action",
171
+ className: "type-body-sm ds:flex ds:flex-wrap ds:items-center ds:gap-x-[var(--spacing-md)] ds:gap-y-[var(--spacing-xs)]",
172
+ children: h
173
+ }
174
+ ) : null
175
+ ] })
176
+ ]
177
+ }
178
+ ) });
179
+ }
180
+ );
181
+ oe.displayName = "FormField";
182
+ export {
183
+ oe as F
184
+ };
185
+ //# sourceMappingURL=form-field-CyHfOVKF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-field-CyHfOVKF.js","sources":["../../src/components/form-field/form-field.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useId,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n} from 'react';\nimport { cva, type VariantProps } from 'class-variance-authority';\nimport { useTranslation } from 'react-i18next';\nimport { CircleAlert } from 'lucide-react';\nimport {\n FormFieldContext,\n type FormFieldContextShape,\n} from './form-field-context';\n\nconst fieldVariants = cva('ds:text-start', {\n variants: {\n orientation: {\n vertical: 'ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]',\n horizontal:\n 'ds:grid ds:grid-cols-[minmax(0,var(--form-label-inline-size))_minmax(0,1fr)] ds:items-start ds:gap-x-[var(--spacing-md)] ds:gap-y-[var(--spacing-xs)]',\n },\n disabled: {\n true: 'ds:opacity-50 ds:cursor-not-allowed',\n false: '',\n },\n },\n defaultVariants: {\n orientation: 'vertical',\n disabled: false,\n },\n});\n\nconst slotsVariants = cva('ds:flex ds:flex-col ds:gap-[var(--spacing-xs)]', {\n variants: {\n orientation: {\n vertical: '',\n horizontal: 'ds:min-w-0',\n },\n },\n defaultVariants: {\n orientation: 'vertical',\n },\n});\n\ntype RequiredIndicator =\n | { required?: boolean; optional?: never }\n | { required?: never; optional?: boolean };\n\ninterface BaseFormFieldProps\n extends\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>,\n Omit<VariantProps<typeof fieldVariants>, 'disabled'> {\n label: string;\n /**\n * Rendered at the inline START of the label line, `--spacing-xs` before\n * the text — a status chip or a marker, never a control. Part of the\n * label, so its text joins the field's accessible name (\"Highlighted,\n * Allergies\"). Use it when the mark qualifies the question itself; a\n * reader should not have to cross the line to learn what it refers to.\n */\n labelStart?: React.ReactNode;\n /**\n * Rendered at the inline end of the label line — a status chip or a\n * marker, never a control. Part of the label, so its text joins the\n * field's accessible name (\"Allergies, Highlighted\").\n */\n labelEnd?: React.ReactNode;\n description?: string;\n error?: string;\n /**\n * Read the error out the moment it appears (`role=\"alert\"`). Default\n * true: right for a field checked on its own, as the user leaves it.\n * Pass false while an `ErrorSummary` lists this field's error: the\n * summary takes focus and reads every problem once, so the fields stay\n * quiet instead of each interrupting at the same time. The message is\n * still tied to the control, so it is read when the control has focus.\n */\n announceError?: boolean;\n /**\n * Shown on its own line directly under the error, only while there is an\n * error: the way forward from it, such as a \"Sign in\" link. Not part of\n * the announced message. Keep it to links or buttons.\n */\n errorAction?: React.ReactNode;\n disabled?: boolean;\n children: React.ReactNode;\n}\n\nexport type FormFieldProps = BaseFormFieldProps & RequiredIndicator;\n\nexport const FormField = forwardRef<HTMLDivElement, FormFieldProps>(\n (props, ref) => {\n const {\n label,\n labelStart,\n labelEnd,\n description,\n error,\n announceError = true,\n errorAction,\n required = false,\n optional = false,\n orientation = 'vertical',\n disabled = false,\n className,\n children,\n ...rest\n } = props as BaseFormFieldProps & {\n required?: boolean;\n optional?: boolean;\n };\n\n const { t } = useTranslation('ui');\n const id = useId();\n const helpId = `${id}-help`;\n const errorId = `${id}-error`;\n const noticeId = `${id}-notice`;\n const invalid = Boolean(error);\n const [notice, setNotice] = useState<string | undefined>(undefined);\n\n const describedBy = useMemo(\n () =>\n [description ? helpId : null, error ? errorId : null]\n .filter(Boolean)\n .join(' '),\n [description, error, helpId, errorId],\n );\n\n /* The ids the controls inside really render. The label follows one of\n them only while nothing uses the field's own id: a control that reads\n `useFormField().id` itself never registers, so the DOM is asked too.\n Of several host ids, the first in the document wins. */\n const labelRef = useRef<HTMLLabelElement>(null);\n const controlIdsRef = useRef<string[]>([]);\n const [customControlId, setCustomControlId] = useState<string | null>(null);\n const registerControlId = useCallback(\n (controlId: string) => {\n const ids = controlIdsRef.current;\n const sync = () => {\n const root = labelRef.current?.getRootNode();\n const find = (elementId: string) =>\n root instanceof Document || root instanceof ShadowRoot\n ? root.getElementById(elementId)\n : null;\n if (ids.includes(id) || find(id)) {\n setCustomControlId(null);\n return;\n }\n const inDocumentOrder = [...ids].sort((a, b) => {\n const first = find(a);\n const second = find(b);\n if (!first || !second || first === second) return 0;\n return first.compareDocumentPosition(second) &\n Node.DOCUMENT_POSITION_FOLLOWING\n ? -1\n : 1;\n });\n setCustomControlId(inDocumentOrder[0] ?? null);\n };\n ids.push(controlId);\n sync();\n return () => {\n const index = ids.indexOf(controlId);\n if (index !== -1) ids.splice(index, 1);\n sync();\n };\n },\n [id],\n );\n\n const labelString = typeof label === 'string' ? label : undefined;\n\n const ctx: FormFieldContextShape = useMemo(\n () => ({\n id,\n helpId,\n errorId,\n describedBy,\n invalid,\n required,\n disabled,\n label: labelString,\n registerControlId,\n setNotice,\n }),\n [\n id,\n helpId,\n errorId,\n describedBy,\n invalid,\n required,\n disabled,\n labelString,\n registerControlId,\n ],\n );\n\n const labelText = (\n <>\n {label}\n {required && (\n <span\n aria-hidden=\"true\"\n className=\"ds:text-destructive ds:ms-[var(--spacing-xs)]\"\n >\n *\n </span>\n )}\n {optional && (\n <span className=\"ds:text-muted-foreground ds:ms-[var(--spacing-xs)] ds:font-normal\">\n ({t('common.optional', 'optional')})\n </span>\n )}\n </>\n );\n\n const hasLabelSlot = Boolean(labelStart || labelEnd);\n\n return (\n <FormFieldContext.Provider value={ctx}>\n <div\n ref={ref}\n className={fieldVariants({ orientation, disabled, className })}\n data-component=\"form-field\"\n {...rest}\n >\n <label\n ref={labelRef}\n id={`${id}-label`}\n htmlFor={customControlId ?? id}\n className={\n hasLabelSlot\n ? 'type-label ds:text-foreground ds:flex ds:items-start ds:gap-[var(--spacing-xs)]'\n : 'type-label ds:text-foreground'\n }\n >\n {labelStart ? (\n <span className=\"ds:inline-flex ds:shrink-0 ds:items-center\">\n {labelStart}\n </span>\n ) : null}\n {/* An explicit separator, so the accessible name reads\n \"Highlighted, Allergies\" and not one run-on word. The label\n row is a flex box, which drops a whitespace-only text node —\n it costs nothing on screen. */}\n {labelStart ? ' ' : null}\n {/* Wrapped only when a slot sits beside it: the plain label\n keeps its text as a direct child, as consumers assert. */}\n {hasLabelSlot ? <span>{labelText}</span> : labelText}\n {labelEnd ? ' ' : null}\n {labelEnd ? (\n <span className=\"ds:ms-auto ds:inline-flex ds:shrink-0 ds:items-center\">\n {labelEnd}\n </span>\n ) : null}\n </label>\n <div className={slotsVariants({ orientation })}>\n {children}\n {description && (\n <p id={helpId} className=\"type-body-sm ds:text-muted-foreground\">\n {description}\n </p>\n )}\n {/* Neither live nor in the field's description: the control\n announces it, and a description that changes while the\n field has focus is read again by NVDA. */}\n {notice && (\n <p\n id={noticeId}\n className=\"type-body-sm ds:text-muted-foreground\"\n >\n {notice}\n </p>\n )}\n {error && (\n <p\n id={errorId}\n role={announceError ? 'alert' : undefined}\n // A hook that holds whether or not the message is announced.\n data-slot=\"error\"\n className=\"ds:inline-flex ds:items-center ds:gap-[var(--spacing-xs)] type-body-sm ds:text-destructive\"\n >\n <CircleAlert\n aria-hidden=\"true\"\n className=\"ds:size-4 ds:shrink-0\"\n />\n <span>{error}</span>\n </p>\n )}\n {error && errorAction ? (\n <div\n data-slot=\"error-action\"\n className=\"type-body-sm ds:flex ds:flex-wrap ds:items-center ds:gap-x-[var(--spacing-md)] ds:gap-y-[var(--spacing-xs)]\"\n >\n {errorAction}\n </div>\n ) : null}\n </div>\n </div>\n </FormFieldContext.Provider>\n );\n },\n);\n\nFormField.displayName = 'FormField';\n"],"names":["fieldVariants","cva","slotsVariants","FormField","forwardRef","props","ref","label","labelStart","labelEnd","description","error","announceError","errorAction","required","optional","orientation","disabled","className","children","rest","t","useTranslation","id","useId","helpId","errorId","noticeId","invalid","notice","setNotice","useState","describedBy","useMemo","labelRef","useRef","controlIdsRef","customControlId","setCustomControlId","registerControlId","useCallback","controlId","ids","sync","root","_a","find","elementId","inDocumentOrder","a","b","first","second","index","labelString","ctx","labelText","jsxs","Fragment","jsx","hasLabelSlot","FormFieldContext","CircleAlert"],"mappings":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;AAAA,UAAA;AAAA,4BAEL,OAAA,EAAI,WAAWzD,GAAc,EAAE,aAAAc,EAAA,CAAa,GAC1C,UAAA;AAAA,YAAAG;AAAA,YACAT,KACC,gBAAAiD,EAAC,KAAA,EAAE,IAAIlC,GAAQ,WAAU,yCACtB,UAAAf,GACH;AAAA,YAKDmB,KACC,gBAAA8B;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,IAAIhC;AAAA,gBACJ,WAAU;AAAA,gBAET,UAAAE;AAAA,cAAA;AAAA,YAAA;AAAA,YAGJlB,KACC,gBAAA8C;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,IAAI/B;AAAA,gBACJ,MAAMd,IAAgB,UAAU;AAAA,gBAEhC,aAAU;AAAA,gBACV,WAAU;AAAA,gBAEV,UAAA;AAAA,kBAAA,gBAAA+C;AAAA,oBAACG;AAAA,oBAAA;AAAA,sBACC,eAAY;AAAA,sBACZ,WAAU;AAAA,oBAAA;AAAA,kBAAA;AAAA,kBAEZ,gBAAAH,EAAC,UAAM,UAAAhD,EAAA,CAAM;AAAA,gBAAA;AAAA,cAAA;AAAA,YAAA;AAAA,YAGhBA,KAASE,IACR,gBAAA8C;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,aAAU;AAAA,gBACV,WAAU;AAAA,gBAET,UAAA9C;AAAA,cAAA;AAAA,YAAA,IAED;AAAA,UAAA,EAAA,CACN;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,GAEJ;AAAA,EAEJ;AACF;AAEAV,GAAU,cAAc;"}
@@ -5,7 +5,7 @@ import { useTranslation as ce } from "react-i18next";
5
5
  import { u as ue } from "./registry-DvAUVLHh.js";
6
6
  import { R as d } from "./radio-BZQs6_36.js";
7
7
  import { R as S } from "./radio-group-ChIKyeSJ.js";
8
- import { F as k } from "./form-field-Ani72sVY.js";
8
+ import { F as k } from "./form-field-CyHfOVKF.js";
9
9
  import { D as _ } from "./date-picker-CdhXlgVI.js";
10
10
  import { S as me } from "./select-4S-eYZUf.js";
11
11
  import { S as ge } from "./switch-D--x7n6h.js";
@@ -485,4 +485,4 @@ Re.displayName = "GestationalAgeCalculator";
485
485
  export {
486
486
  Re as G
487
487
  };
488
- //# sourceMappingURL=gestational-age-calculator-CTHeJJdb.js.map
488
+ //# sourceMappingURL=gestational-age-calculator-Dr9hdDta.js.map