formanitor 0.0.6 → 0.0.8
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 +14 -1
- 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 +14 -1
- 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
|
@@ -345,7 +345,20 @@ var FormStore = class {
|
|
|
345
345
|
this.schema.computations.forEach((comp) => {
|
|
346
346
|
if (comp.type === "sum") {
|
|
347
347
|
const sum = comp.fields.reduce((acc, fieldId) => {
|
|
348
|
-
const
|
|
348
|
+
const raw = this.state.values[fieldId];
|
|
349
|
+
const fieldDef = this.fieldMap[fieldId];
|
|
350
|
+
const options = fieldDef?.type === "select" || fieldDef?.type === "multiselect" || fieldDef?.type === "radio" || fieldDef?.type === "checkbox" ? fieldDef.options : void 0;
|
|
351
|
+
const hasScoreOptions = options?.some((o) => o.score !== void 0);
|
|
352
|
+
let val;
|
|
353
|
+
if (hasScoreOptions && options) {
|
|
354
|
+
const selected = fieldDef?.type === "multiselect" || fieldDef?.type === "checkbox" ? (Array.isArray(raw) ? raw : [raw]).filter(Boolean) : [raw];
|
|
355
|
+
val = selected.reduce((s, v) => {
|
|
356
|
+
const opt = options.find((o) => o.value === v || String(o.value) === String(v));
|
|
357
|
+
return s + (opt && "score" in opt && typeof opt.score === "number" ? opt.score : 0);
|
|
358
|
+
}, 0);
|
|
359
|
+
} else {
|
|
360
|
+
val = Number(raw) || 0;
|
|
361
|
+
}
|
|
349
362
|
return acc + val;
|
|
350
363
|
}, 0);
|
|
351
364
|
if (this.state.values[comp.target] !== sum) {
|