formanitor 0.0.33 → 0.0.34

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
@@ -732,6 +732,7 @@ var emptyFrequentItems = {
732
732
  procedures: []
733
733
  };
734
734
  var FrequentItemsContext = React15.createContext(emptyFrequentItems);
735
+ var PackagesContext = React15.createContext([]);
735
736
  var FieldHandlersContext = React15.createContext({});
736
737
  function useFieldHandlers(fieldId) {
737
738
  const map = React15.useContext(FieldHandlersContext);
@@ -740,11 +741,15 @@ function useFieldHandlers(fieldId) {
740
741
  function useFrequentItems() {
741
742
  return React15.useContext(FrequentItemsContext);
742
743
  }
744
+ function usePackages() {
745
+ return React15.useContext(PackagesContext);
746
+ }
743
747
  var FormProvider = ({
744
748
  schema,
745
749
  config,
746
750
  fieldHandlers,
747
751
  frequentItems,
752
+ packages,
748
753
  children
749
754
  }) => {
750
755
  const storeRef = React15.useRef(null);
@@ -760,7 +765,7 @@ var FormProvider = ({
760
765
  storeRef.current?.load();
761
766
  }, []);
762
767
  const frequentItemsValue = frequentItems ?? emptyFrequentItems;
763
- 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 }) }) }) });
768
+ 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(PackagesContext.Provider, { value: packages ?? [], children: /* @__PURE__ */ jsxRuntime.jsx(VoiceContextProvider, { children }) }) }) }) });
764
769
  };
765
770
  function useFormStore() {
766
771
  const context = React15.useContext(FormContext);
@@ -3113,18 +3118,20 @@ var AddEntityDialog = ({
3113
3118
  open,
3114
3119
  onClose,
3115
3120
  title,
3121
+ chipSections,
3116
3122
  recentlyUsedSlot,
3117
3123
  chipSectionLabel = "Recently Used",
3118
3124
  children,
3119
3125
  actionSlot
3120
3126
  }) => {
3121
- return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-lg w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
3127
+ const sections = chipSections ?? (recentlyUsedSlot ? [{ label: chipSectionLabel, content: recentlyUsedSlot }] : []);
3128
+ return /* @__PURE__ */ jsxRuntime.jsx(Dialog, { open, onOpenChange: (o) => !o && onClose(), children: /* @__PURE__ */ jsxRuntime.jsxs(DialogContent, { className: "max-w-4xl w-full p-0 gap-0 flex flex-col max-h-[90vh] overflow-hidden", children: [
3122
3129
  /* @__PURE__ */ jsxRuntime.jsx(DialogHeader, { className: "px-6 pt-6 pb-4 shrink-0", children: /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { className: "text-lg font-semibold", children: title }) }),
3123
3130
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-6 flex flex-col gap-4 overflow-y-auto flex-1 min-h-0 pb-4", children: [
3124
- recentlyUsedSlot && /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3125
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mb-2", children: chipSectionLabel }),
3126
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: recentlyUsedSlot })
3127
- ] }),
3131
+ sections.map((section) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
3132
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs text-muted-foreground mb-2", children: section.label }),
3133
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: section.content })
3134
+ ] }, section.label)),
3128
3135
  children
3129
3136
  ] }),
3130
3137
  actionSlot != null && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4 flex justify-end shrink-0 border-t border-border bg-background", children: actionSlot })
@@ -3666,7 +3673,8 @@ var AddInvestigationField = ({
3666
3673
  onChange,
3667
3674
  onSearch,
3668
3675
  recentlyUsed = [],
3669
- frequentItems = []
3676
+ frequentItems = [],
3677
+ packages = []
3670
3678
  }) => {
3671
3679
  const [open, setOpen] = React15.useState(false);
3672
3680
  const [query, setQuery] = React15.useState("");
@@ -3677,6 +3685,8 @@ var AddInvestigationField = ({
3677
3685
  const debounceRef = React15.useRef(null);
3678
3686
  const valueRef = React15.useRef([]);
3679
3687
  const searchInputRef = React15.useRef(null);
3688
+ const addedByPackage = React15.useRef(/* @__PURE__ */ new Map());
3689
+ const [selectedPackageIds, setSelectedPackageIds] = React15.useState(/* @__PURE__ */ new Set());
3680
3690
  const safeValue = Array.isArray(value) ? value : [];
3681
3691
  valueRef.current = safeValue;
3682
3692
  const addedIds = new Set(safeValue.map((inv) => inv.id));
@@ -3751,6 +3761,27 @@ var AddInvestigationField = ({
3751
3761
  setAddingFrequentId(null);
3752
3762
  }
3753
3763
  }
3764
+ function handlePackageToggle(pkg) {
3765
+ const alreadyAdded = addedByPackage.current.has(pkg.id);
3766
+ if (alreadyAdded) {
3767
+ const idsToRemove = new Set(addedByPackage.current.get(pkg.id) ?? []);
3768
+ onChange(valueRef.current.filter((inv) => !idsToRemove.has(inv.id)));
3769
+ addedByPackage.current.delete(pkg.id);
3770
+ setSelectedPackageIds((prev) => {
3771
+ const next = new Set(prev);
3772
+ next.delete(pkg.id);
3773
+ return next;
3774
+ });
3775
+ } else {
3776
+ const currentIds = new Set(valueRef.current.map((inv) => inv.id));
3777
+ const newTests = pkg.tests.filter((t) => !currentIds.has(t.id)).map((t) => mapToInvestigation(t));
3778
+ if (newTests.length > 0) {
3779
+ onChange([...valueRef.current, ...newTests]);
3780
+ }
3781
+ addedByPackage.current.set(pkg.id, newTests.map((t) => t.id));
3782
+ setSelectedPackageIds((prev) => new Set(prev).add(pkg.id));
3783
+ }
3784
+ }
3754
3785
  const recentlyUsedChips = recentlyUsed.map((r) => {
3755
3786
  const isAdded = addedIds.has(r.id);
3756
3787
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -3794,6 +3825,38 @@ var AddInvestigationField = ({
3794
3825
  item.id
3795
3826
  );
3796
3827
  }) : [];
3828
+ const packageChips = packages.map((pkg) => {
3829
+ const isAdded = selectedPackageIds.has(pkg.id);
3830
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3831
+ "button",
3832
+ {
3833
+ type: "button",
3834
+ onClick: () => handlePackageToggle(pkg),
3835
+ className: cn(
3836
+ "rounded-full border text-xs px-4 py-1.5 transition-colors flex items-center gap-2",
3837
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3838
+ ),
3839
+ children: [
3840
+ isAdded && /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u2713" }),
3841
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "font-semibold", children: pkg.name }),
3842
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(
3843
+ "rounded-full px-1.5 py-0.5 text-[10px] font-medium",
3844
+ isAdded ? "bg-green-100 text-green-600" : "bg-purple-100 text-purple-600"
3845
+ ), children: pkg.tests.length })
3846
+ ]
3847
+ },
3848
+ pkg.id
3849
+ );
3850
+ });
3851
+ const chipSections = [];
3852
+ if (frequentItemChips.length > 0) {
3853
+ chipSections.push({ label: "Frequently used", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: frequentItemChips }) });
3854
+ } else if (recentlyUsedChips.length > 0) {
3855
+ chipSections.push({ label: "Recently Used", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: recentlyUsedChips }) });
3856
+ }
3857
+ if (packageChips.length > 0) {
3858
+ chipSections.push({ label: "Packages", content: /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: packageChips }) });
3859
+ }
3797
3860
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "rounded-md overflow-hidden flex flex-col bg-white border border-[#D0D0D0] space-y-3 p-3 h-fit", children: [
3798
3861
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-3", children: [
3799
3862
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold", children: label }),
@@ -3832,8 +3895,7 @@ var AddInvestigationField = ({
3832
3895
  open,
3833
3896
  onClose: () => setOpen(false),
3834
3897
  title: "Add Investigation",
3835
- recentlyUsedSlot: frequentItemChips.length > 0 ? frequentItemChips : recentlyUsedChips.length > 0 ? recentlyUsedChips : void 0,
3836
- chipSectionLabel: frequentItemChips.length > 0 ? "Frequently used" : void 0,
3898
+ chipSections: chipSections.length > 0 ? chipSections : void 0,
3837
3899
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
3838
3900
  /* @__PURE__ */ jsxRuntime.jsx(
3839
3901
  Input,
@@ -3874,6 +3936,7 @@ var AddInvestigationWidget = ({ fieldId }) => {
3874
3936
  const { value, setValue } = useField(fieldId);
3875
3937
  const handlers = useFieldHandlers(fieldId);
3876
3938
  const { investigations: frequentInvestigations } = useFrequentItems();
3939
+ const packages = usePackages();
3877
3940
  const safeValue = Array.isArray(value) ? value : [];
3878
3941
  return /* @__PURE__ */ jsxRuntime.jsx(
3879
3942
  AddInvestigationField,
@@ -3882,7 +3945,8 @@ var AddInvestigationWidget = ({ fieldId }) => {
3882
3945
  onChange: setValue,
3883
3946
  onSearch: handlers.onSearch,
3884
3947
  recentlyUsed: handlers.recentlyUsed,
3885
- frequentItems: frequentInvestigations
3948
+ frequentItems: frequentInvestigations,
3949
+ packages
3886
3950
  }
3887
3951
  );
3888
3952
  };
@@ -8764,6 +8828,7 @@ exports.useFieldHandlers = useFieldHandlers;
8764
8828
  exports.useForm = useForm;
8765
8829
  exports.useFormStore = useFormStore;
8766
8830
  exports.useFrequentItems = useFrequentItems;
8831
+ exports.usePackages = usePackages;
8767
8832
  exports.useSmartKeywords = useSmartKeywords;
8768
8833
  exports.validateField = validateField;
8769
8834
  exports.validateForm = validateForm;