@formality-ui/core 0.2.2 → 0.2.4
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 +45 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +45 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -458,6 +458,33 @@ function inferFieldsFromDescriptor(descriptor) {
|
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
// src/conditions/evaluate.ts
|
|
461
|
+
function buildFormStateFromInput(fieldValues, fieldStates, record) {
|
|
462
|
+
const fields = {};
|
|
463
|
+
for (const [name, value] of Object.entries(fieldValues)) {
|
|
464
|
+
const state = fieldStates?.[name];
|
|
465
|
+
fields[name] = {
|
|
466
|
+
value,
|
|
467
|
+
isTouched: state?.isTouched ?? false,
|
|
468
|
+
isDirty: state?.isDirty ?? false,
|
|
469
|
+
isValidating: state?.isValidating ?? false,
|
|
470
|
+
error: state?.error,
|
|
471
|
+
invalid: state?.invalid ?? false,
|
|
472
|
+
disabled: state?.disabled
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
fields,
|
|
477
|
+
record: record ?? {},
|
|
478
|
+
errors: {},
|
|
479
|
+
defaultValues: {},
|
|
480
|
+
touchedFields: {},
|
|
481
|
+
dirtyFields: {},
|
|
482
|
+
isDirty: false,
|
|
483
|
+
isTouched: false,
|
|
484
|
+
isValid: true,
|
|
485
|
+
isSubmitting: false
|
|
486
|
+
};
|
|
487
|
+
}
|
|
461
488
|
function evaluateFieldMatcher(fieldName, matcher, fieldValues, fieldStates) {
|
|
462
489
|
const fieldValue = fieldValues[fieldName];
|
|
463
490
|
const fieldState = fieldStates?.[fieldName];
|
|
@@ -529,7 +556,11 @@ function evaluateConditionMatch(condition, context, fieldValues, fieldStates) {
|
|
|
529
556
|
if (typeof condition.selectWhen === "string") {
|
|
530
557
|
triggerValue = evaluate(condition.selectWhen, context);
|
|
531
558
|
} else if (typeof condition.selectWhen === "function") {
|
|
532
|
-
|
|
559
|
+
const ctxRecord = context.record ?? void 0;
|
|
560
|
+
triggerValue = condition.selectWhen(
|
|
561
|
+
buildFormStateFromInput(fieldValues, fieldStates, ctxRecord),
|
|
562
|
+
void 0
|
|
563
|
+
);
|
|
533
564
|
} else {
|
|
534
565
|
triggerValue = evaluateDescriptor(condition.selectWhen, context);
|
|
535
566
|
}
|
|
@@ -603,7 +634,10 @@ function evaluateConditions(input) {
|
|
|
603
634
|
if (typeof condition.selectSet === "string") {
|
|
604
635
|
setValue = unwrapFieldProxy(evaluate(condition.selectSet, context));
|
|
605
636
|
} else if (typeof condition.selectSet === "function") {
|
|
606
|
-
setValue = condition.selectSet
|
|
637
|
+
setValue = condition.selectSet(
|
|
638
|
+
buildFormStateFromInput(fieldValues, fieldStates, record),
|
|
639
|
+
void 0
|
|
640
|
+
);
|
|
607
641
|
} else {
|
|
608
642
|
setValue = unwrapFieldProxy(
|
|
609
643
|
evaluateDescriptor(condition.selectSet, context)
|
|
@@ -696,6 +730,15 @@ function runSingleValidator(validator, value, formValues) {
|
|
|
696
730
|
function resolveNamedValidator(name, validators) {
|
|
697
731
|
const validator = validators[name];
|
|
698
732
|
if (typeof validator === "function") {
|
|
733
|
+
let probe;
|
|
734
|
+
try {
|
|
735
|
+
probe = validator(void 0, {});
|
|
736
|
+
} catch {
|
|
737
|
+
return validator;
|
|
738
|
+
}
|
|
739
|
+
if (typeof probe === "function") {
|
|
740
|
+
return validator();
|
|
741
|
+
}
|
|
699
742
|
return validator;
|
|
700
743
|
}
|
|
701
744
|
return void 0;
|