formanitor 0.0.26 → 0.0.27

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
@@ -3360,8 +3360,9 @@ var AddInvestigationField = ({
3360
3360
  const debounceRef = React13.useRef(null);
3361
3361
  const valueRef = React13.useRef([]);
3362
3362
  const searchInputRef = React13.useRef(null);
3363
- valueRef.current = value;
3364
- const addedIds = new Set(value.map((inv) => inv.id));
3363
+ const safeValue = Array.isArray(value) ? value : [];
3364
+ valueRef.current = safeValue;
3365
+ const addedIds = new Set(safeValue.map((inv) => inv.id));
3365
3366
  React13.useEffect(() => {
3366
3367
  if (!open) {
3367
3368
  setQuery("");
@@ -3404,7 +3405,7 @@ var AddInvestigationField = ({
3404
3405
  }, ADD_FEEDBACK_MS2);
3405
3406
  }
3406
3407
  function removeInvestigation(id) {
3407
- onChange(value.filter((inv) => inv.id !== id));
3408
+ onChange(safeValue.filter((inv) => inv.id !== id));
3408
3409
  }
3409
3410
  function handleRecentlyUsedToggle(result) {
3410
3411
  if (addedIds.has(result.id)) {
@@ -3416,10 +3417,10 @@ var AddInvestigationField = ({
3416
3417
  async function handleFrequentItemToggle(item) {
3417
3418
  const id = String(item.id);
3418
3419
  const addedById = addedIds.has(id);
3419
- const addedByName = value.some((inv) => inv.name === item.name);
3420
+ const addedByName = safeValue.some((inv) => inv.name === item.name);
3420
3421
  if (addedById || addedByName) {
3421
3422
  if (addedById) removeInvestigation(id);
3422
- else onChange(value.filter((inv) => inv.name !== item.name));
3423
+ else onChange(safeValue.filter((inv) => inv.name !== item.name));
3423
3424
  return;
3424
3425
  }
3425
3426
  setAddingFrequentId(id);
@@ -3455,7 +3456,7 @@ var AddInvestigationField = ({
3455
3456
  const limitedFrequentItems = frequentItems.slice(0, 25);
3456
3457
  const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
3457
3458
  const id = String(item.id);
3458
- const isAdded = value.some((inv) => inv.id === id) || value.some((inv) => inv.name === item.name);
3459
+ const isAdded = safeValue.some((inv) => inv.id === id) || safeValue.some((inv) => inv.name === item.name);
3459
3460
  const isAdding = addingFrequentId === id;
3460
3461
  return /* @__PURE__ */ jsxRuntime.jsxs(
3461
3462
  "button",
@@ -3489,7 +3490,7 @@ var AddInvestigationField = ({
3489
3490
  }
3490
3491
  )
3491
3492
  ] }),
3492
- value.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: value.map((inv) => /* @__PURE__ */ jsxRuntime.jsxs(
3493
+ safeValue.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: safeValue.map((inv) => /* @__PURE__ */ jsxRuntime.jsxs(
3493
3494
  "div",
3494
3495
  {
3495
3496
  className: "flex items-center justify-between px-3 py-2 bg-white hover:bg-gray-50",
@@ -3556,10 +3557,11 @@ var AddInvestigationWidget = ({ fieldId }) => {
3556
3557
  const { value, setValue } = useField(fieldId);
3557
3558
  const handlers = useFieldHandlers(fieldId);
3558
3559
  const { investigations: frequentInvestigations } = useFrequentItems();
3560
+ const safeValue = Array.isArray(value) ? value : [];
3559
3561
  return /* @__PURE__ */ jsxRuntime.jsx(
3560
3562
  AddInvestigationField,
3561
3563
  {
3562
- value: value ?? [],
3564
+ value: safeValue,
3563
3565
  onChange: setValue,
3564
3566
  onSearch: handlers.onSearch,
3565
3567
  recentlyUsed: handlers.recentlyUsed,
@@ -3596,9 +3598,10 @@ var AddProcedureField = ({
3596
3598
  const debounceRef = React13.useRef(null);
3597
3599
  const valueRef = React13.useRef([]);
3598
3600
  const searchInputRef = React13.useRef(null);
3599
- valueRef.current = value;
3601
+ const safeValue = Array.isArray(value) ? value : [];
3602
+ valueRef.current = safeValue;
3600
3603
  const addedIds = new Set(
3601
- value.filter((proc) => !proc.is_custom).map((proc) => proc.id)
3604
+ safeValue.filter((proc) => !proc.is_custom).map((proc) => proc.id)
3602
3605
  );
3603
3606
  React13.useEffect(() => {
3604
3607
  if (!open) {
@@ -3642,10 +3645,10 @@ var AddProcedureField = ({
3642
3645
  }, ADD_FEEDBACK_MS3);
3643
3646
  }
3644
3647
  function removeAt(index) {
3645
- onChange(value.filter((_, i) => i !== index));
3648
+ onChange(safeValue.filter((_, i) => i !== index));
3646
3649
  }
3647
3650
  function removeBySearchId(id) {
3648
- onChange(value.filter((proc) => proc.is_custom || proc.id !== id));
3651
+ onChange(safeValue.filter((proc) => proc.is_custom || proc.id !== id));
3649
3652
  }
3650
3653
  function handleAddCustom() {
3651
3654
  const trimmed = query.trim();
@@ -3665,10 +3668,10 @@ var AddProcedureField = ({
3665
3668
  async function handleFrequentItemToggle(item) {
3666
3669
  const id = String(item.id);
3667
3670
  const addedById = addedIds.has(id);
3668
- const addedByName = value.some((proc) => proc.name === item.name);
3671
+ const addedByName = safeValue.some((proc) => proc.name === item.name);
3669
3672
  if (addedById || addedByName) {
3670
3673
  if (addedById) removeBySearchId(id);
3671
- else onChange(value.filter((proc) => proc.name !== item.name));
3674
+ else onChange(safeValue.filter((proc) => proc.name !== item.name));
3672
3675
  return;
3673
3676
  }
3674
3677
  setAddingFrequentId(id);
@@ -3704,7 +3707,7 @@ var AddProcedureField = ({
3704
3707
  const limitedFrequentItems = frequentItems.slice(0, 25);
3705
3708
  const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
3706
3709
  const id = String(item.id);
3707
- const isAdded = value.some((proc) => !proc.is_custom && proc.id === id) || value.some((proc) => proc.name === item.name);
3710
+ const isAdded = safeValue.some((proc) => !proc.is_custom && proc.id === id) || safeValue.some((proc) => proc.name === item.name);
3708
3711
  const isAdding = addingFrequentId === id;
3709
3712
  return /* @__PURE__ */ jsxRuntime.jsxs(
3710
3713
  "button",
@@ -3738,7 +3741,7 @@ var AddProcedureField = ({
3738
3741
  }
3739
3742
  )
3740
3743
  ] }),
3741
- value.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: value.map((proc, index) => /* @__PURE__ */ jsxRuntime.jsxs(
3744
+ safeValue.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y divide-border rounded-lg border border-border overflow-hidden", children: safeValue.map((proc, index) => /* @__PURE__ */ jsxRuntime.jsxs(
3742
3745
  "div",
3743
3746
  {
3744
3747
  className: "flex items-center justify-between px-3 py-2 bg-white hover:bg-gray-50",
@@ -3818,10 +3821,11 @@ var AddProcedureWidget = ({ fieldId }) => {
3818
3821
  const { value, setValue } = useField(fieldId);
3819
3822
  const handlers = useFieldHandlers(fieldId);
3820
3823
  const { procedures: frequentProcedures } = useFrequentItems();
3824
+ const safeValue = Array.isArray(value) ? value : [];
3821
3825
  return /* @__PURE__ */ jsxRuntime.jsx(
3822
3826
  AddProcedureField,
3823
3827
  {
3824
- value: value ?? [],
3828
+ value: safeValue,
3825
3829
  onChange: setValue,
3826
3830
  onSearch: handlers.onSearch,
3827
3831
  recentlyUsed: handlers.recentlyUsed,