formanitor 0.0.27 → 0.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var React13 = require('react');
3
+ var React15 = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
+ var lucideReact = require('lucide-react');
5
6
  var clsx = require('clsx');
6
7
  var tailwindMerge = require('tailwind-merge');
7
8
  var LabelPrimitive = require('@radix-ui/react-label');
@@ -10,7 +11,6 @@ var react = require('@tiptap/react');
10
11
  var StarterKit = require('@tiptap/starter-kit');
11
12
  var Placeholder = require('@tiptap/extension-placeholder');
12
13
  var Underline = require('@tiptap/extension-underline');
13
- var lucideReact = require('lucide-react');
14
14
  var reactSlot = require('@radix-ui/react-slot');
15
15
  var SeparatorPrimitive = require('@radix-ui/react-separator');
16
16
  var SelectPrimitive = require('@radix-ui/react-select');
@@ -44,7 +44,7 @@ function _interopNamespace(e) {
44
44
  return Object.freeze(n);
45
45
  }
46
46
 
47
- var React13__namespace = /*#__PURE__*/_interopNamespace(React13);
47
+ var React15__namespace = /*#__PURE__*/_interopNamespace(React15);
48
48
  var LabelPrimitive__namespace = /*#__PURE__*/_interopNamespace(LabelPrimitive);
49
49
  var StarterKit__default = /*#__PURE__*/_interopDefault(StarterKit);
50
50
  var Placeholder__default = /*#__PURE__*/_interopDefault(Placeholder);
@@ -286,6 +286,9 @@ var FormStore = class {
286
286
  getFieldDef(fieldId) {
287
287
  return this.fieldMap[fieldId];
288
288
  }
289
+ getVoice() {
290
+ return this.config.voice;
291
+ }
289
292
  hasPersistence() {
290
293
  return this.persistence !== NO_OP_PROVIDER;
291
294
  }
@@ -430,6 +433,11 @@ var FormStore = class {
430
433
  result[field.id] = raw?.text ?? null;
431
434
  return;
432
435
  }
436
+ if (field.type === "diagnosis_textarea") {
437
+ const raw = values[field.id];
438
+ result[field.id] = typeof raw === "string" ? raw : raw && typeof raw === "object" ? raw.text ?? null : null;
439
+ return;
440
+ }
433
441
  if (field.type === "ophthal_diagnosis") {
434
442
  const raw = values[field.id];
435
443
  const formatEye = (eyeData, eyeLabel) => {
@@ -633,6 +641,7 @@ var FormStore = class {
633
641
  if (next.onUpload !== void 0) this.config.onUpload = next.onUpload;
634
642
  if (next.onEvent !== void 0) this.config.onEvent = next.onEvent;
635
643
  if (next.onDraftChange !== void 0) this.config.onDraftChange = next.onDraftChange;
644
+ if (next.voice !== void 0) this.config.voice = next.voice;
636
645
  if (next.role !== void 0 && next.role !== this.config.role) {
637
646
  this.config.role = next.role;
638
647
  needsReeval = true;
@@ -694,20 +703,35 @@ var FormStore = class {
694
703
  this.listeners.forEach((l) => l(this.state));
695
704
  }
696
705
  };
697
- var FormContext = React13.createContext(null);
706
+ var VoiceContext = React15.createContext({
707
+ activeFieldId: null,
708
+ setActiveFieldId: () => {
709
+ }
710
+ });
711
+ function useVoiceContext() {
712
+ return React15.useContext(VoiceContext);
713
+ }
714
+ function VoiceContextProvider({ children }) {
715
+ const [activeFieldId, setActiveFieldIdState] = React15.useState(null);
716
+ const setActiveFieldId = React15.useCallback((id) => {
717
+ setActiveFieldIdState(id);
718
+ }, []);
719
+ return /* @__PURE__ */ jsxRuntime.jsx(VoiceContext.Provider, { value: { activeFieldId, setActiveFieldId }, children });
720
+ }
721
+ var FormContext = React15.createContext(null);
698
722
  var emptyFrequentItems = {
699
723
  medications: [],
700
724
  investigations: [],
701
725
  procedures: []
702
726
  };
703
- var FrequentItemsContext = React13.createContext(emptyFrequentItems);
704
- var FieldHandlersContext = React13.createContext({});
727
+ var FrequentItemsContext = React15.createContext(emptyFrequentItems);
728
+ var FieldHandlersContext = React15.createContext({});
705
729
  function useFieldHandlers(fieldId) {
706
- const map = React13.useContext(FieldHandlersContext);
730
+ const map = React15.useContext(FieldHandlersContext);
707
731
  return map[fieldId] ?? { onSearch: async () => [], recentlyUsed: [] };
708
732
  }
709
733
  function useFrequentItems() {
710
- return React13.useContext(FrequentItemsContext);
734
+ return React15.useContext(FrequentItemsContext);
711
735
  }
712
736
  var FormProvider = ({
713
737
  schema,
@@ -716,23 +740,23 @@ var FormProvider = ({
716
740
  frequentItems,
717
741
  children
718
742
  }) => {
719
- const storeRef = React13.useRef(null);
743
+ const storeRef = React15.useRef(null);
720
744
  if (!storeRef.current) {
721
745
  storeRef.current = new FormStore(schema, config);
722
746
  }
723
- React13.useEffect(() => {
747
+ React15.useEffect(() => {
724
748
  if (storeRef.current && config) {
725
749
  storeRef.current.updateConfig(config);
726
750
  }
727
751
  });
728
- React13.useEffect(() => {
752
+ React15.useEffect(() => {
729
753
  storeRef.current?.load();
730
754
  }, []);
731
755
  const frequentItemsValue = frequentItems ?? emptyFrequentItems;
732
- return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxRuntime.jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsxRuntime.jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children }) }) });
756
+ return /* @__PURE__ */ jsxRuntime.jsx(FormContext.Provider, { value: storeRef.current, children: /* @__PURE__ */ jsxRuntime.jsx(FieldHandlersContext.Provider, { value: fieldHandlers ?? {}, children: /* @__PURE__ */ jsxRuntime.jsx(FrequentItemsContext.Provider, { value: frequentItemsValue, children: /* @__PURE__ */ jsxRuntime.jsx(VoiceContextProvider, { children }) }) }) });
733
757
  };
734
758
  function useFormStore() {
735
- const context = React13.useContext(FormContext);
759
+ const context = React15.useContext(FormContext);
736
760
  if (!context) {
737
761
  throw new Error("useFormStore must be used within a FormProvider");
738
762
  }
@@ -740,8 +764,8 @@ function useFormStore() {
740
764
  }
741
765
  function useForm() {
742
766
  const store = useFormStore();
743
- const [state, setState] = React13.useState(store.getState());
744
- React13.useEffect(() => {
767
+ const [state, setState] = React15.useState(store.getState());
768
+ React15.useEffect(() => {
745
769
  const unsubscribe = store.subscribe((newState) => {
746
770
  setState({ ...newState });
747
771
  });
@@ -763,8 +787,8 @@ function useForm() {
763
787
  }
764
788
  function useField(fieldId) {
765
789
  const store = useFormStore();
766
- const [fieldState, setFieldState] = React13.useState(store.getFieldState(fieldId));
767
- React13.useEffect(() => {
790
+ const [fieldState, setFieldState] = React15.useState(store.getFieldState(fieldId));
791
+ React15.useEffect(() => {
768
792
  const unsubscribe = store.subscribe(() => {
769
793
  const newState = store.getFieldState(fieldId);
770
794
  setFieldState((prev) => {
@@ -786,10 +810,76 @@ function useField(fieldId) {
786
810
  setTouched
787
811
  };
788
812
  }
813
+ function RecordingWave() {
814
+ const bars = [
815
+ { dur: "0.6s", values: "3;10;3", yValues: "4.5;0;4.5", delay: "0s" },
816
+ { dur: "0.6s", values: "8;3;8", yValues: "2;4.5;2", delay: "0.1s" },
817
+ { dur: "0.6s", values: "5;11;5", yValues: "3.5;0.5;3.5", delay: "0.05s" },
818
+ { dur: "0.6s", values: "10;4;10", yValues: "1;4;1", delay: "0.15s" }
819
+ ];
820
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "12", viewBox: "0 0 18 12", "aria-hidden": true, children: bars.map((b, i) => /* @__PURE__ */ jsxRuntime.jsxs("rect", { x: i * 4 + 1, width: "2.5", rx: "1.25", fill: "currentColor", y: "0", height: "12", children: [
821
+ /* @__PURE__ */ jsxRuntime.jsx("animate", { attributeName: "height", values: b.values, dur: b.dur, begin: b.delay, repeatCount: "indefinite" }),
822
+ /* @__PURE__ */ jsxRuntime.jsx("animate", { attributeName: "y", values: b.yValues, dur: b.dur, begin: b.delay, repeatCount: "indefinite" })
823
+ ] }, i)) });
824
+ }
825
+ function VoiceMicButton({ fieldId, onTranscriptReady }) {
826
+ const store = useFormStore();
827
+ const { activeFieldId, setActiveFieldId } = useVoiceContext();
828
+ const [status, setStatus] = React15.useState("idle");
829
+ const voice = store.getVoice();
830
+ const isActive = activeFieldId === fieldId;
831
+ const isRecording = status === "recording" && isActive;
832
+ const isTranscribing = status === "transcribing" && isActive;
833
+ const isBlocked = activeFieldId !== null && !isActive;
834
+ const handleClick = React15.useCallback(async () => {
835
+ if (!voice || isBlocked || isTranscribing) return;
836
+ if (isRecording) {
837
+ setStatus("transcribing");
838
+ try {
839
+ const transcript = await voice.stopRecording();
840
+ if (transcript) onTranscriptReady(transcript);
841
+ } catch {
842
+ } finally {
843
+ setStatus("idle");
844
+ setActiveFieldId(null);
845
+ }
846
+ } else {
847
+ setActiveFieldId(fieldId);
848
+ setStatus("recording");
849
+ try {
850
+ await voice.startRecording();
851
+ } catch {
852
+ setStatus("idle");
853
+ setActiveFieldId(null);
854
+ }
855
+ }
856
+ }, [voice, isBlocked, isTranscribing, isRecording, fieldId, onTranscriptReady, setActiveFieldId]);
857
+ const title = isTranscribing ? "Processing\u2026" : isRecording ? "Stop recording" : "Dictate this field";
858
+ return /* @__PURE__ */ jsxRuntime.jsx(
859
+ "button",
860
+ {
861
+ type: "button",
862
+ onClick: handleClick,
863
+ disabled: isBlocked || isTranscribing,
864
+ title,
865
+ className: [
866
+ "flex items-center gap-1 rounded px-1 py-0.5",
867
+ "text-[11px] font-medium transition-opacity",
868
+ isBlocked ? "pointer-events-none opacity-30" : "",
869
+ isTranscribing ? "cursor-wait opacity-50" : "",
870
+ !isBlocked && !isTranscribing ? "hover:opacity-70" : ""
871
+ ].filter(Boolean).join(" "),
872
+ children: isTranscribing ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-3.5 w-3.5 animate-spin text-slate-400" }) : isRecording ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
873
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-rose-400", children: /* @__PURE__ */ jsxRuntime.jsx(RecordingWave, {}) }),
874
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-rose-400", children: "Stop" })
875
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Mic, { className: "h-4 w-4 text-slate-400" })
876
+ }
877
+ );
878
+ }
789
879
  function cn(...inputs) {
790
880
  return tailwindMerge.twMerge(clsx.clsx(inputs));
791
881
  }
792
- var Input = React13__namespace.forwardRef(
882
+ var Input = React15__namespace.forwardRef(
793
883
  ({ className, type, ...props }, ref) => {
794
884
  return /* @__PURE__ */ jsxRuntime.jsx(
795
885
  "input",
@@ -809,7 +899,7 @@ Input.displayName = "Input";
809
899
  var labelVariants = classVarianceAuthority.cva(
810
900
  "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
811
901
  );
812
- var Label = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
902
+ var Label = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
813
903
  LabelPrimitive__namespace.Root,
814
904
  {
815
905
  ref,
@@ -818,7 +908,7 @@ var Label = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @
818
908
  }
819
909
  ));
820
910
  Label.displayName = LabelPrimitive__namespace.Root.displayName;
821
- var Textarea = React13__namespace.forwardRef(
911
+ var Textarea = React15__namespace.forwardRef(
822
912
  ({ className, height, style, ...props }, ref) => {
823
913
  return /* @__PURE__ */ jsxRuntime.jsx(
824
914
  "textarea",
@@ -862,6 +952,8 @@ function getThemeConfig(fieldType, themeName) {
862
952
  var TextWidget = ({ fieldId }) => {
863
953
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
864
954
  const { state } = useForm();
955
+ const store = useFormStore();
956
+ const hasVoice = !!(fieldDef?.voice && store.getVoice());
865
957
  const showError = !!error && (touched || state.submitAttempted);
866
958
  if (!fieldDef) return null;
867
959
  const Component = fieldDef.type === "textarea" ? Textarea : Input;
@@ -879,8 +971,12 @@ var TextWidget = ({ fieldId }) => {
879
971
  " ",
880
972
  fieldDef.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500", children: "*" })
881
973
  ] });
974
+ const labelEl = theme ? /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent });
882
975
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: wrapperClass, children: [
883
- theme ? /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent }),
976
+ hasVoice ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
977
+ labelEl,
978
+ /* @__PURE__ */ jsxRuntime.jsx(VoiceMicButton, { fieldId, onTranscriptReady: setValue })
979
+ ] }) : labelEl,
884
980
  /* @__PURE__ */ jsxRuntime.jsx(
885
981
  Component,
886
982
  {
@@ -922,7 +1018,7 @@ var buttonVariants = classVarianceAuthority.cva(
922
1018
  }
923
1019
  }
924
1020
  );
925
- var Button = React13__namespace.forwardRef(
1021
+ var Button = React15__namespace.forwardRef(
926
1022
  ({ className, variant, size, asChild = false, ...props }, ref) => {
927
1023
  const Comp = asChild ? reactSlot.Slot : "button";
928
1024
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -936,7 +1032,7 @@ var Button = React13__namespace.forwardRef(
936
1032
  }
937
1033
  );
938
1034
  Button.displayName = "Button";
939
- var Separator = React13__namespace.forwardRef(
1035
+ var Separator = React15__namespace.forwardRef(
940
1036
  ({ className, orientation = "horizontal", decorative = true, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
941
1037
  SeparatorPrimitive__namespace.Root,
942
1038
  {
@@ -961,8 +1057,8 @@ function RichTextToolbar({
961
1057
  editor,
962
1058
  disabled
963
1059
  }) {
964
- const [, rerender] = React13.useReducer((n) => n + 1, 0);
965
- React13.useEffect(() => {
1060
+ const [, rerender] = React15.useReducer((n) => n + 1, 0);
1061
+ React15.useEffect(() => {
966
1062
  if (!editor) return;
967
1063
  const handler = () => rerender();
968
1064
  editor.on("selectionUpdate", handler);
@@ -1068,11 +1164,13 @@ function RichTextToolbar({
1068
1164
  var RichTextWidget = ({ fieldId }) => {
1069
1165
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
1070
1166
  const { state } = useForm();
1167
+ const store = useFormStore();
1168
+ const hasVoice = !!(fieldDef?.voice && store.getVoice());
1071
1169
  const showError = !!error && (touched || state.submitAttempted);
1072
1170
  const def = fieldDef;
1073
1171
  const placeholder = def?.placeholder ?? "Start typing\u2026";
1074
1172
  const minHeight = def?.minHeight ?? 160;
1075
- const extensions = React13.useMemo(
1173
+ const extensions = React15.useMemo(
1076
1174
  () => [
1077
1175
  StarterKit__default.default.configure({
1078
1176
  // Disable headings entirely so the UI/content can't introduce H2/H3.
@@ -1122,16 +1220,16 @@ var RichTextWidget = ({ fieldId }) => {
1122
1220
  },
1123
1221
  [extensions, fieldId]
1124
1222
  );
1125
- React13.useEffect(() => {
1223
+ React15.useEffect(() => {
1126
1224
  if (!editor || editor.isDestroyed) return;
1127
1225
  editor.setEditable(!disabled);
1128
1226
  }, [editor, disabled]);
1129
- React13.useEffect(() => {
1227
+ React15.useEffect(() => {
1130
1228
  if (!editor || editor.isDestroyed) return;
1131
1229
  const el = editor.view.dom;
1132
1230
  el.style.minHeight = `${minHeight}px`;
1133
1231
  }, [editor, minHeight]);
1134
- React13.useEffect(() => {
1232
+ React15.useEffect(() => {
1135
1233
  if (!editor || editor.isDestroyed) return;
1136
1234
  const fromForm = stringValue;
1137
1235
  const fromEditor = editor.getHTML();
@@ -1149,8 +1247,12 @@ var RichTextWidget = ({ fieldId }) => {
1149
1247
  " ",
1150
1248
  fieldDef.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500", children: "*" })
1151
1249
  ] });
1250
+ const labelEl = /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent });
1152
1251
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
1153
- /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent }),
1252
+ hasVoice ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between", children: [
1253
+ labelEl,
1254
+ /* @__PURE__ */ jsxRuntime.jsx(VoiceMicButton, { fieldId, onTranscriptReady: setValue })
1255
+ ] }) : labelEl,
1154
1256
  /* @__PURE__ */ jsxRuntime.jsxs(
1155
1257
  "div",
1156
1258
  {
@@ -1188,7 +1290,7 @@ var RichTextWidget = ({ fieldId }) => {
1188
1290
  };
1189
1291
  var Select = SelectPrimitive__namespace.Root;
1190
1292
  var SelectValue = SelectPrimitive__namespace.Value;
1191
- var SelectTrigger = React13__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
1293
+ var SelectTrigger = React15__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
1192
1294
  SelectPrimitive__namespace.Trigger,
1193
1295
  {
1194
1296
  ref,
@@ -1204,7 +1306,7 @@ var SelectTrigger = React13__namespace.forwardRef(({ className, children, ...pro
1204
1306
  }
1205
1307
  ));
1206
1308
  SelectTrigger.displayName = SelectPrimitive__namespace.Trigger.displayName;
1207
- var SelectScrollUpButton = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1309
+ var SelectScrollUpButton = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1208
1310
  SelectPrimitive__namespace.ScrollUpButton,
1209
1311
  {
1210
1312
  ref,
@@ -1217,7 +1319,7 @@ var SelectScrollUpButton = React13__namespace.forwardRef(({ className, ...props
1217
1319
  }
1218
1320
  ));
1219
1321
  SelectScrollUpButton.displayName = SelectPrimitive__namespace.ScrollUpButton.displayName;
1220
- var SelectScrollDownButton = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1322
+ var SelectScrollDownButton = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1221
1323
  SelectPrimitive__namespace.ScrollDownButton,
1222
1324
  {
1223
1325
  ref,
@@ -1230,7 +1332,7 @@ var SelectScrollDownButton = React13__namespace.forwardRef(({ className, ...prop
1230
1332
  }
1231
1333
  ));
1232
1334
  SelectScrollDownButton.displayName = SelectPrimitive__namespace.ScrollDownButton.displayName;
1233
- var SelectContent = React13__namespace.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
1335
+ var SelectContent = React15__namespace.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
1234
1336
  SelectPrimitive__namespace.Content,
1235
1337
  {
1236
1338
  ref,
@@ -1258,7 +1360,7 @@ var SelectContent = React13__namespace.forwardRef(({ className, children, positi
1258
1360
  }
1259
1361
  ) }));
1260
1362
  SelectContent.displayName = SelectPrimitive__namespace.Content.displayName;
1261
- var SelectLabel = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1363
+ var SelectLabel = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1262
1364
  SelectPrimitive__namespace.Label,
1263
1365
  {
1264
1366
  ref,
@@ -1267,7 +1369,7 @@ var SelectLabel = React13__namespace.forwardRef(({ className, ...props }, ref) =
1267
1369
  }
1268
1370
  ));
1269
1371
  SelectLabel.displayName = SelectPrimitive__namespace.Label.displayName;
1270
- var SelectItem = React13__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
1372
+ var SelectItem = React15__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
1271
1373
  SelectPrimitive__namespace.Item,
1272
1374
  {
1273
1375
  ref,
@@ -1283,7 +1385,7 @@ var SelectItem = React13__namespace.forwardRef(({ className, children, ...props
1283
1385
  }
1284
1386
  ));
1285
1387
  SelectItem.displayName = SelectPrimitive__namespace.Item.displayName;
1286
- var SelectSeparator = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1388
+ var SelectSeparator = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1287
1389
  SelectPrimitive__namespace.Separator,
1288
1390
  {
1289
1391
  ref,
@@ -1330,11 +1432,11 @@ async function fetchOptions(source, params) {
1330
1432
  }
1331
1433
  var SelectWidget = ({ fieldId }) => {
1332
1434
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
1333
- const [options, setOptions] = React13.useState([]);
1334
- const [loading, setLoading] = React13.useState(false);
1435
+ const [options, setOptions] = React15.useState([]);
1436
+ const [loading, setLoading] = React15.useState(false);
1335
1437
  const { state } = useForm();
1336
1438
  const showError = !!error && (touched || state.submitAttempted);
1337
- React13.useEffect(() => {
1439
+ React15.useEffect(() => {
1338
1440
  if (!fieldDef) return;
1339
1441
  const def = fieldDef;
1340
1442
  if (def.options) {
@@ -1372,7 +1474,7 @@ var SelectWidget = ({ fieldId }) => {
1372
1474
  showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
1373
1475
  ] });
1374
1476
  };
1375
- var Checkbox = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1477
+ var Checkbox = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1376
1478
  CheckboxPrimitive__namespace.Root,
1377
1479
  {
1378
1480
  ref,
@@ -1393,12 +1495,12 @@ var Checkbox = React13__namespace.forwardRef(({ className, ...props }, ref) => /
1393
1495
  Checkbox.displayName = CheckboxPrimitive__namespace.Root.displayName;
1394
1496
  var MultiSelectWidget = ({ fieldId }) => {
1395
1497
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
1396
- const [options, setOptions] = React13.useState([]);
1397
- const [loading, setLoading] = React13.useState(false);
1498
+ const [options, setOptions] = React15.useState([]);
1499
+ const [loading, setLoading] = React15.useState(false);
1398
1500
  const { state } = useForm();
1399
1501
  const showError = !!error && (touched || state.submitAttempted);
1400
1502
  const currentValues = Array.isArray(value) ? value : [];
1401
- React13.useEffect(() => {
1503
+ React15.useEffect(() => {
1402
1504
  if (!fieldDef) return;
1403
1505
  const def = fieldDef;
1404
1506
  if (def.options) {
@@ -1446,7 +1548,7 @@ var MultiSelectWidget = ({ fieldId }) => {
1446
1548
  showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
1447
1549
  ] });
1448
1550
  };
1449
- var Table = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative w-full overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
1551
+ var Table = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "relative w-full overflow-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
1450
1552
  "table",
1451
1553
  {
1452
1554
  ref,
@@ -1455,9 +1557,9 @@ var Table = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @
1455
1557
  }
1456
1558
  ) }));
1457
1559
  Table.displayName = "Table";
1458
- var TableHeader = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
1560
+ var TableHeader = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
1459
1561
  TableHeader.displayName = "TableHeader";
1460
- var TableBody = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1562
+ var TableBody = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1461
1563
  "tbody",
1462
1564
  {
1463
1565
  ref,
@@ -1466,7 +1568,7 @@ var TableBody = React13__namespace.forwardRef(({ className, ...props }, ref) =>
1466
1568
  }
1467
1569
  ));
1468
1570
  TableBody.displayName = "TableBody";
1469
- var TableFooter = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1571
+ var TableFooter = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1470
1572
  "tfoot",
1471
1573
  {
1472
1574
  ref,
@@ -1478,7 +1580,7 @@ var TableFooter = React13__namespace.forwardRef(({ className, ...props }, ref) =
1478
1580
  }
1479
1581
  ));
1480
1582
  TableFooter.displayName = "TableFooter";
1481
- var TableRow = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1583
+ var TableRow = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1482
1584
  "tr",
1483
1585
  {
1484
1586
  ref,
@@ -1490,7 +1592,7 @@ var TableRow = React13__namespace.forwardRef(({ className, ...props }, ref) => /
1490
1592
  }
1491
1593
  ));
1492
1594
  TableRow.displayName = "TableRow";
1493
- var TableHead = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1595
+ var TableHead = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1494
1596
  "th",
1495
1597
  {
1496
1598
  ref,
@@ -1502,7 +1604,7 @@ var TableHead = React13__namespace.forwardRef(({ className, ...props }, ref) =>
1502
1604
  }
1503
1605
  ));
1504
1606
  TableHead.displayName = "TableHead";
1505
- var TableCell = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1607
+ var TableCell = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1506
1608
  "td",
1507
1609
  {
1508
1610
  ref,
@@ -1511,7 +1613,7 @@ var TableCell = React13__namespace.forwardRef(({ className, ...props }, ref) =>
1511
1613
  }
1512
1614
  ));
1513
1615
  TableCell.displayName = "TableCell";
1514
- var TableCaption = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1616
+ var TableCaption = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
1515
1617
  "caption",
1516
1618
  {
1517
1619
  ref,
@@ -1527,7 +1629,7 @@ var RepeatableWidget = ({
1527
1629
  if (!fieldDef || fieldDef.type !== "repeatable") return null;
1528
1630
  const def = fieldDef;
1529
1631
  const rows = Array.isArray(value) ? value : [];
1530
- const [hasInteracted, setHasInteracted] = React13__namespace.default.useState(false);
1632
+ const [hasInteracted, setHasInteracted] = React15__namespace.default.useState(false);
1531
1633
  const showError = !!error && (touched || hasInteracted);
1532
1634
  const addRow = () => {
1533
1635
  setValue([...rows, {}]);
@@ -1696,7 +1798,7 @@ function Calendar({
1696
1798
  Calendar.displayName = "Calendar";
1697
1799
  var Popover = PopoverPrimitive__namespace.Root;
1698
1800
  var PopoverTrigger = PopoverPrimitive__namespace.Trigger;
1699
- var PopoverContent = React13__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
1801
+ var PopoverContent = React15__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
1700
1802
  PopoverPrimitive__namespace.Content,
1701
1803
  {
1702
1804
  ref,
@@ -1775,14 +1877,14 @@ function DateTimePicker({
1775
1877
  className,
1776
1878
  placeholder = "Pick date & time"
1777
1879
  }) {
1778
- const [internalDate, setInternalDate] = React13__namespace.useState(dateTime);
1779
- const [timeString, setTimeString] = React13__namespace.useState(() => {
1880
+ const [internalDate, setInternalDate] = React15__namespace.useState(dateTime);
1881
+ const [timeString, setTimeString] = React15__namespace.useState(() => {
1780
1882
  if (!dateTime) return "";
1781
1883
  const hours = dateTime.getHours().toString().padStart(2, "0");
1782
1884
  const minutes = dateTime.getMinutes().toString().padStart(2, "0");
1783
1885
  return `${hours}:${minutes}`;
1784
1886
  });
1785
- React13__namespace.useEffect(() => {
1887
+ React15__namespace.useEffect(() => {
1786
1888
  setInternalDate(dateTime);
1787
1889
  if (!dateTime) {
1788
1890
  setTimeString("");
@@ -1911,9 +2013,9 @@ var ImageUploadWidget = ({ fieldId }) => {
1911
2013
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
1912
2014
  const store = useFormStore();
1913
2015
  const { state } = useForm();
1914
- const [isUploading, setIsUploading] = React13.useState(false);
1915
- const [preview, setPreview] = React13.useState(null);
1916
- const fileInputRef = React13.useRef(null);
2016
+ const [isUploading, setIsUploading] = React15.useState(false);
2017
+ const [preview, setPreview] = React15.useState(null);
2018
+ const fileInputRef = React15.useRef(null);
1917
2019
  const showError = !!error && (touched || state.submitAttempted);
1918
2020
  if (!fieldDef) return null;
1919
2021
  const uploadHandler = store.getUploadHandler();
@@ -1926,7 +2028,7 @@ var ImageUploadWidget = ({ fieldId }) => {
1926
2028
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-2 border-red-300 rounded-lg p-4 bg-red-50", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-red-600", children: "Upload handler not configured. Please provide an onUpload function in FormProvider config." }) })
1927
2029
  ] });
1928
2030
  }
1929
- React13__namespace.default.useEffect(() => {
2031
+ React15__namespace.default.useEffect(() => {
1930
2032
  if (value && typeof value === "string") {
1931
2033
  setPreview(value);
1932
2034
  } else {
@@ -2051,18 +2153,18 @@ var SignatureUploadWidget = ({ fieldId }) => {
2051
2153
  const { fieldDef, setValue, setTouched, error, disabled, touched, value } = useField(fieldId);
2052
2154
  const store = useFormStore();
2053
2155
  const { state } = useForm();
2054
- const canvasRef = React13.useRef(null);
2055
- const pathRef = React13.useRef("");
2056
- const lastPointRef = React13.useRef(null);
2057
- const lastTimeRef = React13.useRef(null);
2058
- const lastWidthRef = React13.useRef(2);
2059
- const [isDrawing, setIsDrawing] = React13.useState(false);
2060
- const [hasDrawing, setHasDrawing] = React13.useState(false);
2061
- const [isUploading, setIsUploading] = React13.useState(false);
2062
- const [isConfirmed, setIsConfirmed] = React13.useState(false);
2063
- const [uploadError, setUploadError] = React13.useState(null);
2064
- const confirmSignatureRef = React13.useRef(null);
2065
- React13.useEffect(() => {
2156
+ const canvasRef = React15.useRef(null);
2157
+ const pathRef = React15.useRef("");
2158
+ const lastPointRef = React15.useRef(null);
2159
+ const lastTimeRef = React15.useRef(null);
2160
+ const lastWidthRef = React15.useRef(2);
2161
+ const [isDrawing, setIsDrawing] = React15.useState(false);
2162
+ const [hasDrawing, setHasDrawing] = React15.useState(false);
2163
+ const [isUploading, setIsUploading] = React15.useState(false);
2164
+ const [isConfirmed, setIsConfirmed] = React15.useState(false);
2165
+ const [uploadError, setUploadError] = React15.useState(null);
2166
+ const confirmSignatureRef = React15.useRef(null);
2167
+ React15.useEffect(() => {
2066
2168
  if (hasDrawing && !isConfirmed) {
2067
2169
  store.registerPreSubmitHandler(fieldId, async () => {
2068
2170
  if (confirmSignatureRef.current) {
@@ -2077,9 +2179,9 @@ var SignatureUploadWidget = ({ fieldId }) => {
2077
2179
  };
2078
2180
  }, [hasDrawing, isConfirmed, fieldId, store]);
2079
2181
  const showError = !!error && (touched || state.submitAttempted);
2080
- const displayUrl = React13.useMemo(() => extractDisplayUrl(value), [value]);
2182
+ const displayUrl = React15.useMemo(() => extractDisplayUrl(value), [value]);
2081
2183
  const showPreview = displayUrl !== null;
2082
- React13.useEffect(() => {
2184
+ React15.useEffect(() => {
2083
2185
  if (showPreview) return;
2084
2186
  const canvas = canvasRef.current;
2085
2187
  if (!canvas) return;
@@ -2319,7 +2421,7 @@ var EditableTableWidget = ({
2319
2421
  const addColumnLabel = def?.addColumnLabel ?? "Add Column";
2320
2422
  const newColumnNameHint = def?.newColumnNameHint ?? "New Column Name";
2321
2423
  const newColumnNameInputType = def?.newColumnNameInputType ?? "text";
2322
- const tableData = React13.useMemo(() => {
2424
+ const tableData = React15.useMemo(() => {
2323
2425
  if (value && typeof value === "object" && "columns" in value && "rows" in value) {
2324
2426
  return value;
2325
2427
  }
@@ -2334,12 +2436,12 @@ var EditableTableWidget = ({
2334
2436
  rows: []
2335
2437
  };
2336
2438
  }, [value, fieldDef]);
2337
- const dataRef = React13.useRef(tableData);
2338
- React13.useEffect(() => {
2439
+ const dataRef = React15.useRef(tableData);
2440
+ React15.useEffect(() => {
2339
2441
  dataRef.current = tableData;
2340
2442
  }, [tableData]);
2341
- const [newColumnName, setNewColumnName] = React13.useState("");
2342
- const [newColumnDate, setNewColumnDate] = React13.useState(void 0);
2443
+ const [newColumnName, setNewColumnName] = React15.useState("");
2444
+ const [newColumnDate, setNewColumnDate] = React15.useState(void 0);
2343
2445
  const updateData = (newData) => {
2344
2446
  setValue(newData);
2345
2447
  };
@@ -2407,7 +2509,7 @@ var EditableTableWidget = ({
2407
2509
  newRows[rowIndex] = { ...newRows[rowIndex], [colId]: val };
2408
2510
  updateData({ ...currentData, rows: newRows });
2409
2511
  };
2410
- const columns = React13.useMemo(() => {
2512
+ const columns = React15.useMemo(() => {
2411
2513
  const currentCols = tableData.columns;
2412
2514
  const dataCols = currentCols.map((col) => {
2413
2515
  const showColumnDelete = !disabled && canDeleteColumn && col.allowDelete !== false;
@@ -2565,7 +2667,7 @@ var EditableTableWidget = ({
2565
2667
  ] })
2566
2668
  ] });
2567
2669
  };
2568
- var RadioGroup = React13__namespace.forwardRef(({ className, ...props }, ref) => {
2670
+ var RadioGroup = React15__namespace.forwardRef(({ className, ...props }, ref) => {
2569
2671
  return /* @__PURE__ */ jsxRuntime.jsx(
2570
2672
  RadioGroupPrimitive__namespace.Root,
2571
2673
  {
@@ -2576,7 +2678,7 @@ var RadioGroup = React13__namespace.forwardRef(({ className, ...props }, ref) =>
2576
2678
  );
2577
2679
  });
2578
2680
  RadioGroup.displayName = RadioGroupPrimitive__namespace.Root.displayName;
2579
- var RadioGroupItem = React13__namespace.forwardRef(({ className, ...props }, ref) => {
2681
+ var RadioGroupItem = React15__namespace.forwardRef(({ className, ...props }, ref) => {
2580
2682
  return /* @__PURE__ */ jsxRuntime.jsx(
2581
2683
  RadioGroupPrimitive__namespace.Item,
2582
2684
  {
@@ -2593,11 +2695,11 @@ var RadioGroupItem = React13__namespace.forwardRef(({ className, ...props }, ref
2593
2695
  RadioGroupItem.displayName = RadioGroupPrimitive__namespace.Item.displayName;
2594
2696
  var RadioWidget = ({ fieldId }) => {
2595
2697
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
2596
- const [options, setOptions] = React13.useState([]);
2597
- const [loading, setLoading] = React13.useState(false);
2698
+ const [options, setOptions] = React15.useState([]);
2699
+ const [loading, setLoading] = React15.useState(false);
2598
2700
  const { state } = useForm();
2599
2701
  const showError = !!error && (touched || state.submitAttempted);
2600
- React13.useEffect(() => {
2702
+ React15.useEffect(() => {
2601
2703
  if (!fieldDef) return;
2602
2704
  const def = fieldDef;
2603
2705
  if (def.options?.length) {
@@ -2656,12 +2758,12 @@ function isOptionSelected(selected, optValue) {
2656
2758
  }
2657
2759
  var CheckboxWidget = ({ fieldId }) => {
2658
2760
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
2659
- const [options, setOptions] = React13.useState([]);
2660
- const [loading, setLoading] = React13.useState(false);
2761
+ const [options, setOptions] = React15.useState([]);
2762
+ const [loading, setLoading] = React15.useState(false);
2661
2763
  const { state } = useForm();
2662
2764
  const showError = !!error && (touched || state.submitAttempted);
2663
2765
  const selectedValues = Array.isArray(value) ? value : [];
2664
- React13.useEffect(() => {
2766
+ React15.useEffect(() => {
2665
2767
  if (!fieldDef) return;
2666
2768
  const def = fieldDef;
2667
2769
  if (def.options?.length) {
@@ -2716,14 +2818,14 @@ var CheckboxWidget = ({ fieldId }) => {
2716
2818
  showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
2717
2819
  ] });
2718
2820
  };
2719
- var AISuggestionsContext = React13.createContext({});
2821
+ var AISuggestionsContext = React15.createContext({});
2720
2822
  function useAISuggestions() {
2721
- return React13.useContext(AISuggestionsContext);
2823
+ return React15.useContext(AISuggestionsContext);
2722
2824
  }
2723
2825
  var AISuggestionsProvider = AISuggestionsContext.Provider;
2724
2826
  var Dialog = DialogPrimitive__namespace.Root;
2725
2827
  var DialogPortal = DialogPrimitive__namespace.Portal;
2726
- var DialogOverlay = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2828
+ var DialogOverlay = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2727
2829
  DialogPrimitive__namespace.Overlay,
2728
2830
  {
2729
2831
  ref,
@@ -2735,7 +2837,7 @@ var DialogOverlay = React13__namespace.forwardRef(({ className, ...props }, ref)
2735
2837
  }
2736
2838
  ));
2737
2839
  DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
2738
- var DialogContent = React13__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
2840
+ var DialogContent = React15__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
2739
2841
  /* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
2740
2842
  /* @__PURE__ */ jsxRuntime.jsxs(
2741
2843
  DialogPrimitive__namespace.Content,
@@ -2771,7 +2873,7 @@ var DialogHeader = ({
2771
2873
  }
2772
2874
  );
2773
2875
  DialogHeader.displayName = "DialogHeader";
2774
- var DialogTitle = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2876
+ var DialogTitle = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2775
2877
  DialogPrimitive__namespace.Title,
2776
2878
  {
2777
2879
  ref,
@@ -2783,7 +2885,7 @@ var DialogTitle = React13__namespace.forwardRef(({ className, ...props }, ref) =
2783
2885
  }
2784
2886
  ));
2785
2887
  DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
2786
- var DialogDescription = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2888
+ var DialogDescription = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
2787
2889
  DialogPrimitive__namespace.Description,
2788
2890
  {
2789
2891
  ref,
@@ -2950,7 +3052,7 @@ function MedicationCard({
2950
3052
  onUpdate,
2951
3053
  onRemove
2952
3054
  }) {
2953
- const [notesOpen, setNotesOpen] = React13.useState(false);
3055
+ const [notesOpen, setNotesOpen] = React15.useState(false);
2954
3056
  function set(key, val) {
2955
3057
  onUpdate({ ...med, [key]: val });
2956
3058
  }
@@ -3111,19 +3213,19 @@ var AddMedicationField = ({
3111
3213
  frequentItems = [],
3112
3214
  suggestedMedications = []
3113
3215
  }) => {
3114
- const [open, setOpen] = React13.useState(false);
3115
- const [query, setQuery] = React13.useState("");
3116
- const [results, setResults] = React13.useState([]);
3117
- const [loading, setLoading] = React13.useState(false);
3118
- const [addingResultId, setAddingResultId] = React13.useState(null);
3119
- const debounceRef = React13.useRef(null);
3120
- const customIdRef = React13.useRef(-1);
3121
- const valueRef = React13.useRef([]);
3122
- const searchInputRef = React13.useRef(null);
3216
+ const [open, setOpen] = React15.useState(false);
3217
+ const [query, setQuery] = React15.useState("");
3218
+ const [results, setResults] = React15.useState([]);
3219
+ const [loading, setLoading] = React15.useState(false);
3220
+ const [addingResultId, setAddingResultId] = React15.useState(null);
3221
+ const debounceRef = React15.useRef(null);
3222
+ const customIdRef = React15.useRef(-1);
3223
+ const valueRef = React15.useRef([]);
3224
+ const searchInputRef = React15.useRef(null);
3123
3225
  const safeValue = Array.isArray(value) ? value : [];
3124
3226
  valueRef.current = safeValue;
3125
3227
  const addedIds = new Set(safeValue.map((m) => String(m.id)));
3126
- React13.useEffect(() => {
3228
+ React15.useEffect(() => {
3127
3229
  if (!open) {
3128
3230
  setQuery("");
3129
3231
  setResults([]);
@@ -3351,19 +3453,19 @@ var AddInvestigationField = ({
3351
3453
  recentlyUsed = [],
3352
3454
  frequentItems = []
3353
3455
  }) => {
3354
- const [open, setOpen] = React13.useState(false);
3355
- const [query, setQuery] = React13.useState("");
3356
- const [results, setResults] = React13.useState([]);
3357
- const [loading, setLoading] = React13.useState(false);
3358
- const [addingId, setAddingId] = React13.useState(null);
3359
- const [addingFrequentId, setAddingFrequentId] = React13.useState(null);
3360
- const debounceRef = React13.useRef(null);
3361
- const valueRef = React13.useRef([]);
3362
- const searchInputRef = React13.useRef(null);
3456
+ const [open, setOpen] = React15.useState(false);
3457
+ const [query, setQuery] = React15.useState("");
3458
+ const [results, setResults] = React15.useState([]);
3459
+ const [loading, setLoading] = React15.useState(false);
3460
+ const [addingId, setAddingId] = React15.useState(null);
3461
+ const [addingFrequentId, setAddingFrequentId] = React15.useState(null);
3462
+ const debounceRef = React15.useRef(null);
3463
+ const valueRef = React15.useRef([]);
3464
+ const searchInputRef = React15.useRef(null);
3363
3465
  const safeValue = Array.isArray(value) ? value : [];
3364
3466
  valueRef.current = safeValue;
3365
3467
  const addedIds = new Set(safeValue.map((inv) => inv.id));
3366
- React13.useEffect(() => {
3468
+ React15.useEffect(() => {
3367
3469
  if (!open) {
3368
3470
  setQuery("");
3369
3471
  setResults([]);
@@ -3589,21 +3691,21 @@ var AddProcedureField = ({
3589
3691
  recentlyUsed = [],
3590
3692
  frequentItems = []
3591
3693
  }) => {
3592
- const [open, setOpen] = React13.useState(false);
3593
- const [query, setQuery] = React13.useState("");
3594
- const [results, setResults] = React13.useState([]);
3595
- const [loading, setLoading] = React13.useState(false);
3596
- const [addingId, setAddingId] = React13.useState(null);
3597
- const [addingFrequentId, setAddingFrequentId] = React13.useState(null);
3598
- const debounceRef = React13.useRef(null);
3599
- const valueRef = React13.useRef([]);
3600
- const searchInputRef = React13.useRef(null);
3694
+ const [open, setOpen] = React15.useState(false);
3695
+ const [query, setQuery] = React15.useState("");
3696
+ const [results, setResults] = React15.useState([]);
3697
+ const [loading, setLoading] = React15.useState(false);
3698
+ const [addingId, setAddingId] = React15.useState(null);
3699
+ const [addingFrequentId, setAddingFrequentId] = React15.useState(null);
3700
+ const debounceRef = React15.useRef(null);
3701
+ const valueRef = React15.useRef([]);
3702
+ const searchInputRef = React15.useRef(null);
3601
3703
  const safeValue = Array.isArray(value) ? value : [];
3602
3704
  valueRef.current = safeValue;
3603
3705
  const addedIds = new Set(
3604
3706
  safeValue.filter((proc) => !proc.is_custom).map((proc) => proc.id)
3605
3707
  );
3606
- React13.useEffect(() => {
3708
+ React15.useEffect(() => {
3607
3709
  if (!open) {
3608
3710
  setQuery("");
3609
3711
  setResults([]);
@@ -3846,7 +3948,7 @@ function getStatusBasedClass(status) {
3846
3948
  }
3847
3949
  }
3848
3950
  function DiagnosisCard({ item, defaultOpen = false }) {
3849
- const [open, setOpen] = React13.useState(defaultOpen);
3951
+ const [open, setOpen] = React15.useState(defaultOpen);
3850
3952
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border border-gray-200 rounded-lg bg-[#F2F2F2] mb-2 last:mb-0 overflow-hidden", children: [
3851
3953
  /* @__PURE__ */ jsxRuntime.jsxs(
3852
3954
  "button",
@@ -3931,7 +4033,7 @@ var DifferentialDiagnosisWidget = ({ fieldId }) => {
3931
4033
  const items = Array.isArray(value) ? value : [];
3932
4034
  return /* @__PURE__ */ jsxRuntime.jsx(DifferentialDiagnosis, { differentialDiagnosis: items });
3933
4035
  };
3934
- var Spinner2 = React13__namespace.forwardRef(
4036
+ var Spinner2 = React15__namespace.forwardRef(
3935
4037
  ({ className, size = "md", ...props }, ref) => {
3936
4038
  const sizeClasses = {
3937
4039
  sm: "h-4 w-4 border-2",
@@ -4076,10 +4178,10 @@ var Vitals = ({
4076
4178
  var VitalsWidget = ({ fieldId }) => {
4077
4179
  const { value, setValue, fieldDef } = useField(fieldId);
4078
4180
  const handlers = useFieldHandlers(fieldId);
4079
- const [loading, setLoading] = React13.useState(false);
4080
- const [error, setError] = React13.useState(null);
4181
+ const [loading, setLoading] = React15.useState(false);
4182
+ const [error, setError] = React15.useState(null);
4081
4183
  console.log("[VitalsWidget] fieldId:", fieldId, "| onFetch present:", !!handlers.onFetch, "| value:", value);
4082
- const fetchVitals = React13.useCallback(async () => {
4184
+ const fetchVitals = React15.useCallback(async () => {
4083
4185
  if (!handlers.onFetch) return;
4084
4186
  setLoading(true);
4085
4187
  setError(null);
@@ -4093,7 +4195,7 @@ var VitalsWidget = ({ fieldId }) => {
4093
4195
  setLoading(false);
4094
4196
  }
4095
4197
  }, [handlers, setValue]);
4096
- React13.useEffect(() => {
4198
+ React15.useEffect(() => {
4097
4199
  fetchVitals();
4098
4200
  }, []);
4099
4201
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -4162,15 +4264,15 @@ function normalizeValue(value) {
4162
4264
  var ReferralWidget = ({ fieldId }) => {
4163
4265
  const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
4164
4266
  const handlers = useFieldHandlers(fieldId);
4165
- const [options, setOptions] = React13.useState([]);
4166
- const [loading, setLoading] = React13.useState(false);
4267
+ const [options, setOptions] = React15.useState([]);
4268
+ const [loading, setLoading] = React15.useState(false);
4167
4269
  const { state } = useForm();
4168
4270
  const showError = !!error && (touched || state.submitAttempted);
4169
4271
  const selectedItems = normalizeValue(value);
4170
4272
  const availableOptions = options.filter(
4171
4273
  (opt) => !selectedItems.some((item) => item.specialization === opt.value)
4172
4274
  );
4173
- const loadOptions = React13.useCallback(async () => {
4275
+ const loadOptions = React15.useCallback(async () => {
4174
4276
  if (handlers.onFetchOptions) {
4175
4277
  setLoading(true);
4176
4278
  try {
@@ -4191,11 +4293,11 @@ var ReferralWidget = ({ fieldId }) => {
4191
4293
  setOptions([]);
4192
4294
  }
4193
4295
  }, [fieldDef, handlers]);
4194
- React13.useEffect(() => {
4296
+ React15.useEffect(() => {
4195
4297
  if (!fieldDef) return;
4196
4298
  loadOptions();
4197
4299
  }, [fieldDef, loadOptions]);
4198
- const handleAdd = React13.useCallback(
4300
+ const handleAdd = React15.useCallback(
4199
4301
  (specialization) => {
4200
4302
  const next = [...selectedItems, { specialization, is_urgent: false }];
4201
4303
  setValue(next);
@@ -4203,7 +4305,7 @@ var ReferralWidget = ({ fieldId }) => {
4203
4305
  },
4204
4306
  [selectedItems, setValue, setTouched]
4205
4307
  );
4206
- const handleRemove = React13.useCallback(
4308
+ const handleRemove = React15.useCallback(
4207
4309
  (specialization) => {
4208
4310
  const next = selectedItems.filter((item) => item.specialization !== specialization);
4209
4311
  setValue(next);
@@ -4211,7 +4313,7 @@ var ReferralWidget = ({ fieldId }) => {
4211
4313
  },
4212
4314
  [selectedItems, setValue, setTouched]
4213
4315
  );
4214
- const handleToggleUrgent = React13.useCallback(
4316
+ const handleToggleUrgent = React15.useCallback(
4215
4317
  (specialization) => {
4216
4318
  const next = selectedItems.map(
4217
4319
  (item) => item.specialization === specialization ? { ...item, is_urgent: !item.is_urgent } : item
@@ -4287,7 +4389,7 @@ var ReferralWidget = ({ fieldId }) => {
4287
4389
  showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
4288
4390
  ] });
4289
4391
  };
4290
- var Card = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4392
+ var Card = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4291
4393
  "div",
4292
4394
  {
4293
4395
  ref,
@@ -4299,7 +4401,7 @@ var Card = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @_
4299
4401
  }
4300
4402
  ));
4301
4403
  Card.displayName = "Card";
4302
- var CardHeader = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4404
+ var CardHeader = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4303
4405
  "div",
4304
4406
  {
4305
4407
  ref,
@@ -4308,7 +4410,7 @@ var CardHeader = React13__namespace.forwardRef(({ className, ...props }, ref) =>
4308
4410
  }
4309
4411
  ));
4310
4412
  CardHeader.displayName = "CardHeader";
4311
- var CardTitle = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4413
+ var CardTitle = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4312
4414
  "h3",
4313
4415
  {
4314
4416
  ref,
@@ -4320,7 +4422,7 @@ var CardTitle = React13__namespace.forwardRef(({ className, ...props }, ref) =>
4320
4422
  }
4321
4423
  ));
4322
4424
  CardTitle.displayName = "CardTitle";
4323
- var CardDescription = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4425
+ var CardDescription = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4324
4426
  "p",
4325
4427
  {
4326
4428
  ref,
@@ -4329,9 +4431,9 @@ var CardDescription = React13__namespace.forwardRef(({ className, ...props }, re
4329
4431
  }
4330
4432
  ));
4331
4433
  CardDescription.displayName = "CardDescription";
4332
- var CardContent = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("p-6 pt-0", className), ...props }));
4434
+ var CardContent = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("div", { ref, className: cn("p-6 pt-0", className), ...props }));
4333
4435
  CardContent.displayName = "CardContent";
4334
- var CardFooter = React13__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4436
+ var CardFooter = React15__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4335
4437
  "div",
4336
4438
  {
4337
4439
  ref,
@@ -4417,11 +4519,11 @@ function parseLocalDate(dateString) {
4417
4519
  var FollowupWidget = ({ fieldId }) => {
4418
4520
  const { fieldDef, value, setValue, setTouched, error, disabled, visible } = useField(fieldId);
4419
4521
  const followup = normalizeFollowup(value);
4420
- const [calendarOpen, setCalendarOpen] = React13.useState(false);
4522
+ const [calendarOpen, setCalendarOpen] = React15.useState(false);
4421
4523
  const currentFollowupType = followup ? followup.followupType : "no followup";
4422
4524
  const hasFollowup = followup !== false;
4423
- const [displayMode, setDisplayMode] = React13.useState("duration");
4424
- const [displayUnit, setDisplayUnit] = React13.useState("days");
4525
+ const [displayMode, setDisplayMode] = React15.useState("duration");
4526
+ const [displayUnit, setDisplayUnit] = React15.useState("days");
4425
4527
  const daysNum = hasFollowup ? parseInt(followup.value, 10) || 7 : 7;
4426
4528
  const currentDate = hasFollowup ? daysToDate(daysNum) : null;
4427
4529
  const followupMode = displayMode;
@@ -4429,7 +4531,7 @@ var FollowupWidget = ({ fieldId }) => {
4429
4531
  displayUnit === "weeks" ? Math.round(daysNum / 7) || 1 : Math.round(daysNum / 30) || 1
4430
4532
  ) : "7";
4431
4533
  const currentUnit = displayUnit;
4432
- const handleFollowupTypeChange = React13.useCallback(
4534
+ const handleFollowupTypeChange = React15.useCallback(
4433
4535
  (newType) => {
4434
4536
  setTouched();
4435
4537
  if (newType === "no followup") {
@@ -4445,11 +4547,11 @@ var FollowupWidget = ({ fieldId }) => {
4445
4547
  },
4446
4548
  [followup, hasFollowup, setValue, setTouched]
4447
4549
  );
4448
- const handleModeChange = React13.useCallback((newMode) => {
4550
+ const handleModeChange = React15.useCallback((newMode) => {
4449
4551
  setDisplayMode(newMode);
4450
4552
  if (newMode === "date") setCalendarOpen(false);
4451
4553
  }, []);
4452
- const handleValueChange = React13.useCallback(
4554
+ const handleValueChange = React15.useCallback(
4453
4555
  (newValue) => {
4454
4556
  setTouched();
4455
4557
  const num = parseInt(newValue, 10);
@@ -4464,10 +4566,10 @@ var FollowupWidget = ({ fieldId }) => {
4464
4566
  },
4465
4567
  [displayUnit, setValue, setTouched]
4466
4568
  );
4467
- const handleUnitChange = React13.useCallback((newUnit) => {
4569
+ const handleUnitChange = React15.useCallback((newUnit) => {
4468
4570
  setDisplayUnit(newUnit);
4469
4571
  }, []);
4470
- const handleDateSelect = React13.useCallback(
4572
+ const handleDateSelect = React15.useCallback(
4471
4573
  (selected) => {
4472
4574
  setTouched();
4473
4575
  setCalendarOpen(false);
@@ -4600,13 +4702,13 @@ function useSmartKeywords(text, onSearch, debounceDelay = 1e3) {
4600
4702
  hasOnSearch: typeof onSearch === "function",
4601
4703
  debounceDelay
4602
4704
  });
4603
- const [extractedNouns, setExtractedNouns] = React13.useState([]);
4604
- const [matchedConditions, setMatchedConditions] = React13.useState([]);
4605
- const [isProcessing, setIsProcessing] = React13.useState(false);
4606
- const [error, setError] = React13.useState(null);
4607
- const timerRef = React13.useRef(null);
4608
- const abortRef = React13.useRef(0);
4609
- const processText = React13.useCallback(
4705
+ const [extractedNouns, setExtractedNouns] = React15.useState([]);
4706
+ const [matchedConditions, setMatchedConditions] = React15.useState([]);
4707
+ const [isProcessing, setIsProcessing] = React15.useState(false);
4708
+ const [error, setError] = React15.useState(null);
4709
+ const timerRef = React15.useRef(null);
4710
+ const abortRef = React15.useRef(0);
4711
+ const processText = React15.useCallback(
4610
4712
  async (input, runId) => {
4611
4713
  if (!input || input.trim().length === 0) {
4612
4714
  console.log("[useSmartKeywords] skip empty input", {
@@ -4690,7 +4792,7 @@ function useSmartKeywords(text, onSearch, debounceDelay = 1e3) {
4690
4792
  },
4691
4793
  [onSearch]
4692
4794
  );
4693
- React13.useEffect(() => {
4795
+ React15.useEffect(() => {
4694
4796
  if (timerRef.current) clearTimeout(timerRef.current);
4695
4797
  const runId = ++abortRef.current;
4696
4798
  console.log("[useSmartKeywords] schedule debounce", {
@@ -4727,7 +4829,7 @@ var SmartTextareaWidget = ({ fieldId }) => {
4727
4829
  const structured = value;
4728
4830
  const textValue = structured?.text ?? "";
4729
4831
  const showError = !!error && (touched || state.submitAttempted);
4730
- const onSearch = React13.useCallback(
4832
+ const onSearch = React15.useCallback(
4731
4833
  (query) => handler.onSearch(query),
4732
4834
  [handler]
4733
4835
  );
@@ -4737,7 +4839,7 @@ var SmartTextareaWidget = ({ fieldId }) => {
4737
4839
  def?.debounceDelay ?? 1e3
4738
4840
  );
4739
4841
  const currentKeywords = structured?.extractedKeywords ?? [];
4740
- const nextKeywords = React13.useMemo(() => {
4842
+ const nextKeywords = React15.useMemo(() => {
4741
4843
  if (matchedConditions.length === 0 && currentKeywords.length === 0) return currentKeywords;
4742
4844
  if (matchedConditions.length === currentKeywords.length && matchedConditions.every(
4743
4845
  (m, i) => m.matchedCondition.id === currentKeywords[i]?.matchedCondition.id && m.extractedKeyword === currentKeywords[i]?.extractedKeyword
@@ -4746,19 +4848,19 @@ var SmartTextareaWidget = ({ fieldId }) => {
4746
4848
  }
4747
4849
  return matchedConditions;
4748
4850
  }, [matchedConditions, currentKeywords]);
4749
- const writeValue = React13.useCallback(
4851
+ const writeValue = React15.useCallback(
4750
4852
  (text, keywords) => {
4751
4853
  const next = { text, extractedKeywords: keywords };
4752
4854
  setValue(next);
4753
4855
  },
4754
4856
  [setValue]
4755
4857
  );
4756
- React13__namespace.default.useEffect(() => {
4858
+ React15__namespace.default.useEffect(() => {
4757
4859
  if (nextKeywords !== currentKeywords) {
4758
4860
  writeValue(textValue, nextKeywords);
4759
4861
  }
4760
4862
  }, [nextKeywords]);
4761
- const handleTextChange = React13.useCallback(
4863
+ const handleTextChange = React15.useCallback(
4762
4864
  (e) => {
4763
4865
  writeValue(e.target.value, currentKeywords);
4764
4866
  },
@@ -4794,6 +4896,174 @@ var SmartTextareaWidget = ({ fieldId }) => {
4794
4896
  showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
4795
4897
  ] });
4796
4898
  };
4899
+ function normalizeDiagnosisGrades(payload) {
4900
+ const result = [];
4901
+ const pushGroup = (conditionRaw, gradesRaw) => {
4902
+ const condition = typeof conditionRaw === "string" ? conditionRaw.trim() : "";
4903
+ if (!condition) return;
4904
+ if (!Array.isArray(gradesRaw)) return;
4905
+ const grades = Array.from(
4906
+ new Set(
4907
+ gradesRaw.map((grade) => typeof grade === "string" ? grade.trim() : "").filter(Boolean)
4908
+ )
4909
+ );
4910
+ if (grades.length === 0) return;
4911
+ result.push({ condition, grades });
4912
+ };
4913
+ const asArrayResponse = payload;
4914
+ if (Array.isArray(asArrayResponse?.diagnosisGrades)) {
4915
+ asArrayResponse.diagnosisGrades.forEach((item) => {
4916
+ pushGroup(item?.condition, item?.grades);
4917
+ });
4918
+ return result;
4919
+ }
4920
+ const asMapResponse = payload;
4921
+ const mapLike = asMapResponse?.field === "diagnosisgrade" && asMapResponse?.value && typeof asMapResponse.value === "object" ? asMapResponse.value : null;
4922
+ if (mapLike) {
4923
+ Object.entries(mapLike).forEach(([condition, grades]) => {
4924
+ pushGroup(condition, grades);
4925
+ });
4926
+ }
4927
+ return result;
4928
+ }
4929
+ var DiagnosisTextareaWidget = ({ fieldId }) => {
4930
+ const { fieldDef, value, setValue, setTouched, error, disabled, touched } = useField(fieldId);
4931
+ const { state } = useForm();
4932
+ const handler = useFieldHandlers(fieldId);
4933
+ const def = fieldDef;
4934
+ const [gradeGroups, setGradeGroups] = React15__namespace.default.useState([]);
4935
+ const [isLoadingGrades, setIsLoadingGrades] = React15__namespace.default.useState(false);
4936
+ const normalized = React15__namespace.default.useMemo(() => {
4937
+ const raw = value;
4938
+ if (typeof raw === "string") {
4939
+ return { text: raw, selectedGradesByCondition: {} };
4940
+ }
4941
+ if (!raw || typeof raw !== "object") {
4942
+ return { text: "", selectedGradesByCondition: {} };
4943
+ }
4944
+ const text = typeof raw.text === "string" ? raw.text : "";
4945
+ const mapRaw = raw.selectedGradesByCondition;
4946
+ let selectedGradesByCondition = {};
4947
+ if (mapRaw && typeof mapRaw === "object" && !Array.isArray(mapRaw)) {
4948
+ const entries = Object.entries(mapRaw);
4949
+ for (const [condition, gradeRaw] of entries) {
4950
+ if (typeof condition !== "string") continue;
4951
+ if (typeof gradeRaw === "string" && gradeRaw.trim()) {
4952
+ selectedGradesByCondition[condition] = gradeRaw;
4953
+ }
4954
+ }
4955
+ }
4956
+ const sg = raw.selectedGrade;
4957
+ if (sg && typeof sg === "object" && typeof sg.condition === "string" && typeof sg.grade === "string") {
4958
+ const condition = sg.condition.trim();
4959
+ const grade = sg.grade.trim();
4960
+ if (condition && grade && !selectedGradesByCondition[condition]) {
4961
+ selectedGradesByCondition = { ...selectedGradesByCondition, [condition]: grade };
4962
+ }
4963
+ }
4964
+ return { text, selectedGradesByCondition };
4965
+ }, [value]);
4966
+ const textValue = normalized.text;
4967
+ const showError = !!error && (touched || state.submitAttempted);
4968
+ React15__namespace.default.useEffect(() => {
4969
+ const query = textValue.trim();
4970
+ const fetchGrades = handler.onFetchDiagnosisGrades;
4971
+ const debounceMs = def?.debounceDelay ?? 1e3;
4972
+ if (!query || !fetchGrades) {
4973
+ setGradeGroups([]);
4974
+ setIsLoadingGrades(false);
4975
+ return;
4976
+ }
4977
+ let isActive = true;
4978
+ const timer = window.setTimeout(async () => {
4979
+ setIsLoadingGrades(true);
4980
+ try {
4981
+ const response = await fetchGrades(query);
4982
+ if (!isActive) return;
4983
+ setGradeGroups(normalizeDiagnosisGrades(response));
4984
+ } catch {
4985
+ if (!isActive) return;
4986
+ setGradeGroups([]);
4987
+ } finally {
4988
+ if (isActive) setIsLoadingGrades(false);
4989
+ }
4990
+ }, debounceMs);
4991
+ return () => {
4992
+ isActive = false;
4993
+ window.clearTimeout(timer);
4994
+ };
4995
+ }, [textValue, handler.onFetchDiagnosisGrades, def?.debounceDelay]);
4996
+ if (!def) return null;
4997
+ const theme = getThemeConfig("textarea", def.theme);
4998
+ const wrapperClass = theme?.wrapperClassName ?? "space-y-2";
4999
+ const labelClass = theme?.labelClassName;
5000
+ const inputClass = cn(theme?.inputClassName, showError && "border-red-500");
5001
+ const toggleSelectedGrade = (condition, grade) => {
5002
+ if (disabled) return;
5003
+ const current = normalized.selectedGradesByCondition[condition];
5004
+ const nextForCondition = current === grade ? "" : grade;
5005
+ const nextMap = { ...normalized.selectedGradesByCondition };
5006
+ if (!nextForCondition) {
5007
+ delete nextMap[condition];
5008
+ } else {
5009
+ nextMap[condition] = nextForCondition;
5010
+ }
5011
+ setValue({ text: normalized.text, selectedGradesByCondition: nextMap });
5012
+ setTouched();
5013
+ };
5014
+ const labelContent = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5015
+ def.label,
5016
+ " ",
5017
+ def.required && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-red-500", children: "*" })
5018
+ ] });
5019
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: wrapperClass, children: [
5020
+ theme ? /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, className: labelClass, children: labelContent }) : /* @__PURE__ */ jsxRuntime.jsx(Label, { htmlFor: fieldId, children: labelContent }),
5021
+ /* @__PURE__ */ jsxRuntime.jsx(
5022
+ Textarea,
5023
+ {
5024
+ id: fieldId,
5025
+ value: textValue,
5026
+ onChange: (e) => setValue({ text: e.target.value, selectedGradesByCondition: normalized.selectedGradesByCondition }),
5027
+ onBlur: setTouched,
5028
+ disabled,
5029
+ placeholder: def.placeholder,
5030
+ className: inputClass,
5031
+ ...def.height != null ? { height: def.height } : {}
5032
+ }
5033
+ ),
5034
+ isLoadingGrades && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-2 text-xs text-muted-foreground", children: "Checking diagnosis grades..." }),
5035
+ !isLoadingGrades && gradeGroups.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
5036
+ "div",
5037
+ {
5038
+ className: "mt-2 space-y-3 rounded-lg border border-border bg-muted/30 p-3",
5039
+ role: "group",
5040
+ "aria-label": "Diagnosis grade options",
5041
+ children: gradeGroups.map((group) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-1.5", children: [
5042
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "text-xs font-medium leading-none text-muted-foreground", children: [
5043
+ group.condition,
5044
+ ":"
5045
+ ] }),
5046
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: group.grades.map((grade) => /* @__PURE__ */ jsxRuntime.jsx(
5047
+ "button",
5048
+ {
5049
+ type: "button",
5050
+ onClick: () => toggleSelectedGrade(group.condition, grade),
5051
+ disabled,
5052
+ className: cn(
5053
+ "inline-flex min-h-8 items-center rounded-full border px-3 py-1 text-xs font-medium leading-none transition-colors",
5054
+ normalized.selectedGradesByCondition[group.condition] === grade ? "border-primary bg-primary/15 text-primary shadow-sm" : "border-border/80 bg-background text-foreground hover:bg-muted/80",
5055
+ disabled && "cursor-not-allowed opacity-60"
5056
+ ),
5057
+ children: grade
5058
+ },
5059
+ `${group.condition}-${grade}`
5060
+ )) })
5061
+ ] }, group.condition))
5062
+ }
5063
+ ),
5064
+ showError && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-red-500", children: error })
5065
+ ] });
5066
+ };
4797
5067
  var DEFAULT_DRAFT = {
4798
5068
  gpal: { G: 0, P: 0, A: 0, L: 0 },
4799
5069
  lmp: "",
@@ -5000,10 +5270,10 @@ function stripGpalSuffix(label) {
5000
5270
  return label.replace(/\s*\(G-P-A-L\)\s*$/i, "").trim();
5001
5271
  }
5002
5272
  function useDebouncedCommit(commit, delayMs) {
5003
- const timeoutRef = React13.useRef(null);
5004
- const latestCommit = React13.useRef(commit);
5273
+ const timeoutRef = React15.useRef(null);
5274
+ const latestCommit = React15.useRef(commit);
5005
5275
  latestCommit.current = commit;
5006
- React13.useEffect(() => {
5276
+ React15.useEffect(() => {
5007
5277
  return () => {
5008
5278
  if (timeoutRef.current != null) window.clearTimeout(timeoutRef.current);
5009
5279
  };
@@ -5015,18 +5285,18 @@ function useDebouncedCommit(commit, delayMs) {
5015
5285
  }
5016
5286
  var ObstetricHistoryWidget = ({ fieldId }) => {
5017
5287
  const { fieldDef, value, setValue, disabled } = useField(fieldId);
5018
- const [{ draft, isNewEntry }, setDraftState] = React13.useState(() => normalizeToDraft(value));
5019
- const [lmpError, setLmpError] = React13.useState(null);
5020
- const [primaryEddError, setPrimaryEddError] = React13.useState(null);
5021
- const [activeGpalKey, setActiveGpalKey] = React13.useState(null);
5288
+ const [{ draft, isNewEntry }, setDraftState] = React15.useState(() => normalizeToDraft(value));
5289
+ const [lmpError, setLmpError] = React15.useState(null);
5290
+ const [primaryEddError, setPrimaryEddError] = React15.useState(null);
5291
+ const [activeGpalKey, setActiveGpalKey] = React15.useState(null);
5022
5292
  const refs = {
5023
- G: React13.useRef(null),
5024
- P: React13.useRef(null),
5025
- A: React13.useRef(null),
5026
- L: React13.useRef(null)
5293
+ G: React15.useRef(null),
5294
+ P: React15.useRef(null),
5295
+ A: React15.useRef(null),
5296
+ L: React15.useRef(null)
5027
5297
  };
5028
- const today = React13.useMemo(() => todayIso(), []);
5029
- React13.useEffect(() => {
5298
+ const today = React15.useMemo(() => todayIso(), []);
5299
+ React15.useEffect(() => {
5030
5300
  const next = normalizeToDraft(value);
5031
5301
  const currStr = JSON.stringify(buildStored(draft, today));
5032
5302
  const nextStr = JSON.stringify(buildStored(next.draft, today));
@@ -5037,7 +5307,7 @@ var ObstetricHistoryWidget = ({ fieldId }) => {
5037
5307
  setValue(JSON.stringify(stored));
5038
5308
  };
5039
5309
  const commitDebounced = useDebouncedCommit(commitImmediate, 500);
5040
- const storedComputed = React13.useMemo(() => buildStored(draft, today), [draft, today]);
5310
+ const storedComputed = React15.useMemo(() => buildStored(draft, today), [draft, today]);
5041
5311
  const rightPanelEnabled = draft.is_pregnant && (!!storedComputed.lmp || !!storedComputed.edd?.usg);
5042
5312
  const headerLabel = fieldDef?.label ? stripGpalSuffix(fieldDef.label) : "Obstetric History";
5043
5313
  const setDraft = (updater, persist) => {
@@ -5486,7 +5756,7 @@ var numberInputClass = "w-full border border-[#D0D0D0] rounded-md bg-white px-2
5486
5756
  var textInputClass = "w-full border border-[#D0D0D0] rounded-md bg-white px-2 py-1 text-xs focus-visible:outline-none focus-visible:ring-0";
5487
5757
  var OphthalmologyWidget = ({ fieldId }) => {
5488
5758
  const { fieldDef, value, setValue, disabled } = useField(fieldId);
5489
- const safe = React13.useMemo(() => ensureValue(value), [value]);
5759
+ const safe = React15.useMemo(() => ensureValue(value), [value]);
5490
5760
  const label = fieldDef?.label || "";
5491
5761
  const update = (updater) => {
5492
5762
  if (disabled) return;
@@ -6663,7 +6933,7 @@ var headerCellClass = "border border-slate-200 px-2 py-1 text-center font-semibo
6663
6933
  var cellClass = "border border-slate-200 px-2 py-1 align-top";
6664
6934
  var OphthalDiagnosisWidget = ({ fieldId }) => {
6665
6935
  const { fieldDef, value, setValue, disabled } = useField(fieldId);
6666
- const safe = React13.useMemo(() => ensureValue2(value), [value]);
6936
+ const safe = React15.useMemo(() => ensureValue2(value), [value]);
6667
6937
  const label = fieldDef?.label || "";
6668
6938
  const updateEyeField = (eye, fieldLabel, next) => {
6669
6939
  if (disabled) return;
@@ -6713,7 +6983,7 @@ var OphthalDiagnosisWidget = ({ fieldId }) => {
6713
6983
  ] })
6714
6984
  ] });
6715
6985
  };
6716
- var Slider = React13__namespace.forwardRef(({ className, trackClassName, thumbClassName, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
6986
+ var Slider = React15__namespace.forwardRef(({ className, trackClassName, thumbClassName, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
6717
6987
  SliderPrimitive__namespace.Root,
6718
6988
  {
6719
6989
  ref,
@@ -6807,7 +7077,7 @@ var OrthopedicExamWidget = ({ fieldId }) => {
6807
7077
  const { fieldDef, value, setValue, setTouched, error, touched, disabled } = useField(fieldId);
6808
7078
  const { state } = useForm();
6809
7079
  const showError = !!error && (touched || state.submitAttempted);
6810
- const safeValue = React13.useMemo(() => {
7080
+ const safeValue = React15.useMemo(() => {
6811
7081
  if (!value || typeof value !== "object") return defaultValue();
6812
7082
  const v = value;
6813
7083
  const concerns = Array.isArray(v.concerns) ? v.concerns : [];
@@ -6829,10 +7099,10 @@ var OrthopedicExamWidget = ({ fieldId }) => {
6829
7099
  }
6830
7100
  };
6831
7101
  }, [value]);
6832
- const [panelOpen, setPanelOpen] = React13.useState(false);
6833
- const draggingRef = React13.useRef(null);
6834
- const prevConcernsLengthRef = React13.useRef(safeValue.concerns.length);
6835
- const reminderSections = React13.useMemo(() => {
7102
+ const [panelOpen, setPanelOpen] = React15.useState(false);
7103
+ const draggingRef = React15.useRef(null);
7104
+ const prevConcernsLengthRef = React15.useRef(safeValue.concerns.length);
7105
+ const reminderSections = React15.useMemo(() => {
6836
7106
  return safeValue.concerns.map((id) => ({
6837
7107
  id,
6838
7108
  label: CONCERNS.find((c) => c.id === id)?.label ?? id,
@@ -6840,7 +7110,7 @@ var OrthopedicExamWidget = ({ fieldId }) => {
6840
7110
  })).filter((s) => s.points.length > 0);
6841
7111
  }, [safeValue.concerns]);
6842
7112
  const hasReminders = reminderSections.length > 0;
6843
- React13.useEffect(() => {
7113
+ React15.useEffect(() => {
6844
7114
  const prevLen = prevConcernsLengthRef.current;
6845
7115
  const currLen = safeValue.concerns.length;
6846
7116
  prevConcernsLengthRef.current = currLen;
@@ -6855,7 +7125,7 @@ var OrthopedicExamWidget = ({ fieldId }) => {
6855
7125
  setPanelOpen(true);
6856
7126
  }
6857
7127
  }, [safeValue, setValue]);
6858
- React13.useEffect(() => {
7128
+ React15.useEffect(() => {
6859
7129
  const onMove = (e) => {
6860
7130
  if (!draggingRef.current) return;
6861
7131
  const { startX, startY, startTop, startRight } = draggingRef.current;
@@ -7101,6 +7371,9 @@ var FieldRenderer = ({ fieldId }) => {
7101
7371
  if (!visible || !fieldDef) {
7102
7372
  return null;
7103
7373
  }
7374
+ return renderWidget(fieldId, fieldDef);
7375
+ };
7376
+ function renderWidget(fieldId, fieldDef) {
7104
7377
  switch (fieldDef.type) {
7105
7378
  case "text":
7106
7379
  case "number":
@@ -7147,6 +7420,8 @@ var FieldRenderer = ({ fieldId }) => {
7147
7420
  return /* @__PURE__ */ jsxRuntime.jsx(FollowupWidget, { fieldId });
7148
7421
  case "smart_textarea":
7149
7422
  return /* @__PURE__ */ jsxRuntime.jsx(SmartTextareaWidget, { fieldId });
7423
+ case "diagnosis_textarea":
7424
+ return /* @__PURE__ */ jsxRuntime.jsx(DiagnosisTextareaWidget, { fieldId });
7150
7425
  case "obstetric_history":
7151
7426
  return /* @__PURE__ */ jsxRuntime.jsx(ObstetricHistoryWidget, { fieldId });
7152
7427
  case "eye_prescription":
@@ -7171,9 +7446,9 @@ var FieldRenderer = ({ fieldId }) => {
7171
7446
  fieldDef.type
7172
7447
  ] });
7173
7448
  }
7174
- };
7449
+ }
7175
7450
  var Section = ({ title, children }) => {
7176
- const [expanded, setExpanded] = React13.useState(true);
7451
+ const [expanded, setExpanded] = React15.useState(true);
7177
7452
  const handleToggle = () => setExpanded((prev) => !prev);
7178
7453
  const contentClassName = cn(
7179
7454
  "overflow-hidden transition-[height] duration-200 ease-in-out",
@@ -7226,7 +7501,7 @@ var DynamicForm = () => {
7226
7501
  children: child.children.map((fieldId) => /* @__PURE__ */ jsxRuntime.jsx(FieldRenderer, { fieldId }, fieldId))
7227
7502
  },
7228
7503
  child.id
7229
- ) : /* @__PURE__ */ jsxRuntime.jsx(React13__namespace.default.Fragment, {}, child.id ?? index)
7504
+ ) : /* @__PURE__ */ jsxRuntime.jsx(React15__namespace.default.Fragment, {}, child.id ?? index)
7230
7505
  ) }, node.id);
7231
7506
  }
7232
7507
  if (node.type === "column_layout") {
@@ -7314,13 +7589,13 @@ var SmartForm = ({
7314
7589
  }) => {
7315
7590
  const store = useFormStore();
7316
7591
  const schema = store.getSchema();
7317
- const prevAiResultRef = React13.useRef(void 0);
7318
- const aiSuggestions = React13.useMemo(() => {
7592
+ const prevAiResultRef = React15.useRef(void 0);
7593
+ const aiSuggestions = React15.useMemo(() => {
7319
7594
  if (aiAnalysisResult == null) return { medications: [] };
7320
7595
  const medications = normalizeAIMedications(aiAnalysisResult.medications);
7321
7596
  return { medications };
7322
7597
  }, [aiAnalysisResult]);
7323
- React13.useEffect(() => {
7598
+ React15.useEffect(() => {
7324
7599
  if (aiAnalysisResult == null || Object.keys(aiAnalysisResult).length === 0) return;
7325
7600
  const prev = prevAiResultRef.current;
7326
7601
  if (prev != null && prev === aiAnalysisResult && shallowEqualKeys(prev, aiAnalysisResult)) return;
@@ -7393,9 +7668,9 @@ var ReadOnlyText = ({ fieldDef, value }) => {
7393
7668
  ] });
7394
7669
  };
7395
7670
  var ReadOnlySelect = ({ fieldDef, value }) => {
7396
- const [options, setOptions] = React13.useState([]);
7397
- const [loading, setLoading] = React13.useState(false);
7398
- React13.useEffect(() => {
7671
+ const [options, setOptions] = React15.useState([]);
7672
+ const [loading, setLoading] = React15.useState(false);
7673
+ React15.useEffect(() => {
7399
7674
  if (fieldDef.options) {
7400
7675
  setOptions(fieldDef.options);
7401
7676
  } else if (fieldDef.dataSource) {
@@ -7417,9 +7692,9 @@ var ReadOnlySelect = ({ fieldDef, value }) => {
7417
7692
  ] });
7418
7693
  };
7419
7694
  var ReadOnlyMultiSelect = ({ fieldDef, value }) => {
7420
- const [options, setOptions] = React13.useState([]);
7421
- const [loading, setLoading] = React13.useState(false);
7422
- React13.useEffect(() => {
7695
+ const [options, setOptions] = React15.useState([]);
7696
+ const [loading, setLoading] = React15.useState(false);
7697
+ React15.useEffect(() => {
7423
7698
  if (fieldDef.options) {
7424
7699
  setOptions(fieldDef.options);
7425
7700
  } else if (fieldDef.dataSource) {
@@ -7568,13 +7843,13 @@ var ReadOnlyTable = ({
7568
7843
  fieldDef,
7569
7844
  value
7570
7845
  }) => {
7571
- const tableData = React13.useMemo(() => {
7846
+ const tableData = React15.useMemo(() => {
7572
7847
  if (value && typeof value === "object" && "columns" in value && "rows" in value && Array.isArray(value.columns) && Array.isArray(value.rows)) {
7573
7848
  return value;
7574
7849
  }
7575
7850
  return { columns: [], rows: [] };
7576
7851
  }, [value]);
7577
- const columns = React13.useMemo(() => {
7852
+ const columns = React15.useMemo(() => {
7578
7853
  return tableData.columns.map((col) => ({
7579
7854
  accessorKey: col.id,
7580
7855
  header: col.label,
@@ -7629,9 +7904,9 @@ var ReadOnlyDateTime = ({ fieldDef, value }) => {
7629
7904
  ] });
7630
7905
  };
7631
7906
  var ReadOnlyRadio = ({ fieldDef, value }) => {
7632
- const [options, setOptions] = React13.useState([]);
7633
- const [loading, setLoading] = React13.useState(false);
7634
- React13.useEffect(() => {
7907
+ const [options, setOptions] = React15.useState([]);
7908
+ const [loading, setLoading] = React15.useState(false);
7909
+ React15.useEffect(() => {
7635
7910
  if (fieldDef.options?.length) {
7636
7911
  setOptions(fieldDef.options);
7637
7912
  } else if (fieldDef.dataSource) {
@@ -7656,9 +7931,9 @@ function isOptionSelected2(selected, optValue) {
7656
7931
  );
7657
7932
  }
7658
7933
  var ReadOnlyCheckbox = ({ fieldDef, value }) => {
7659
- const [options, setOptions] = React13.useState([]);
7660
- const [loading, setLoading] = React13.useState(false);
7661
- React13.useEffect(() => {
7934
+ const [options, setOptions] = React15.useState([]);
7935
+ const [loading, setLoading] = React15.useState(false);
7936
+ React15.useEffect(() => {
7662
7937
  if (fieldDef.options?.length) {
7663
7938
  setOptions(fieldDef.options);
7664
7939
  } else if (fieldDef.dataSource) {
@@ -7810,7 +8085,7 @@ var ReadOnlyForm = ({ schema, submission }) => {
7810
8085
  child.id
7811
8086
  );
7812
8087
  }
7813
- return /* @__PURE__ */ jsxRuntime.jsx(React13__namespace.default.Fragment, {}, child.id ?? index);
8088
+ return /* @__PURE__ */ jsxRuntime.jsx(React15__namespace.default.Fragment, {}, child.id ?? index);
7814
8089
  };
7815
8090
  const hasContent = node.children.some(
7816
8091
  (child) => typeof child === "string" ? fieldMap.has(child) : child.type === "column_layout" && child.children?.some((id) => fieldMap.has(id))