formanitor 0.0.6 → 0.0.9

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
@@ -181,10 +181,6 @@ var NO_OP_PROVIDER = {
181
181
  function applyPrefill(currentValues, fields, prefilledData = {}) {
182
182
  const newValues = { ...currentValues };
183
183
  fields.forEach((field) => {
184
- const currentValue = newValues[field.id];
185
- if (!isEmpty(currentValue)) {
186
- return;
187
- }
188
184
  if (field.prefill?.value !== void 0) {
189
185
  newValues[field.id] = field.prefill.value;
190
186
  return;
@@ -196,9 +192,6 @@ function applyPrefill(currentValues, fields, prefilledData = {}) {
196
192
  });
197
193
  return newValues;
198
194
  }
199
- function isEmpty(val) {
200
- return val === void 0 || val === null || val === "";
201
- }
202
195
 
203
196
  // src/core/store.ts
204
197
  var FormStore = class {
@@ -371,7 +364,20 @@ var FormStore = class {
371
364
  this.schema.computations.forEach((comp) => {
372
365
  if (comp.type === "sum") {
373
366
  const sum = comp.fields.reduce((acc, fieldId) => {
374
- const val = Number(this.state.values[fieldId]) || 0;
367
+ const raw = this.state.values[fieldId];
368
+ const fieldDef = this.fieldMap[fieldId];
369
+ const options = fieldDef?.type === "select" || fieldDef?.type === "multiselect" || fieldDef?.type === "radio" || fieldDef?.type === "checkbox" ? fieldDef.options : void 0;
370
+ const hasScoreOptions = options?.some((o) => o.score !== void 0);
371
+ let val;
372
+ if (hasScoreOptions && options) {
373
+ const selected = fieldDef?.type === "multiselect" || fieldDef?.type === "checkbox" ? (Array.isArray(raw) ? raw : [raw]).filter(Boolean) : [raw];
374
+ val = selected.reduce((s, v) => {
375
+ const opt = options.find((o) => o.value === v || String(o.value) === String(v));
376
+ return s + (opt && "score" in opt && typeof opt.score === "number" ? opt.score : 0);
377
+ }, 0);
378
+ } else {
379
+ val = Number(raw) || 0;
380
+ }
375
381
  return acc + val;
376
382
  }, 0);
377
383
  if (this.state.values[comp.target] !== sum) {
@@ -2354,10 +2360,10 @@ var ReadOnlySelect = ({ fieldDef, value }) => {
2354
2360
  return String(opt.value) === String(value) || opt.value === value;
2355
2361
  });
2356
2362
  const displayValue = selectedOption ? selectedOption.label : value ?? "";
2357
- const isEmpty2 = !value && value !== 0;
2363
+ const isEmpty = !value && value !== 0;
2358
2364
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
2359
2365
  /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
2360
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem] flex items-center", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty2 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
2366
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem] flex items-center", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
2361
2367
  ] });
2362
2368
  };
2363
2369
  var ReadOnlyMultiSelect = ({ fieldDef, value }) => {
@@ -2381,10 +2387,10 @@ var ReadOnlyMultiSelect = ({ fieldDef, value }) => {
2381
2387
  });
2382
2388
  return option ? option.label : String(val);
2383
2389
  }).filter(Boolean);
2384
- const isEmpty2 = selectedLabels.length === 0;
2390
+ const isEmpty = selectedLabels.length === 0;
2385
2391
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
2386
2392
  /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
2387
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty2 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No values selected" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: selectedLabels.map((label, idx) => /* @__PURE__ */ jsxRuntime.jsx(
2393
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No values selected" }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: selectedLabels.map((label, idx) => /* @__PURE__ */ jsxRuntime.jsx(
2388
2394
  "span",
2389
2395
  {
2390
2396
  className: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800",
@@ -2587,10 +2593,10 @@ var ReadOnlyRadio = ({ fieldDef, value }) => {
2587
2593
  (opt) => String(opt.value) === String(value) || opt.value === value
2588
2594
  );
2589
2595
  const displayValue = selectedOption ? selectedOption.label : value ?? "";
2590
- const isEmpty2 = value == null || value === "";
2596
+ const isEmpty = value == null || value === "";
2591
2597
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-2", children: [
2592
2598
  /* @__PURE__ */ jsxRuntime.jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
2593
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem] flex items-center", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty2 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
2599
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem] flex items-center", children: loading ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
2594
2600
  ] });
2595
2601
  };
2596
2602
  function isOptionSelected2(selected, optValue) {