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 +20 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -13
- package/dist/index.d.ts +10 -13
- package/dist/index.mjs +20 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -52,27 +52,24 @@ interface TextFieldDef extends BaseFieldDef {
|
|
|
52
52
|
interface NumberFieldDef extends BaseFieldDef {
|
|
53
53
|
type: 'number';
|
|
54
54
|
}
|
|
55
|
+
/** Option for select/radio/checkbox. When score is set, sum computation uses it for aggregation. */
|
|
56
|
+
interface SelectOption {
|
|
57
|
+
label: string;
|
|
58
|
+
value: any;
|
|
59
|
+
score?: number;
|
|
60
|
+
}
|
|
55
61
|
interface SelectFieldDef extends BaseFieldDef {
|
|
56
62
|
type: 'select' | 'multiselect';
|
|
57
|
-
options?:
|
|
58
|
-
label: string;
|
|
59
|
-
value: any;
|
|
60
|
-
}[];
|
|
63
|
+
options?: SelectOption[];
|
|
61
64
|
}
|
|
62
65
|
interface RadioFieldDef extends BaseFieldDef {
|
|
63
66
|
type: 'radio';
|
|
64
|
-
options?:
|
|
65
|
-
label: string;
|
|
66
|
-
value: any;
|
|
67
|
-
}[];
|
|
67
|
+
options?: SelectOption[];
|
|
68
68
|
}
|
|
69
69
|
interface CheckboxFieldDef extends BaseFieldDef {
|
|
70
70
|
type: 'checkbox';
|
|
71
71
|
/** Options for the checkbox group; value is stored as array of selected option values. */
|
|
72
|
-
options?:
|
|
73
|
-
label: string;
|
|
74
|
-
value: any;
|
|
75
|
-
}[];
|
|
72
|
+
options?: SelectOption[];
|
|
76
73
|
}
|
|
77
74
|
interface RepeatableFieldDef extends BaseFieldDef {
|
|
78
75
|
type: 'repeatable';
|
|
@@ -440,4 +437,4 @@ interface CreateUploadHandlerOptions {
|
|
|
440
437
|
*/
|
|
441
438
|
declare function createUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
442
439
|
|
|
443
|
-
export { type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type FieldDef, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type ImageUploadFieldDef, ImageUploadWidget, type LayoutNode, type NumberFieldDef, type Permission, type PresignedUploadResponse, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, type RepeatableFieldDef, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SignatureFieldDef, SignatureUploadWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useForm, useFormStore, validateField, validateForm };
|
|
440
|
+
export { type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type FieldDef, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type ImageUploadFieldDef, ImageUploadWidget, type LayoutNode, type NumberFieldDef, type Permission, type PresignedUploadResponse, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, type RepeatableFieldDef, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useForm, useFormStore, validateField, validateForm };
|
package/dist/index.d.ts
CHANGED
|
@@ -52,27 +52,24 @@ interface TextFieldDef extends BaseFieldDef {
|
|
|
52
52
|
interface NumberFieldDef extends BaseFieldDef {
|
|
53
53
|
type: 'number';
|
|
54
54
|
}
|
|
55
|
+
/** Option for select/radio/checkbox. When score is set, sum computation uses it for aggregation. */
|
|
56
|
+
interface SelectOption {
|
|
57
|
+
label: string;
|
|
58
|
+
value: any;
|
|
59
|
+
score?: number;
|
|
60
|
+
}
|
|
55
61
|
interface SelectFieldDef extends BaseFieldDef {
|
|
56
62
|
type: 'select' | 'multiselect';
|
|
57
|
-
options?:
|
|
58
|
-
label: string;
|
|
59
|
-
value: any;
|
|
60
|
-
}[];
|
|
63
|
+
options?: SelectOption[];
|
|
61
64
|
}
|
|
62
65
|
interface RadioFieldDef extends BaseFieldDef {
|
|
63
66
|
type: 'radio';
|
|
64
|
-
options?:
|
|
65
|
-
label: string;
|
|
66
|
-
value: any;
|
|
67
|
-
}[];
|
|
67
|
+
options?: SelectOption[];
|
|
68
68
|
}
|
|
69
69
|
interface CheckboxFieldDef extends BaseFieldDef {
|
|
70
70
|
type: 'checkbox';
|
|
71
71
|
/** Options for the checkbox group; value is stored as array of selected option values. */
|
|
72
|
-
options?:
|
|
73
|
-
label: string;
|
|
74
|
-
value: any;
|
|
75
|
-
}[];
|
|
72
|
+
options?: SelectOption[];
|
|
76
73
|
}
|
|
77
74
|
interface RepeatableFieldDef extends BaseFieldDef {
|
|
78
75
|
type: 'repeatable';
|
|
@@ -440,4 +437,4 @@ interface CreateUploadHandlerOptions {
|
|
|
440
437
|
*/
|
|
441
438
|
declare function createUploadHandler(options: CreateUploadHandlerOptions): (file: File | Blob, filename: string) => Promise<string>;
|
|
442
439
|
|
|
443
|
-
export { type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type FieldDef, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type ImageUploadFieldDef, ImageUploadWidget, type LayoutNode, type NumberFieldDef, type Permission, type PresignedUploadResponse, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, type RepeatableFieldDef, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SignatureFieldDef, SignatureUploadWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useForm, useFormStore, validateField, validateForm };
|
|
440
|
+
export { type BaseFieldDef, type CheckboxFieldDef, type ColumnLayout, type Computation, type Condition, type CreateUploadHandlerOptions, type DataSource, DynamicForm, EMAIL_REGEX, type EditableTableColumnDef, type EditableTableFieldDef, type EventDefinition, type FieldDef, type FieldPrefill, FieldRenderer, type FieldState, type FieldType, FormControls, type FormControlsProps, type FormDef, type FormErrors, FormProvider, type FormState, FormStore, type FormValues, type ImageUploadFieldDef, ImageUploadWidget, type LayoutNode, type NumberFieldDef, type Permission, type PresignedUploadResponse, type RadioFieldDef, ReadOnlyForm, ReadOnlyImageUpload, ReadOnlySignature, ReadOnlyTable, type RepeatableFieldDef, type Rule, type RuleAction, type RuleResult, type ScoreComputation, type ScoreRange, type Section, type SectionChild, type SelectFieldDef, type SelectOption, type SignatureFieldDef, SignatureUploadWidget, type StaticTextFieldDef, type StoreConfig, type SubmissionData, type SumComputation, type TextFieldDef, type ValidationRule, type WebhookDef, type Workflow, type WorkflowTransition, createUploadHandler, evaluateRules, useField, useForm, useFormStore, validateField, validateForm };
|
package/dist/index.mjs
CHANGED
|
@@ -155,10 +155,6 @@ var NO_OP_PROVIDER = {
|
|
|
155
155
|
function applyPrefill(currentValues, fields, prefilledData = {}) {
|
|
156
156
|
const newValues = { ...currentValues };
|
|
157
157
|
fields.forEach((field) => {
|
|
158
|
-
const currentValue = newValues[field.id];
|
|
159
|
-
if (!isEmpty(currentValue)) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
158
|
if (field.prefill?.value !== void 0) {
|
|
163
159
|
newValues[field.id] = field.prefill.value;
|
|
164
160
|
return;
|
|
@@ -170,9 +166,6 @@ function applyPrefill(currentValues, fields, prefilledData = {}) {
|
|
|
170
166
|
});
|
|
171
167
|
return newValues;
|
|
172
168
|
}
|
|
173
|
-
function isEmpty(val) {
|
|
174
|
-
return val === void 0 || val === null || val === "";
|
|
175
|
-
}
|
|
176
169
|
|
|
177
170
|
// src/core/store.ts
|
|
178
171
|
var FormStore = class {
|
|
@@ -345,7 +338,20 @@ var FormStore = class {
|
|
|
345
338
|
this.schema.computations.forEach((comp) => {
|
|
346
339
|
if (comp.type === "sum") {
|
|
347
340
|
const sum = comp.fields.reduce((acc, fieldId) => {
|
|
348
|
-
const
|
|
341
|
+
const raw = this.state.values[fieldId];
|
|
342
|
+
const fieldDef = this.fieldMap[fieldId];
|
|
343
|
+
const options = fieldDef?.type === "select" || fieldDef?.type === "multiselect" || fieldDef?.type === "radio" || fieldDef?.type === "checkbox" ? fieldDef.options : void 0;
|
|
344
|
+
const hasScoreOptions = options?.some((o) => o.score !== void 0);
|
|
345
|
+
let val;
|
|
346
|
+
if (hasScoreOptions && options) {
|
|
347
|
+
const selected = fieldDef?.type === "multiselect" || fieldDef?.type === "checkbox" ? (Array.isArray(raw) ? raw : [raw]).filter(Boolean) : [raw];
|
|
348
|
+
val = selected.reduce((s, v) => {
|
|
349
|
+
const opt = options.find((o) => o.value === v || String(o.value) === String(v));
|
|
350
|
+
return s + (opt && "score" in opt && typeof opt.score === "number" ? opt.score : 0);
|
|
351
|
+
}, 0);
|
|
352
|
+
} else {
|
|
353
|
+
val = Number(raw) || 0;
|
|
354
|
+
}
|
|
349
355
|
return acc + val;
|
|
350
356
|
}, 0);
|
|
351
357
|
if (this.state.values[comp.target] !== sum) {
|
|
@@ -2328,10 +2334,10 @@ var ReadOnlySelect = ({ fieldDef, value }) => {
|
|
|
2328
2334
|
return String(opt.value) === String(value) || opt.value === value;
|
|
2329
2335
|
});
|
|
2330
2336
|
const displayValue = selectedOption ? selectedOption.label : value ?? "";
|
|
2331
|
-
const
|
|
2337
|
+
const isEmpty = !value && value !== 0;
|
|
2332
2338
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2333
2339
|
/* @__PURE__ */ jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
|
|
2334
|
-
/* @__PURE__ */ 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__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) :
|
|
2340
|
+
/* @__PURE__ */ 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__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
|
|
2335
2341
|
] });
|
|
2336
2342
|
};
|
|
2337
2343
|
var ReadOnlyMultiSelect = ({ fieldDef, value }) => {
|
|
@@ -2355,10 +2361,10 @@ var ReadOnlyMultiSelect = ({ fieldDef, value }) => {
|
|
|
2355
2361
|
});
|
|
2356
2362
|
return option ? option.label : String(val);
|
|
2357
2363
|
}).filter(Boolean);
|
|
2358
|
-
const
|
|
2364
|
+
const isEmpty = selectedLabels.length === 0;
|
|
2359
2365
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2360
2366
|
/* @__PURE__ */ jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
|
|
2361
|
-
/* @__PURE__ */ jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: loading ? /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) :
|
|
2367
|
+
/* @__PURE__ */ jsx("div", { className: "text-gray-900 border border-gray-200 rounded-md p-3 bg-gray-50 min-h-[2.5rem]", children: loading ? /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "No values selected" }) : /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: selectedLabels.map((label, idx) => /* @__PURE__ */ jsx(
|
|
2362
2368
|
"span",
|
|
2363
2369
|
{
|
|
2364
2370
|
className: "inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800",
|
|
@@ -2561,10 +2567,10 @@ var ReadOnlyRadio = ({ fieldDef, value }) => {
|
|
|
2561
2567
|
(opt) => String(opt.value) === String(value) || opt.value === value
|
|
2562
2568
|
);
|
|
2563
2569
|
const displayValue = selectedOption ? selectedOption.label : value ?? "";
|
|
2564
|
-
const
|
|
2570
|
+
const isEmpty = value == null || value === "";
|
|
2565
2571
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-2", children: [
|
|
2566
2572
|
/* @__PURE__ */ jsx(Label, { className: "text-sm font-medium text-gray-700", children: fieldDef.label }),
|
|
2567
|
-
/* @__PURE__ */ 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__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) :
|
|
2573
|
+
/* @__PURE__ */ 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__ */ jsx("span", { className: "text-gray-400 italic", children: "Loading..." }) : isEmpty ? /* @__PURE__ */ jsx("span", { className: "text-gray-400 italic", children: "No value" }) : displayValue })
|
|
2568
2574
|
] });
|
|
2569
2575
|
};
|
|
2570
2576
|
function isOptionSelected2(selected, optValue) {
|