formanitor 0.0.16 → 0.0.17

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
@@ -368,7 +368,7 @@ var FormStore = class {
368
368
  }
369
369
  };
370
370
  this.config.onDraftChange?.(payload);
371
- }, 2500);
371
+ }, 5e3);
372
372
  }
373
373
  async save() {
374
374
  const payload = {
@@ -3042,16 +3042,6 @@ function mapToInvestigation(result) {
3042
3042
  fromAI: false
3043
3043
  };
3044
3044
  }
3045
- function mapFrequentItemToInvestigation(item) {
3046
- return {
3047
- id: String(item.id),
3048
- name: item.name,
3049
- code: item.code ?? void 0,
3050
- label: item.name,
3051
- is_custom: false,
3052
- fromAI: false
3053
- };
3054
- }
3055
3045
  var AddInvestigationField = ({
3056
3046
  label = "Investigations",
3057
3047
  value,
@@ -3065,6 +3055,7 @@ var AddInvestigationField = ({
3065
3055
  const [results, setResults] = React11.useState([]);
3066
3056
  const [loading, setLoading] = React11.useState(false);
3067
3057
  const [addingId, setAddingId] = React11.useState(null);
3058
+ const [addingFrequentId, setAddingFrequentId] = React11.useState(null);
3068
3059
  const debounceRef = React11.useRef(null);
3069
3060
  const valueRef = React11.useRef([]);
3070
3061
  const searchInputRef = React11.useRef(null);
@@ -3075,6 +3066,7 @@ var AddInvestigationField = ({
3075
3066
  setQuery("");
3076
3067
  setResults([]);
3077
3068
  setAddingId(null);
3069
+ setAddingFrequentId(null);
3078
3070
  }
3079
3071
  }, [open]);
3080
3072
  function handleQueryChange(q) {
@@ -3120,12 +3112,24 @@ var AddInvestigationField = ({
3120
3112
  addInvestigation(result);
3121
3113
  }
3122
3114
  }
3123
- function handleFrequentItemToggle(item) {
3115
+ async function handleFrequentItemToggle(item) {
3124
3116
  const id = String(item.id);
3125
- if (addedIds.has(id)) {
3126
- removeInvestigation(id);
3127
- } else {
3128
- onChange([...valueRef.current, mapFrequentItemToInvestigation(item)]);
3117
+ const addedById = addedIds.has(id);
3118
+ const addedByName = value.some((inv) => inv.name === item.name);
3119
+ if (addedById || addedByName) {
3120
+ if (addedById) removeInvestigation(id);
3121
+ else onChange(value.filter((inv) => inv.name !== item.name));
3122
+ return;
3123
+ }
3124
+ setAddingFrequentId(id);
3125
+ try {
3126
+ const searchResults = await onSearch(item.name);
3127
+ const first = searchResults?.[0];
3128
+ if (first && !valueRef.current.some((inv) => inv.id === first.id)) {
3129
+ onChange([...valueRef.current, mapToInvestigation(first)]);
3130
+ }
3131
+ } finally {
3132
+ setAddingFrequentId(null);
3129
3133
  }
3130
3134
  }
3131
3135
  const recentlyUsedChips = recentlyUsed.map((r) => {
@@ -3150,19 +3154,22 @@ var AddInvestigationField = ({
3150
3154
  const limitedFrequentItems = frequentItems.slice(0, 25);
3151
3155
  const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
3152
3156
  const id = String(item.id);
3153
- const isAdded = addedIds.has(id);
3157
+ const isAdded = value.some((inv) => inv.id === id) || value.some((inv) => inv.name === item.name);
3158
+ const isAdding = addingFrequentId === id;
3154
3159
  return /* @__PURE__ */ jsxRuntime.jsxs(
3155
3160
  "button",
3156
3161
  {
3157
3162
  type: "button",
3163
+ disabled: isAdding,
3158
3164
  onClick: () => handleFrequentItemToggle(item),
3159
3165
  className: cn(
3160
3166
  "rounded-full border text-xs px-3 py-1 transition-colors",
3161
- isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3167
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50",
3168
+ isAdding && "opacity-70 pointer-events-none"
3162
3169
  ),
3163
3170
  children: [
3164
3171
  isAdded && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1", children: "\u2713" }),
3165
- item.name
3172
+ isAdding ? "\u2026" : item.name
3166
3173
  ]
3167
3174
  },
3168
3175
  item.id
@@ -3268,16 +3275,6 @@ function mapToProcedure(result) {
3268
3275
  fromAI: false
3269
3276
  };
3270
3277
  }
3271
- function mapFrequentItemToProcedure(item) {
3272
- return {
3273
- id: String(item.id),
3274
- name: item.name,
3275
- code: item.code ?? void 0,
3276
- label: item.name,
3277
- is_custom: false,
3278
- fromAI: false
3279
- };
3280
- }
3281
3278
  var AddProcedureField = ({
3282
3279
  label = "Procedures",
3283
3280
  value,
@@ -3291,6 +3288,7 @@ var AddProcedureField = ({
3291
3288
  const [results, setResults] = React11.useState([]);
3292
3289
  const [loading, setLoading] = React11.useState(false);
3293
3290
  const [addingId, setAddingId] = React11.useState(null);
3291
+ const [addingFrequentId, setAddingFrequentId] = React11.useState(null);
3294
3292
  const debounceRef = React11.useRef(null);
3295
3293
  const valueRef = React11.useRef([]);
3296
3294
  const searchInputRef = React11.useRef(null);
@@ -3301,6 +3299,7 @@ var AddProcedureField = ({
3301
3299
  setQuery("");
3302
3300
  setResults([]);
3303
3301
  setAddingId(null);
3302
+ setAddingFrequentId(null);
3304
3303
  }
3305
3304
  }, [open]);
3306
3305
  function handleQueryChange(q) {
@@ -3346,12 +3345,24 @@ var AddProcedureField = ({
3346
3345
  addProcedure(result);
3347
3346
  }
3348
3347
  }
3349
- function handleFrequentItemToggle(item) {
3348
+ async function handleFrequentItemToggle(item) {
3350
3349
  const id = String(item.id);
3351
- if (addedIds.has(id)) {
3352
- removeProcedure(id);
3353
- } else {
3354
- onChange([...valueRef.current, mapFrequentItemToProcedure(item)]);
3350
+ const addedById = addedIds.has(id);
3351
+ const addedByName = value.some((proc) => proc.name === item.name);
3352
+ if (addedById || addedByName) {
3353
+ if (addedById) removeProcedure(id);
3354
+ else onChange(value.filter((proc) => proc.name !== item.name));
3355
+ return;
3356
+ }
3357
+ setAddingFrequentId(id);
3358
+ try {
3359
+ const searchResults = await onSearch(item.name);
3360
+ const first = searchResults?.[0];
3361
+ if (first && !valueRef.current.some((proc) => proc.id === first.id)) {
3362
+ onChange([...valueRef.current, mapToProcedure(first)]);
3363
+ }
3364
+ } finally {
3365
+ setAddingFrequentId(null);
3355
3366
  }
3356
3367
  }
3357
3368
  const recentlyUsedChips = recentlyUsed.map((r) => {
@@ -3376,19 +3387,22 @@ var AddProcedureField = ({
3376
3387
  const limitedFrequentItems = frequentItems.slice(0, 25);
3377
3388
  const frequentItemChips = limitedFrequentItems.length > 0 ? limitedFrequentItems.map((item) => {
3378
3389
  const id = String(item.id);
3379
- const isAdded = addedIds.has(id);
3390
+ const isAdded = value.some((proc) => proc.id === id) || value.some((proc) => proc.name === item.name);
3391
+ const isAdding = addingFrequentId === id;
3380
3392
  return /* @__PURE__ */ jsxRuntime.jsxs(
3381
3393
  "button",
3382
3394
  {
3383
3395
  type: "button",
3396
+ disabled: isAdding,
3384
3397
  onClick: () => handleFrequentItemToggle(item),
3385
3398
  className: cn(
3386
3399
  "rounded-full border text-xs px-3 py-1 transition-colors",
3387
- isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50"
3400
+ isAdded ? "border-green-300 bg-green-50 text-green-700" : "border-border bg-white hover:bg-gray-50",
3401
+ isAdding && "opacity-70 pointer-events-none"
3388
3402
  ),
3389
3403
  children: [
3390
3404
  isAdded && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-1", children: "\u2713" }),
3391
- item.name
3405
+ isAdding ? "\u2026" : item.name
3392
3406
  ]
3393
3407
  },
3394
3408
  item.id